[issue5597] inspect.formatargspec crashes on missing kwonlydefaults

Petr Dolezal report at bugs.python.org
Sun Mar 29 19:41:13 CEST 2009


New submission from Petr Dolezal <petr.dolezal at matfyz.cz>:

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))

----------
components: Library (Lib)
messages: 84417
nosy: petr.dolezal
severity: normal
status: open
title: inspect.formatargspec crashes on missing kwonlydefaults
type: behavior
versions: Python 3.0

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5597>
_______________________________________


More information about the Python-bugs-list mailing list