Kaydet (Commit) 2e510fb9 authored tarafından Christian Heimes's avatar Christian Heimes

Fix for bug #1109

Warning required when calling register() on an ABCMeta subclass.
üst c8967002
......@@ -137,8 +137,11 @@ class ABCMeta(type):
cls._abc_negative_cache_version = ABCMeta._abc_invalidation_counter
return cls
def register(cls, subclass):
def register(cls, subclass=None):
"""Register a virtual subclass of an ABC."""
if subclass is None:
raise TypeError("register() cannot be called on an ABCMeta "
"subclass, use class Example(metaclass=abc.ABCMeta) instead.")
if not isinstance(cls, type):
raise TypeError("Can only register classes")
if issubclass(subclass, cls):
......
......@@ -146,6 +146,13 @@ class TestABC(unittest.TestCase):
C()
self.assertEqual(B.counter, 1)
def test_error_on_subclass(self):
class A(abc.ABCMeta):
pass
class B:
pass
self.assertRaises(TypeError, A.register, B)
def test_main():
test_support.run_unittest(TestABC)
......
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