Kaydet (Commit) fd1c2451 authored tarafından Jeffrey Yasskin's avatar Jeffrey Yasskin

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

ABCs.
üst 1db6f80c
......@@ -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)
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment