python / cpython

The Python programming language
https://www.python.org
Other
62.35k stars 29.94k forks source link

Broken help() on metaclasses #79795

Closed serhiy-storchaka closed 5 years ago

serhiy-storchaka commented 5 years ago
BPO 35614
Nosy @ncoghlan, @abalkin, @merwok, @serhiy-storchaka, @CuriousLearner
PRs
  • python/cpython#11357
  • python/cpython#11357
  • python/cpython#11357
  • 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: ```python assignee = None closed_at = created_at = labels = ['3.8', 'type-bug', 'library'] title = 'Broken help() on metaclasses' updated_at = user = 'https://github.com/serhiy-storchaka' ``` bugs.python.org fields: ```python activity = actor = 'ncoghlan' assignee = 'none' closed = True closed_date = closer = 'ncoghlan' components = ['Library (Lib)'] creation = creator = 'serhiy.storchaka' dependencies = [] files = [] hgrepos = [] issue_num = 35614 keywords = ['patch', 'patch', 'patch'] message_count = 4.0 messages = ['332720', '332726', '332727', '332802'] nosy_count = 5.0 nosy_names = ['ncoghlan', 'belopolsky', 'eric.araujo', 'serhiy.storchaka', 'CuriousLearner'] pr_nums = ['11357', '11357', '11357'] priority = 'normal' resolution = 'fixed' stage = 'resolved' status = 'closed' superseder = None type = 'behavior' url = 'https://bugs.python.org/issue35614' versions = ['Python 3.8'] ```

    serhiy-storchaka commented 5 years ago
    $ ./python -m pydoc abc
    Traceback (most recent call last):
      File "/home/serhiy/py/cpython/Lib/runpy.py", line 192, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "/home/serhiy/py/cpython/Lib/runpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 2765, in <module>
        cli()
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 2727, in cli
        help.help(arg)
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1967, in help
        elif request: doc(request, 'Help on %s:', output=self._output)
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1690, in doc
        pager(render_doc(thing, title, forceload))
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1683, in render_doc
        return title % desc + '\n\n' + renderer.document(object, name)
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 385, in document
        if inspect.ismodule(object): return self.docmodule(*args)
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1182, in docmodule
        contents.append(self.document(value, key, name))
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 386, in document
        if inspect.isclass(object): return self.docclass(*args)
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1258, in docclass
        (str(cls.__name__) for cls in object.__subclasses__()
    TypeError: descriptor '__subclasses__' of 'type' object needs an argument
    
    $ ./python -m pydoc enum
    Traceback (most recent call last):
      File "/home/serhiy/py/cpython/Lib/runpy.py", line 192, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "/home/serhiy/py/cpython/Lib/runpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 2765, in <module>
        cli()
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 2727, in cli
        help.help(arg)
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1967, in help
        elif request: doc(request, 'Help on %s:', output=self._output)
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1690, in doc
        pager(render_doc(thing, title, forceload))
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1683, in render_doc
        return title % desc + '\n\n' + renderer.document(object, name)
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 385, in document
        if inspect.ismodule(object): return self.docmodule(*args)
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1182, in docmodule
        contents.append(self.document(value, key, name))
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 386, in document
        if inspect.isclass(object): return self.docclass(*args)
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1258, in docclass
        (str(cls.__name__) for cls in object.__subclasses__()
    TypeError: descriptor '__subclasses__' of 'type' object needs an argument

    "object" is a metaclass (abc.ABCMeta or enum.EnumMeta) in tracebacks above.

    The regression was introduced in bpo-8525.

    serhiy-storchaka commented 5 years ago

    It fails also for builtin "type".

    $ ./python -m pydoc type
    Traceback (most recent call last):
      File "/home/serhiy/py/cpython/Lib/runpy.py", line 192, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "/home/serhiy/py/cpython/Lib/runpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 2765, in <module>
        cli()
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 2727, in cli
        help.help(arg)
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1967, in help
        elif request: doc(request, 'Help on %s:', output=self._output)
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1690, in doc
        pager(render_doc(thing, title, forceload))
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1683, in render_doc
        return title % desc + '\n\n' + renderer.document(object, name)
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 386, in document
        if inspect.isclass(object): return self.docclass(*args)
      File "/home/serhiy/py/cpython/Lib/pydoc.py", line 1258, in docclass
        (str(cls.__name__) for cls in object.__subclasses__()
    TypeError: descriptor '__subclasses__' of 'type' object needs an argument
    serhiy-storchaka commented 5 years ago

    There are two ways of solving this issue: 1) skip this chunk of code if object is a type subclass, 2) use type.__subclasses__(object) instead of object.__subclasses__().

    ncoghlan commented 5 years ago

    New changeset b539cef31c060c7eecc331d25a23b80ded0baf08 by Nick Coghlan (Sanyam Khurana) in branch 'master': bpo-35614: Fix pydoc help() on metaclasses (bpo-11357) https://github.com/python/cpython/commit/b539cef31c060c7eecc331d25a23b80ded0baf08