gh-118404: Fix inspect.signature() for non-comparable callables (GH-118405)

This commit is contained in:
Serhiy Storchaka 2024-04-30 15:04:16 +03:00 committed by GitHub
parent 5b05d452cd
commit 11f8348d78
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 2 deletions

View File

@ -2179,8 +2179,10 @@ def _signature_is_builtin(obj):
ismethoddescriptor(obj) or
isinstance(obj, _NonUserDefinedCallables) or
# Can't test 'isinstance(type)' here, as it would
# also be True for regular python classes
obj in (type, object))
# also be True for regular python classes.
# Can't use the `in` operator here, as it would
# invoke the custom __eq__ method.
obj is type or obj is object)
def _signature_is_functionlike(obj):

View File

@ -4690,6 +4690,16 @@ class TestSignatureObject(unittest.TestCase):
self.assertEqual(inspect.signature(D2), inspect.signature(D1))
def test_signature_on_non_comparable(self):
class NoncomparableCallable:
def __call__(self, a):
pass
def __eq__(self, other):
1/0
self.assertEqual(self.signature(NoncomparableCallable()),
((('a', ..., ..., 'positional_or_keyword'),),
...))
class TestParameterObject(unittest.TestCase):
def test_signature_parameter_kinds(self):

View File

@ -0,0 +1 @@
Fix :func:`inspect.signature` for non-comparable callables.