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

gh-128772: Fix pydoc for methods with __module__ is None #129177

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def parentname(object, modname):
if necessary) or module."""
if '.' in object.__qualname__:
name = object.__qualname__.rpartition('.')[0]
if object.__module__ != modname:
if object.__module__ != modname and object.__module__ is not None:
return object.__module__ + '.' + name
else:
return name
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_pydoc/module_none.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def func():
pass
func.__module__ = None

class A:
def method(self):
pass
method.__module__ = None
5 changes: 5 additions & 0 deletions Lib/test/test_pydoc/test_pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1903,6 +1903,11 @@ def a_fn_with_https_link():
html
)

def test_module_none(self):
# Issue #128772
from test.test_pydoc import module_none
pydoc.render_doc(module_none)


class PydocFodderTest(unittest.TestCase):
def tearDown(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :mod:`pydoc` for methods with the ``__module__`` attribute equal to
``None``.
Loading