Skip to content

Commit 4e5b27e

Browse files
gh-81682: Fix test failures when CPython is built without docstrings (GH-113410)
1 parent c3f92f6 commit 4e5b27e

File tree

12 files changed

+55
-21
lines changed

12 files changed

+55
-21
lines changed

Lib/idlelib/idle_test/test_calltip.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import types
88
import re
99
from idlelib.idle_test.mock_tk import Text
10+
from test.support import MISSING_C_DOCSTRINGS
1011

1112

1213
# Test Class TC is used in multiple get_argspec test methods
@@ -50,6 +51,8 @@ class Get_argspecTest(unittest.TestCase):
5051
# but a red buildbot is better than a user crash (as has happened).
5152
# For a simple mismatch, change the expected output to the actual.
5253

54+
@unittest.skipIf(MISSING_C_DOCSTRINGS,
55+
"Signature information for builtins requires docstrings")
5356
def test_builtins(self):
5457

5558
def tiptest(obj, out):
@@ -143,6 +146,8 @@ def f(): pass
143146
f.__doc__ = 'a'*300
144147
self.assertEqual(get_spec(f), f"()\n{'a'*(calltip._MAX_COLS-3) + '...'}")
145148

149+
@unittest.skipIf(MISSING_C_DOCSTRINGS,
150+
"Signature information for builtins requires docstrings")
146151
def test_multiline_docstring(self):
147152
# Test fewer lines than max.
148153
self.assertEqual(get_spec(range),
@@ -157,6 +162,7 @@ def test_multiline_docstring(self):
157162
bytes(int) -> bytes object of size given by the parameter initialized with null bytes
158163
bytes() -> empty bytes object''')
159164

165+
def test_multiline_docstring_2(self):
160166
# Test more than max lines
161167
def f(): pass
162168
f.__doc__ = 'a\n' * 15

Lib/test/test_capi/test_misc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,8 @@ def __del__(self):
469469
del L
470470
self.assertEqual(PyList.num, 0)
471471

472+
@unittest.skipIf(MISSING_C_DOCSTRINGS,
473+
"Signature information for builtins requires docstrings")
472474
def test_heap_ctype_doc_and_text_signature(self):
473475
self.assertEqual(_testcapi.HeapDocCType.__doc__, "somedoc")
474476
self.assertEqual(_testcapi.HeapDocCType.__text_signature__, "(arg1, arg2)")

Lib/test/test_coroutines.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -953,11 +953,12 @@ async def b():
953953

954954
def test_corotype_1(self):
955955
ct = types.CoroutineType
956-
self.assertIn('into coroutine', ct.send.__doc__)
957-
self.assertIn('inside coroutine', ct.close.__doc__)
958-
self.assertIn('in coroutine', ct.throw.__doc__)
959-
self.assertIn('of the coroutine', ct.__dict__['__name__'].__doc__)
960-
self.assertIn('of the coroutine', ct.__dict__['__qualname__'].__doc__)
956+
if not support.MISSING_C_DOCSTRINGS:
957+
self.assertIn('into coroutine', ct.send.__doc__)
958+
self.assertIn('inside coroutine', ct.close.__doc__)
959+
self.assertIn('in coroutine', ct.throw.__doc__)
960+
self.assertIn('of the coroutine', ct.__dict__['__name__'].__doc__)
961+
self.assertIn('of the coroutine', ct.__dict__['__qualname__'].__doc__)
961962
self.assertEqual(ct.__name__, 'coroutine')
962963

963964
async def f(): pass

Lib/test/test_curses.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from unittest.mock import MagicMock
99

1010
from test.support import (requires, verbose, SaveSignals, cpython_only,
11-
check_disallow_instantiation)
11+
check_disallow_instantiation, MISSING_C_DOCSTRINGS)
1212
from test.support.import_helper import import_module
1313

1414
# Optionally test curses module. This currently requires that the
@@ -1142,6 +1142,8 @@ def test_encoding(self):
11421142
with self.assertRaises(TypeError):
11431143
del stdscr.encoding
11441144

1145+
@unittest.skipIf(MISSING_C_DOCSTRINGS,
1146+
"Signature information for builtins requires docstrings")
11451147
def test_issue21088(self):
11461148
stdscr = self.stdscr
11471149
#

Lib/test/test_functools.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,8 @@ def mycmp(x, y):
939939
self.assertRaises(TypeError, hash, k)
940940
self.assertNotIsInstance(k, collections.abc.Hashable)
941941

942+
@unittest.skipIf(support.MISSING_C_DOCSTRINGS,
943+
"Signature information for builtins requires docstrings")
942944
def test_cmp_to_signature(self):
943945
self.assertEqual(str(Signature.from_callable(self.cmp_to_key)),
944946
'(mycmp)')

Lib/test/test_importlib/extension/test_loader.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import warnings
1010
import importlib.util
1111
import importlib
12+
from test.support import MISSING_C_DOCSTRINGS
1213

1314

1415
class LoaderTests:
@@ -373,7 +374,8 @@ def test_nonascii(self):
373374
with self.subTest(name):
374375
module = self.load_module_by_name(name)
375376
self.assertEqual(module.__name__, name)
376-
self.assertEqual(module.__doc__, "Module named in %s" % lang)
377+
if not MISSING_C_DOCSTRINGS:
378+
self.assertEqual(module.__doc__, "Module named in %s" % lang)
377379

378380

379381
(Frozen_MultiPhaseExtensionModuleTests,

Lib/test/test_inspect/test_inspect.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3990,6 +3990,8 @@ def foo(a, *, b:1): pass
39903990
foo_sig = MySignature.from_callable(foo)
39913991
self.assertIsInstance(foo_sig, MySignature)
39923992

3993+
@unittest.skipIf(MISSING_C_DOCSTRINGS,
3994+
"Signature information for builtins requires docstrings")
39933995
def test_signature_from_callable_class(self):
39943996
# A regression test for a class inheriting its signature from `object`.
39953997
class MySignature(inspect.Signature): pass
@@ -4080,7 +4082,8 @@ def test_signature_eval_str(self):
40804082
par('c', PORK, annotation="'MyClass'"),
40814083
)))
40824084

4083-
self.assertEqual(signature_func(isa.UnannotatedClass), sig())
4085+
if not MISSING_C_DOCSTRINGS:
4086+
self.assertEqual(signature_func(isa.UnannotatedClass), sig())
40844087
self.assertEqual(signature_func(isa.unannotated_function),
40854088
sig(
40864089
parameters=(

Lib/test/test_module/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_uninitialized(self):
3030
self.fail("__name__ = %s" % repr(s))
3131
except AttributeError:
3232
pass
33-
self.assertEqual(foo.__doc__, ModuleType.__doc__)
33+
self.assertEqual(foo.__doc__, ModuleType.__doc__ or '')
3434

3535
def test_uninitialized_missing_getattr(self):
3636
# Issue 8297

Lib/test/test_pydoc.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from test.support import threading_helper
3333
from test.support import (reap_children, captured_output, captured_stdout,
3434
captured_stderr, is_emscripten, is_wasi,
35-
requires_docstrings)
35+
requires_docstrings, MISSING_C_DOCSTRINGS)
3636
from test.support.os_helper import (TESTFN, rmtree, unlink)
3737
from test import pydoc_mod
3838

@@ -906,12 +906,13 @@ class A(builtins.object)
906906
| ----------------------------------------------------------------------
907907
| Data descriptors defined here:
908908
|
909-
| __dict__
910-
| dictionary for instance variables
909+
| __dict__%s
911910
|
912-
| __weakref__
913-
| list of weak references to the object
914-
''' % __name__)
911+
| __weakref__%s
912+
''' % (__name__,
913+
'' if MISSING_C_DOCSTRINGS else '\n | dictionary for instance variables',
914+
'' if MISSING_C_DOCSTRINGS else '\n | list of weak references to the object',
915+
))
915916

916917
def func(
917918
arg1: Callable[[Annotated[int, 'Some doc']], str],
@@ -1154,13 +1155,15 @@ def test_generic_alias(self):
11541155
doc = pydoc.render_doc(typing.List[int], renderer=pydoc.plaintext)
11551156
self.assertIn('_GenericAlias in module typing', doc)
11561157
self.assertIn('List = class list(object)', doc)
1157-
self.assertIn(list.__doc__.strip().splitlines()[0], doc)
1158+
if not MISSING_C_DOCSTRINGS:
1159+
self.assertIn(list.__doc__.strip().splitlines()[0], doc)
11581160

11591161
self.assertEqual(pydoc.describe(list[int]), 'GenericAlias')
11601162
doc = pydoc.render_doc(list[int], renderer=pydoc.plaintext)
11611163
self.assertIn('GenericAlias in module builtins', doc)
11621164
self.assertIn('\nclass list(object)', doc)
1163-
self.assertIn(list.__doc__.strip().splitlines()[0], doc)
1165+
if not MISSING_C_DOCSTRINGS:
1166+
self.assertIn(list.__doc__.strip().splitlines()[0], doc)
11641167

11651168
def test_union_type(self):
11661169
self.assertEqual(pydoc.describe(typing.Union[int, str]), '_UnionGenericAlias')
@@ -1174,7 +1177,8 @@ def test_union_type(self):
11741177
doc = pydoc.render_doc(int | str, renderer=pydoc.plaintext)
11751178
self.assertIn('UnionType in module types object', doc)
11761179
self.assertIn('\nclass UnionType(builtins.object)', doc)
1177-
self.assertIn(types.UnionType.__doc__.strip().splitlines()[0], doc)
1180+
if not MISSING_C_DOCSTRINGS:
1181+
self.assertIn(types.UnionType.__doc__.strip().splitlines()[0], doc)
11781182

11791183
def test_special_form(self):
11801184
self.assertEqual(pydoc.describe(typing.NoReturn), '_SpecialForm')
@@ -1327,13 +1331,15 @@ def test_bound_builtin_classmethod_o(self):
13271331
"__class_getitem__(object, /) method of builtins.type instance")
13281332

13291333
@support.cpython_only
1334+
@requires_docstrings
13301335
def test_module_level_callable_unrepresentable_default(self):
13311336
import _testcapi
13321337
builtin = _testcapi.func_with_unrepresentable_signature
13331338
self.assertEqual(self._get_summary_line(builtin),
13341339
"func_with_unrepresentable_signature(a, b=<x>)")
13351340

13361341
@support.cpython_only
1342+
@requires_docstrings
13371343
def test_builtin_staticmethod_unrepresentable_default(self):
13381344
self.assertEqual(self._get_summary_line(str.maketrans),
13391345
"maketrans(x, y=<unrepresentable>, z=<unrepresentable>, /)")
@@ -1343,6 +1349,7 @@ def test_builtin_staticmethod_unrepresentable_default(self):
13431349
"staticmeth(a, b=<x>)")
13441350

13451351
@support.cpython_only
1352+
@requires_docstrings
13461353
def test_unbound_builtin_method_unrepresentable_default(self):
13471354
self.assertEqual(self._get_summary_line(dict.pop),
13481355
"pop(self, key, default=<unrepresentable>, /)")
@@ -1352,6 +1359,7 @@ def test_unbound_builtin_method_unrepresentable_default(self):
13521359
"meth(self, /, a, b=<x>)")
13531360

13541361
@support.cpython_only
1362+
@requires_docstrings
13551363
def test_bound_builtin_method_unrepresentable_default(self):
13561364
self.assertEqual(self._get_summary_line({}.pop),
13571365
"pop(key, default=<unrepresentable>, /) "
@@ -1363,6 +1371,7 @@ def test_bound_builtin_method_unrepresentable_default(self):
13631371
"method of _testcapi.DocStringUnrepresentableSignatureTest instance")
13641372

13651373
@support.cpython_only
1374+
@requires_docstrings
13661375
def test_unbound_builtin_classmethod_unrepresentable_default(self):
13671376
import _testcapi
13681377
cls = _testcapi.DocStringUnrepresentableSignatureTest
@@ -1371,6 +1380,7 @@ def test_unbound_builtin_classmethod_unrepresentable_default(self):
13711380
"classmeth(type, /, a, b=<x>)")
13721381

13731382
@support.cpython_only
1383+
@requires_docstrings
13741384
def test_bound_builtin_classmethod_unrepresentable_default(self):
13751385
import _testcapi
13761386
cls = _testcapi.DocStringUnrepresentableSignatureTest

Lib/test/test_rlcompleter.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from unittest.mock import patch
33
import builtins
44
import rlcompleter
5+
from test.support import MISSING_C_DOCSTRINGS
56

67
class CompleteMe:
78
""" Trivial class used in testing rlcompleter.Completer. """
@@ -40,12 +41,12 @@ def test_global_matches(self):
4041

4142
# test with a customized namespace
4243
self.assertEqual(self.completer.global_matches('CompleteM'),
43-
['CompleteMe()'])
44+
['CompleteMe(' if MISSING_C_DOCSTRINGS else 'CompleteMe()'])
4445
self.assertEqual(self.completer.global_matches('eg'),
4546
['egg('])
4647
# XXX: see issue5256
4748
self.assertEqual(self.completer.global_matches('CompleteM'),
48-
['CompleteMe()'])
49+
['CompleteMe(' if MISSING_C_DOCSTRINGS else 'CompleteMe()'])
4950

5051
def test_attr_matches(self):
5152
# test with builtins namespace

Lib/test/test_types.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Python test set -- part 6, built-in types
22

3-
from test.support import run_with_locale, cpython_only
3+
from test.support import run_with_locale, cpython_only, MISSING_C_DOCSTRINGS
44
import collections.abc
55
from collections import namedtuple
66
import copy
@@ -598,6 +598,8 @@ def test_slot_wrapper_types(self):
598598
self.assertIsInstance(object.__lt__, types.WrapperDescriptorType)
599599
self.assertIsInstance(int.__lt__, types.WrapperDescriptorType)
600600

601+
@unittest.skipIf(MISSING_C_DOCSTRINGS,
602+
"Signature information for builtins requires docstrings")
601603
def test_dunder_get_signature(self):
602604
sig = inspect.signature(object.__init__.__get__)
603605
self.assertEqual(list(sig.parameters), ["instance", "owner"])

Lib/test/test_zoneinfo/test_zoneinfo.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from datetime import date, datetime, time, timedelta, timezone
1818
from functools import cached_property
1919

20+
from test.support import MISSING_C_DOCSTRINGS
2021
from test.test_zoneinfo import _support as test_support
2122
from test.test_zoneinfo._support import OS_ENV_LOCK, TZPATH_TEST_LOCK, ZoneInfoTestBase
2223
from test.support.import_helper import import_module
@@ -404,6 +405,8 @@ def test_time_fixed_offset(self):
404405
class CZoneInfoTest(ZoneInfoTest):
405406
module = c_zoneinfo
406407

408+
@unittest.skipIf(MISSING_C_DOCSTRINGS,
409+
"Signature information for builtins requires docstrings")
407410
def test_signatures(self):
408411
"""Ensure that C module has valid method signatures."""
409412
import inspect

0 commit comments

Comments
 (0)