bpo-32999: Fix ABC.__subclasscheck__ crash (GH-6002)

This commit is contained in:
INADA Naoki 2018-03-07 16:27:01 +09:00 committed by GitHub
parent bc3f2289b9
commit fc7df0e664
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 12 deletions

View file

@ -392,6 +392,24 @@ def test_factory(abc_ABCMeta, abc_get_cache_token):
self.assertIsInstance(42, A)
self.assertIsInstance(42, (A,))
def test_issubclass_bad_arguments(self):
class A(metaclass=abc_ABCMeta):
pass
with self.assertRaises(TypeError):
issubclass({}, A) # unhashable
with self.assertRaises(TypeError):
issubclass(42, A) # No __mro__
# Python version supports any iterable as __mro__.
# But it's implementation detail and don't emulate it in C version.
class C:
__mro__ = 42 # __mro__ is not tuple
with self.assertRaises(TypeError):
issubclass(C(), A)
def test_all_new_methods_are_called(self):
class A(metaclass=abc_ABCMeta):
pass