Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inspect.formatargspec fails for keyword args without defaults, affects help and likely pydoc #49209

Closed
dariusp mannequin opened this issue Jan 16, 2009 · 2 comments
Closed
Labels
stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@dariusp
Copy link
Mannequin

dariusp mannequin commented Jan 16, 2009

BPO 4959
Nosy @benjaminp
Files
  • inspect_keyworded_no_default.diff: Patch inspect_keyworded_no_default
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2009-01-17.04:15:16.827>
    created_at = <Date 2009-01-16.05:53:19.652>
    labels = ['library', 'type-crash']
    title = 'inspect.formatargspec fails for keyword args without defaults, affects help and likely pydoc'
    updated_at = <Date 2009-01-17.04:15:16.757>
    user = 'https://bugs.python.org/dariusp'

    bugs.python.org fields:

    activity = <Date 2009-01-17.04:15:16.757>
    actor = 'benjamin.peterson'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-01-17.04:15:16.827>
    closer = 'benjamin.peterson'
    components = ['Library (Lib)']
    creation = <Date 2009-01-16.05:53:19.652>
    creator = 'dariusp'
    dependencies = []
    files = ['12760']
    hgrepos = []
    issue_num = 4959
    keywords = ['patch']
    message_count = 2.0
    messages = ['79932', '80003']
    nosy_count = 2.0
    nosy_names = ['benjamin.peterson', 'dariusp']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue4959'
    versions = ['Python 3.0', 'Python 3.1']

    @dariusp
    Copy link
    Mannequin Author

    dariusp mannequin commented Jan 16, 2009

    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)

    @dariusp dariusp mannequin added stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump labels Jan 16, 2009
    @benjaminp
    Copy link
    Contributor

    Thanks for the patch! Fixed in r68647.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant