bpo-38689: avoid IDLE hanging when calltip fails getting a signature (GH-17152)

Inspect.signature failed on the test case because its isinstance call raised.
This commit is contained in:
Tal Einat 2020-04-04 06:05:58 +03:00 committed by GitHub
parent 6e623ff9d2
commit 52013e5b6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 15 deletions

View file

@ -219,20 +219,30 @@ bytes() -> empty bytes object''')
with self.subTest(meth=meth, mtip=mtip):
self.assertEqual(get_spec(meth), mtip)
def test_attribute_exception(self):
def test_buggy_getattr_class(self):
class NoCall:
def __getattr__(self, name):
raise BaseException
def __getattr__(self, name): # Not invoked for class attribute.
raise IndexError # Bug.
class CallA(NoCall):
def __call__(oui, a, b, c):
def __call__(self, ci): # Bug does not matter.
pass
class CallB(NoCall):
def __call__(self, ci):
def __call__(oui, a, b, c): # Non-standard 'self'.
pass
for meth, mtip in ((NoCall, default_tip), (CallA, default_tip),
(NoCall(), ''), (CallA(), '(a, b, c)'),
(CallB(), '(ci)')):
(NoCall(), ''), (CallA(), '(ci)'),
(CallB(), '(a, b, c)')):
with self.subTest(meth=meth, mtip=mtip):
self.assertEqual(get_spec(meth), mtip)
def test_metaclass_class(self): # Failure case for issue 38689.
class Type(type): # Type() requires 3 type args, returns class.
__class__ = property({}.__getitem__, {}.__setitem__)
class Object(metaclass=Type):
__slots__ = '__class__'
for meth, mtip in ((Type, default_tip), (Object, default_tip),
(Object(), '')):
with self.subTest(meth=meth, mtip=mtip):
self.assertEqual(get_spec(meth), mtip)