smartcall.PosOrKw
- class smartcall.PosOrKw(name: str, value: Any, *, required: bool = False)[source]
A value that can be passed as either a positional or a keyword argument.
- Parameters:
name – The name of the keyword argument, i.e. the “keyword” that will be used when passing this argument as a keyword argument.
value – The value to pass to the function.
required – What to do when passing this argument to a function with an incompatible signature. If
True, raise an error. IfFalse(the default), ignore it.
When the function could accept either kind of argument, a positional argument will be used. This is because positional arguments don’t require that the function use the same argument names as the caller.
Examples
>>> from smartcall import call, PosOrKw >>> def f(a): ... return a ... >>> call(f, PosOrKw('a', 1)) 1
Note that the name given to the argument doesn’t need to match the function’s signature, if the argument is to be passed positionally:
>>> call(f, PosOrKw('b', 1)) 1