diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2011-10-19 11:06:26 +0300 |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2011-10-19 11:06:26 +0300 |
commit | 2b4338c5e090fa94a32d5cd7154aef5dfe25e6da (patch) | |
tree | 665a409563a70f93da9fb962f7a7da81aee8b93f /Lib/abc.py | |
parent | 0ab6fc6fe33837bc950d2cb0a5cf2a25579f8f3e (diff) | |
parent | 22388c044ed1680554f5c8b1ef9dc1deaa84ad08 (diff) | |
download | cpython-2b4338c5e090fa94a32d5cd7154aef5dfe25e6da.tar.gz |
Merge with 3.2.
Diffstat (limited to 'Lib/abc.py')
-rw-r--r-- | Lib/abc.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/abc.py b/Lib/abc.py index a6c2dc4877..40f88b92c0 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.""" |