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 crashes on missing kwonlydefaults
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.0
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, petr.dolezal
Priority: normal Keywords:

Created on 2009-03-29 17:41 by petr.dolezal, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg84417 - (view) Author: Petr Dolezal (petr.dolezal) Date: 2009-03-29 17:41
inspect.formatargspec is not able to handle functions with keyword only
arguments without the default values (probably rare, but still allowed).
This has also impact on help command which is then unable to show proper
help page for such functions. 

Offending function examples:
def fun1(arg, defarg=None, *args, kwonly):
    """Some documentation."""
    return arg, defarg, args, kwonly

def fun2(arg, defarg=None, *, kwonly):
    """Some documentation."""
    return arg, defarg, kwonly


The fix is easy:
897c897
<             if kwonlyarg in kwonlydefaults:
---
>             if kwonlydefaults and kwonlyarg in kwonlydefaults:


For the test following code snippet taken from help module (or help) can
be used:

import inspect

def trybug(fun):
    args, varargs, varkw, defaults, kwonlyargs, kwdefaults, ann = \
        inspect.getfullargspec(fun)
    argspec = inspect.formatargspec(
        args, varargs, varkw, defaults, kwonlyargs, kwdefaults, ann,
        formatannotation=inspect.formatannotationrelativeto(object))
msg84419 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-03-29 17:59
This was fixed in r68647 and will appear in 3.0.2 and 3.1.
History
Date User Action Args
2022-04-11 14:56:47adminsetgithub: 49847
2009-03-29 17:59:29benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg84419

resolution: out of date
2009-03-29 17:41:11petr.dolezalcreate