You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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=Noneclosed_at=Nonecreated_at=<Date2018-05-28.14:22:23.146>labels= ['3.7', 'type-bug', 'library']
title='Wrong behavior of help function on module'updated_at=<Date2019-08-01.05:15:50.897>user='https://bugs.python.org/OlegOleinik'
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 helpelif 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_docreturn title % desc +'\n\n'+ renderer.document(object, name)
File "C:\Program Files\Python37\lib\pydoc.py", line 385, in documentif inspect.ismodule(object): returnself.docmodule(*args)
File "C:\Program Files\Python37\lib\pydoc.py", line 1136, in docmodulefor key, value in inspect.getmembers(object, inspect.isclass):
File "C:\Program Files\Python37\lib\inspect.py", line 330, in getmembersfor base inobject.__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
Hm, replacing the return with a random string, this leads to another crash:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/ilevkivskyi/src/cpython/Lib/_sitebuiltins.py", line 103, in __call__return pydoc.help(*args, **kwds)
File "/Users/ilevkivskyi/src/cpython/Lib/pydoc.py", line 1895, in __call__self.help(request)
File "/Users/ilevkivskyi/src/cpython/Lib/pydoc.py", line 1954, in helpelse: doc(request, 'Help on %s:', output=self._output)
File "/Users/ilevkivskyi/src/cpython/Lib/pydoc.py", line 1674, in doc
pager(render_doc(thing, title, forceload))
File "/Users/ilevkivskyi/src/cpython/Lib/pydoc.py", line 1667, in render_docreturn title % desc +'\n\n'+ renderer.document(object, name)
File "/Users/ilevkivskyi/src/cpython/Lib/pydoc.py", line 385, in documentif inspect.ismodule(object): returnself.docmodule(*args)
File "/Users/ilevkivskyi/src/cpython/Lib/pydoc.py", line 1157, in docmodulefor importer, modname, ispkg in pkgutil.iter_modules(object.__path__):
File "/Users/ilevkivskyi/src/cpython/Lib/pkgutil.py", line 123, in iter_modulesraiseValueError("path must be None or list of paths to look for "ValueError: path must be None or list of paths to look for modules in
The reason is that __getattr__ is also triggered when a special attribute is looked up. I am not sure what to do with this. This is a bit inconsistent with how classes behave, where e.g. __len__ is never searched on an instance. But modules are special in many other ways, so maybe we can just fix pydoc (and other tools like inspect) to expect some ill-typed values in special module attributes and fail gracefully?
Activity
OlegOleinik commentedon May 28, 2018
I write file test.py:
def __getattr__(key):
return None
help(name)
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
ilevkivskyi commentedon May 31, 2018
Hm, replacing the return with a random string, this leads to another crash:
The reason is that
__getattr__is also triggered when a special attribute is looked up. I am not sure what to do with this. This is a bit inconsistent with how classes behave, where e.g.__len__is never searched on an instance. But modules are special in many other ways, so maybe we can just fix pydoc (and other tools like inspect) to expect some ill-typed values in special module attributes and fail gracefully?ilevkivskyi commentedon May 31, 2018
Adding Yury as an inspect expert. I don't think this is something urgent, we can probably postpone this to 3.7.1.
corona10 commentedon Jul 14, 2018
This script works well on Python2 but not on Python3.
I've submitted a PR. Please take a look.
corona10 commentedon Jul 14, 2018
I've checked both cases are now working on my patch.
corona10 commentedon Aug 1, 2019
I close PR 8284.
If there is a chance to work with this issue.
Please let me know
Thanks!