Tested in Python 3.3 and Python 3.4.0rc1 5e05d7d3db9c If a function has keyword-only arguments but no keyword-only defaults, then calling inspect.getcallargs with no arguments results in the wrong TypeError being raised. Example: >>> import inspect >>> def fn(*, a): >>> pass >>> inspect.getcallargs(fn) Result: TypeError: argument of type 'NoneType' is not iterable Expected Result: TypeError: fn() missing 1 required keyword-only argument: 'a'
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.