Skip to content

gh-133210: Fix test_pydoc in --without-doc-strings mode #133271

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

Merged
merged 1 commit into from
May 2, 2025
Merged
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
82 changes: 60 additions & 22 deletions Lib/test/test_pydoc/test_pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1927,18 +1927,28 @@ def test_text_doc_routines_in_class(self, cls=pydocfodder.B):
self.assertIn(' | global_func(x, y) from test.test_pydoc.pydocfodder', lines)
self.assertIn(' | global_func_alias = global_func(x, y)', lines)
self.assertIn(' | global_func2_alias = global_func2(x, y) from test.test_pydoc.pydocfodder', lines)
self.assertIn(' | count(self, value, /) from builtins.list', lines)
self.assertIn(' | list_count = count(self, value, /)', lines)
self.assertIn(' | __repr__(self, /) from builtins.object', lines)
self.assertIn(' | object_repr = __repr__(self, /)', lines)
if not support.MISSING_C_DOCSTRINGS:
self.assertIn(' | count(self, value, /) from builtins.list', lines)
self.assertIn(' | list_count = count(self, value, /)', lines)
self.assertIn(' | __repr__(self, /) from builtins.object', lines)
self.assertIn(' | object_repr = __repr__(self, /)', lines)
else:
self.assertIn(' | count(self, object, /) from builtins.list', lines)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have CI building Python without docstrings, this code path is less well tested. Maybe just remove it and only keep tests when we have C docstrings?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case we can have unexpected results when python is built without docstrings and no one will ever notice. Plus, this gives an example that you need to think about both modes when writting tests.

I don't think that signature of repr, list.count and list.get without docstrings will change that often.

But, I don't have a strong opinion here for sure, I will make any change that you think is best here

self.assertIn(' | list_count = count(self, object, /)', lines)
self.assertIn(' | __repr__(...) from builtins.object', lines)
self.assertIn(' | object_repr = __repr__(...)', lines)

lines = self.getsection(result, f' | Static methods {where}:', ' | ' + '-'*70)
self.assertIn(' | A_classmethod_ref = A_classmethod(x) class method of test.test_pydoc.pydocfodder.A', lines)
note = '' if cls is pydocfodder.B else ' class method of test.test_pydoc.pydocfodder.B'
self.assertIn(' | B_classmethod_ref = B_classmethod(x)' + note, lines)
self.assertIn(' | A_method_ref = A_method() method of test.test_pydoc.pydocfodder.A instance', lines)
self.assertIn(' | get(key, default=None, /) method of builtins.dict instance', lines)
self.assertIn(' | dict_get = get(key, default=None, /) method of builtins.dict instance', lines)
if not support.MISSING_C_DOCSTRINGS:
self.assertIn(' | get(key, default=None, /) method of builtins.dict instance', lines)
self.assertIn(' | dict_get = get(key, default=None, /) method of builtins.dict instance', lines)
else:
self.assertIn(' | get(...) method of builtins.dict instance', lines)
self.assertIn(' | dict_get = get(...) method of builtins.dict instance', lines)

lines = self.getsection(result, f' | Class methods {where}:', ' | ' + '-'*70)
self.assertIn(' | B_classmethod(x)', lines)
Expand All @@ -1957,10 +1967,16 @@ def test_html_doc_routines_in_class(self, cls=pydocfodder.B):
self.assertIn('global_func(x, y) from test.test_pydoc.pydocfodder', lines)
self.assertIn('global_func_alias = global_func(x, y)', lines)
self.assertIn('global_func2_alias = global_func2(x, y) from test.test_pydoc.pydocfodder', lines)
self.assertIn('count(self, value, /) from builtins.list', lines)
self.assertIn('list_count = count(self, value, /)', lines)
self.assertIn('__repr__(self, /) from builtins.object', lines)
self.assertIn('object_repr = __repr__(self, /)', lines)
if not support.MISSING_C_DOCSTRINGS:
self.assertIn('count(self, value, /) from builtins.list', lines)
self.assertIn('list_count = count(self, value, /)', lines)
self.assertIn('__repr__(self, /) from builtins.object', lines)
self.assertIn('object_repr = __repr__(self, /)', lines)
else:
self.assertIn('count(self, object, /) from builtins.list', lines)
self.assertIn('list_count = count(self, object, /)', lines)
self.assertIn('__repr__(...) from builtins.object', lines)
self.assertIn('object_repr = __repr__(...)', lines)

