Fix issue 1747: allow classic classes to be checked for being subclasses of

ABCs.
This commit is contained in:
Jeffrey Yasskin 2008-01-07 06:09:40 +00:00
parent 1db6f80cd5
commit fd1c24518b
2 changed files with 12 additions and 5 deletions

View File

@ -188,7 +188,7 @@ class ABCMeta(type):
cls._abc_negative_cache.add(subclass)
return ok
# Check if it's a direct subclass
if cls in subclass.__mro__:
if cls in getattr(subclass, '__mro__', ()):
cls._abc_cache.add(subclass)
return True
# Check if it's a subclass of a registered class (recursive)

View File

@ -8,7 +8,6 @@ import unittest
from test import test_support
import abc
__metaclass__ = type
class TestABC(unittest.TestCase):
@ -59,10 +58,18 @@ class TestABC(unittest.TestCase):
self.assertEqual(F.__abstractmethods__, set(["bar"]))
self.assertRaises(TypeError, F) # because bar is abstract now
def test_subclass_oldstyle_class(self):
class A:
__metaclass__ = abc.ABCMeta
class OldstyleClass:
pass
self.assertFalse(issubclass(OldstyleClass, A))
self.assertFalse(issubclass(A, OldstyleClass))
def test_registration_basics(self):
class A:
__metaclass__ = abc.ABCMeta
class B:
class B(object):
pass
b = B()
self.assertEqual(issubclass(B, A), False)
@ -95,7 +102,7 @@ class TestABC(unittest.TestCase):
class A1(A):
pass
self.assertRaises(RuntimeError, A1.register, A) # cycles not allowed
class B:
class B(object):
pass
A1.register(B) # ok
A1.register(B) # should pass silently
@ -136,7 +143,7 @@ class TestABC(unittest.TestCase):
def test_all_new_methods_are_called(self):
class A:
__metaclass__ = abc.ABCMeta
class B:
class B(object):
counter = 0
def __new__(cls):
B.counter += 1