[New-bugs-announce] [issue33668] Wrong behavior of help function on module

Oleg Oleynik report at bugs.python.org
Mon May 28 10:22:23 EDT 2018


New submission from Oleg Oleynik <oleg_oleinik at mail.ru>:

I write file test.py:
def __getattr__(key):
    return None
help(__name__)

when I try to run it I've got error:
Traceback (most recent call last):
  File "test.py", line 5, in <module>
    help(__name__)
  File "C:\Program Files\Python37\lib\_sitebuiltins.py", line 103, in __call__
    return pydoc.help(*args, **kwds)
  File "C:\Program Files\Python37\lib\pydoc.py", line 1894, in __call__
    self.help(request)
  File "C:\Program Files\Python37\lib\pydoc.py", line 1944, in help
    elif request: doc(request, 'Help on %s:', output=self._output)
  File "C:\Program Files\Python37\lib\pydoc.py", line 1674, in doc
    pager(render_doc(thing, title, forceload))
  File "C:\Program Files\Python37\lib\pydoc.py", line 1667, in render_doc
    return title % desc + '\n\n' + renderer.document(object, name)
  File "C:\Program Files\Python37\lib\pydoc.py", line 385, in document
    if inspect.ismodule(object): return self.docmodule(*args)
  File "C:\Program Files\Python37\lib\pydoc.py", line 1136, in docmodule
    for key, value in inspect.getmembers(object, inspect.isclass):
  File "C:\Program Files\Python37\lib\inspect.py", line 330, in getmembers
    for base in object.__bases__:
TypeError: 'NoneType' object is not iterable

If I change definition of __getattr__ function to:
def __getattr__(key):
   raise AttributeError()
then help function runs without errors. But I need to return None value from __getattr__ function.
When I wrote this function in class definition there is also no errors during runtime

----------
components: Library (Lib)
messages: 317852
nosy: oleg_oleinik
priority: normal
severity: normal
status: open
title: Wrong behavior of help function on module
type: behavior
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33668>
_______________________________________


More information about the New-bugs-announce mailing list