lines = self.getsection(result, f'Static methods {where}:', '-'*70)
self.assertIn('A_classmethod_ref = A_classmethod(x) class method of test.test_pydoc.pydocfodder.A', lines)
Expand Down Expand Up @@ -1997,15 +2013,27 @@ def test_text_doc_routines_in_module(self):
self.assertIn(' A_method3 = A_method() method of B instance', lines)
self.assertIn(' A_staticmethod_ref = A_staticmethod(x, y)', lines)
self.assertIn(' A_staticmethod_ref2 = A_staticmethod(y) method of B instance', lines)
self.assertIn(' get(key, default=None, /) method of builtins.dict instance', lines)
self.assertIn(' dict_get = get(key, default=None, /) method of builtins.dict instance', lines)
if not support.MISSING_C_DOCSTRINGS:
self.assertIn(' get(key, default=None, /) method of builtins.dict instance', lines)
self.assertIn(' dict_get = get(key, default=None, /) method of builtins.dict instance', lines)
else:
self.assertIn(' get(...) method of builtins.dict instance', lines)
self.assertIn(' dict_get = get(...) method of builtins.dict instance', lines)

# unbound methods
self.assertIn(' B_method(self)', lines)
self.assertIn(' B_method2 = B_method(self)', lines)
self.assertIn(' count(self, value, /) unbound builtins.list method', lines)
self.assertIn(' list_count = count(self, value, /) unbound builtins.list method', lines)
self.assertIn(' __repr__(self, /) unbound builtins.object method', lines)
self.assertIn(' object_repr = __repr__(self, /) unbound builtins.object method', lines)
if not support.MISSING_C_DOCSTRINGS:
self.assertIn(' count(self, value, /) unbound builtins.list method', lines)
self.assertIn(' list_count = count(self, value, /) unbound builtins.list method', lines)
self.assertIn(' __repr__(self, /) unbound builtins.object method', lines)
self.assertIn(' object_repr = __repr__(self, /) unbound builtins.object method', lines)
else:
self.assertIn(' count(self, object, /) unbound builtins.list method', lines)
self.assertIn(' list_count = count(self, object, /) unbound builtins.list method', lines)
self.assertIn(' __repr__(...) unbound builtins.object method', lines)
self.assertIn(' object_repr = __repr__(...) unbound builtins.object method', lines)


def test_html_doc_routines_in_module(self):
doc = pydoc.HTMLDoc()
Expand All @@ -2026,15 +2054,25 @@ def test_html_doc_routines_in_module(self):
self.assertIn(' A_method3 = A_method() method of B instance', lines)
self.assertIn(' A_staticmethod_ref = A_staticmethod(x, y)', lines)
self.assertIn(' A_staticmethod_ref2 = A_staticmethod(y) method of B instance', lines)
self.assertIn(' get(key, default=None, /) method of builtins.dict instance', lines)
self.assertIn(' dict_get = get(key, default=None, /) method of builtins.dict instance', lines)
if not support.MISSING_C_DOCSTRINGS:
self.assertIn(' get(key, default=None, /) method of builtins.dict instance', lines)
self.assertIn(' dict_get = get(key, default=None, /) method of builtins.dict instance', lines)
else:
self.assertIn(' get(...) method of builtins.dict instance', lines)
self.assertIn(' dict_get = get(...) method of builtins.dict instance', lines)
# unbound methods
self.assertIn(' B_method(self)', lines)
self.assertIn(' B_method2 = B_method(self)', lines)
self.assertIn(' count(self, value, /) unbound builtins.list method', lines)
self.assertIn(' list_count = count(self, value, /) unbound builtins.list method', lines)
self.assertIn(' __repr__(self, /) unbound builtins.object method', lines)
self.assertIn(' object_repr = __repr__(self, /) unbound builtins.object method', lines)
if not support.MISSING_C_DOCSTRINGS:
self.assertIn(' count(self, value, /) unbound builtins.list method', lines)
self.assertIn(' list_count = count(self, value, /) unbound builtins.list method', lines)
self.assertIn(' __repr__(self, /) unbound builtins.object method', lines)
self.assertIn(' object_repr = __repr__(self, /) unbound builtins.object method', lines)
else:
self.assertIn(' count(self, object, /) unbound builtins.list method', lines)
self.assertIn(' list_count = count(self, object, /) unbound builtins.list method', lines)
self.assertIn(' __repr__(...) unbound builtins.object method', lines)
self.assertIn(' object_repr = __repr__(...) unbound builtins.object method', lines)


@unittest.skipIf(
Expand Down
Loading