This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: inspect.formatargspec fails for keyword args without defaults, affects help and likely pydoc
Type: crash Stage:
Components: Library (Lib) Versions: Python 3.0, Python 3.1
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, dariusp
Priority: normal Keywords: patch

Created on 2009-01-16 05:53 by dariusp, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
inspect_keyworded_no_default.diff dariusp, 2009-01-16 05:53 Patch inspect_keyworded_no_default
Messages (2)
msg79932 - (view) Author: (dariusp) Date: 2009-01-16 05:53

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.

The patch contains a suggested fix to and a new test in and to demonstrate the issue.

>>> def foo(*, a):
...  print(a)
>>> help(foo)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.0/", line 427, in __call__
    return*args, **kwds)
  File "/usr/local/lib/python3.0/", line 1672, in __call__
  File "/usr/local/lib/python3.0/", line 1716, in help
    else: doc(request, 'Help on %s:')
  File "/usr/local/lib/python3.0/", line 1504, in doc
    pager(render_doc(thing, title, forceload))
  File "/usr/local/lib/python3.0/", line 1499, in render_doc
    return title % desc + '\n\n' + text.document(object, name)
  File "/usr/local/lib/python3.0/", line 322, in document
    if inspect.isroutine(object): return self.docroutine(*args)
  File "/usr/local/lib/python3.0/", line 1263, in docroutine
  File "/usr/local/lib/python3.0/", line 895, in formatargspec
    if kwonlyarg in kwonlydefaults:
TypeError: argument of type 'NoneType' is not iterable

>>> def foo(*, a):
...  print(a)
>>> help(foo)

Help on function foo in module __main__:

foo(*, a)
msg80003 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-01-17 04:15
Thanks for the patch! Fixed in r68647.
Date User Action Args
2022-04-11 14:56:44adminsetgithub: 49209
2009-01-17 04:15:16benjamin.petersonsetstatus: open -> closed
resolution: fixed
messages: + msg80003
nosy: + benjamin.peterson
versions: + Python 3.1
2009-01-16 05:53:19dariuspcreate