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.

classification
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
process
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.

Files
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
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)
msg80003 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-01-17 04:15
Thanks for the patch! Fixed in r68647.
History
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