mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
Backmerge -r59233:59232
Guido said: Please roll this back. The error message you added is inappropriate when the parameter to a legitimate register() call is omitted, e.g. collections.Sequence.register()
This commit is contained in:
parent
7d2ff884ee
commit
45031dfd1c
2 changed files with 1 additions and 11 deletions
|
@ -137,11 +137,8 @@ class ABCMeta(type):
|
||||||
cls._abc_negative_cache_version = ABCMeta._abc_invalidation_counter
|
cls._abc_negative_cache_version = ABCMeta._abc_invalidation_counter
|
||||||
return cls
|
return cls
|
||||||
|
|
||||||
def register(cls, subclass=None):
|
def register(cls, subclass):
|
||||||
"""Register a virtual subclass of an ABC."""
|
"""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):
|
if not isinstance(cls, type):
|
||||||
raise TypeError("Can only register classes")
|
raise TypeError("Can only register classes")
|
||||||
if issubclass(subclass, cls):
|
if issubclass(subclass, cls):
|
||||||
|
|
|
@ -146,13 +146,6 @@ class TestABC(unittest.TestCase):
|
||||||
C()
|
C()
|
||||||
self.assertEqual(B.counter, 1)
|
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():
|
def test_main():
|
||||||
test_support.run_unittest(TestABC)
|
test_support.run_unittest(TestABC)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue