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

(cherry picked from commit fc7df0e664)

Co-authored-by: INADA Naoki <methane@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2018-03-06 23:47:40 -08:00 committed by GitHub
parent c4d77a6611
commit d824b4e4af
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