summaryrefslogtreecommitdiffstats
path: root/Lib/abc.py
diff options
context:
space:
mode:
authorÉric Araujo <merwok@netwok.org>2011-02-24 18:03:10 (GMT)
committerÉric Araujo <merwok@netwok.org>2011-02-24 18:03:10 (GMT)
commit6c3787cb70d8efa5f70939a5db300f56a724d698 (patch)
treebab3ed85944db0993682255f1bb751c788f38001 /Lib/abc.py
parent5390d00cc6b99a375140f22e8d75580c1f4cb0a4 (diff)
downloadcpython-6c3787cb70d8efa5f70939a5db300f56a724d698.zip
cpython-6c3787cb70d8efa5f70939a5db300f56a724d698.tar.gz
cpython-6c3787cb70d8efa5f70939a5db300f56a724d698.tar.bz2
Allow usage of SomeABC.register as a class decorator. Patch by Edoardo Spadolini (#10868).
Diffstat (limited to 'Lib/abc.py')
-rw-r--r--Lib/abc.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/abc.py b/Lib/abc.py
index a6c2dc4..40f88b9 100644
--- a/Lib/abc.py
+++ b/Lib/abc.py
@@ -133,11 +133,14 @@ class ABCMeta(type):
return cls
def register(cls, subclass):
- """Register a virtual subclass of an ABC."""
+ """Register a virtual subclass of an ABC.
+
+ Returns the subclass, to allow usage as a class decorator.
+ """
if not isinstance(subclass, type):
raise TypeError("Can only register classes")
if issubclass(subclass, cls):
- return # Already a subclass
+ return subclass # Already a subclass
# Subtle: test for cycles *after* testing for "already a subclass";
# this means we allow X.register(X) and interpret it as a no-op.
if issubclass(cls, subclass):
@@ -145,6 +148,7 @@ class ABCMeta(type):
raise RuntimeError("Refusing to create an inheritance cycle")
cls._abc_registry.add(subclass)
ABCMeta._abc_invalidation_counter += 1 # Invalidate negative cache
+ return subclass
def _dump_registry(cls, file=None):
"""Debug helper to print the ABC registry."""