Consider a function with signature f(a, b). In future, I would like to change the signature to f(a, *, b), disallowing b to be passed as positional argument.
To reduce the impact of the change, I want to first deprecate specifying b positionally, warning users that do so.
For that I would like to write something like:
def f(a, b):
frame = inspect.currentframe()
if b in frame.specified_as_positional:
print('Do not do that')
else:
print('Good')
The result would be that
>>> f(1, 2)
'Do not do that'
>>> f(1, b=2)
'Good'
inspect.getargvalues(frame) does not seem to be sufficient. The ArgInfo object just provides
>>> f(1,b=2)
ArgInfo(args=['a', 'b'], varargs=None, keywords=None, locals={'a': 1, 'b': 2})
Is such inspection even possible in Python? Conceptually the interpreter does not seem to be required to remember if a argument was specified positionally or as keyword.
Python 2 support would be nice to have but is not strictly required.