All TILs
python3·
forcing positional and keyword arguments in a python function
forcing positional and keyword arguments in a python function
consider this arbitrary function:
def f(user_id: str, /, message, *, channel: str) -> bool:
pass
/ means everything to its left must be passed positionally. so user_id cannot be passed as a keyword argument
f("123", "hello", channel="general") # ok
f(user_id="123", message="hello", channel="general") # TypeError
message is a normal argument. you can pass it positionally or as a keyword.
* means everything to its right must be passed as keyword arguments.
f("123", "hello", channel="general") # ok
f(user_id="123", message="hello", channel="general") # TypeError
You violate these rules and python raises a TypeError TypeError
← All TILsApril 3, 2026