[issue20816] inspect.getcallargs() attempts to iterate over None

Jeremiah Lowin report at bugs.python.org
Sat Mar 1 17:07:45 CET 2014


Jeremiah Lowin added the comment:

I created a patch to resolve this. 

If a function has keyword-only arguments, then inspect.getcallargs checks if the argument is in kwonlydefaults. However, kwonlydefaults is None if no defaults were specified. In that situation, 'kwarg in kwonlydefaults' raises the TypeError.

The quick fix is simply to test kwonlydefaults before testing if kwarg is in it.

The test for this situation is a little verbose because a TypeError is expected and one is raised, just the wrong one, so I parse the error message.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20816>
_______________________________________


More information about the Python-bugs-list mailing list