Issue 4959: inspect.formatargspec fails for keyword args without defaults, affects help and likely pydoc
Hi, Suggested log message: formatargspec now handles keyword only args that don't have defaults. Previously it expected an empty dict but was being given None. Patch: The patch contains a suggested fix to inspect.py and a new test in test_inspect.py and inspect_fodder2.py to demonstrate the issue. Before: >>> def foo(*, a): ... print(a) ... >>> help(foo) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.0/site.py", line 427, in __call__ return pydoc.help(*args, **kwds) File "/usr/local/lib/python3.0/pydoc.py", line 1672, in __call__ self.help(request) File "/usr/local/lib/python3.0/pydoc.py", line 1716, in help else: doc(request, 'Help on %s:') File "/usr/local/lib/python3.0/pydoc.py", line 1504, in doc pager(render_doc(thing, title, forceload)) File "/usr/local/lib/python3.0/pydoc.py", line 1499, in render_doc return title % desc + '\n\n' + text.document(object, name) File "/usr/local/lib/python3.0/pydoc.py", line 322, in document if inspect.isroutine(object): return self.docroutine(*args) File "/usr/local/lib/python3.0/pydoc.py", line 1263, in docroutine formatannotation=inspect.formatannotationrelativeto(object)) File "/usr/local/lib/python3.0/inspect.py", line 895, in formatargspec if kwonlyarg in kwonlydefaults: TypeError: argument of type 'NoneType' is not iterable After: >>> def foo(*, a): ... print(a) ... >>> help(foo) Help on function foo in module __main__: foo(*, a)