Skip to content

Commit e4bbea8

Browse files
committed
Fix test_sys_module_has_signatures: METH_NOARGS never has None text signature
METH_NOARGS functions always produce '($self, /)' as their __text_signature__ via signature_from_flags() in Objects/typeobject.c, not None. Placing sys.__dir__ in the no_signature set (which assertIsNone(__text_signature__)) therefore always fails. Remove '__dir__' from no_signature. Since __dir__ is non-public (starts with '__') it is not included in the is_public() filter, so no assertion is made about it in the supported-signatures loop either. The '($self, /)' signature returned by inspect.signature(sys.__dir__) (empty visible params) is correct. sys.__getattr__ stays in no_signature: METH_VARARGS has no fallback in signature_from_flags() so its __text_signature__ is genuinely None.
1 parent 46c6033 commit e4bbea8

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

Lib/test/test_inspect/test_inspect.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6179,9 +6179,11 @@ def test_sys_module_has_signatures(self):
61796179
no_signature = {'getsizeof', 'set_asyncgen_hooks'}
61806180
no_signature |= {name for name in ['getobjects']
61816181
if hasattr(sys, name)}
6182-
# sys.__dir__ and sys.__getattr__ are plain METH_NOARGS/METH_VARARGS
6183-
# builtins without Argument Clinic text signatures.
6184-
no_signature |= {'__dir__', '__getattr__'}
6182+
# sys.__getattr__ is METH_VARARGS without an Argument Clinic signature.
6183+
# sys.__dir__ is METH_NOARGS; METH_NOARGS always produces '($self, /)'
6184+
# via signature_from_flags(), not None, so it must not be in no_signature.
6185+
# __dir__ is non-public so it is not checked in the supported loop either.
6186+
no_signature |= {'__getattr__'}
61856187
self._test_module_has_signatures(sys, no_signature)
61866188

61876189
def test_abc_module_has_signatures(self):

0 commit comments

Comments
 (0)