summaryrefslogtreecommitdiffstats
path: root/Lib/abc.py
diff options
context:
space:
mode:
authorŁukasz Langa <lukasz@langa.pl>2013-05-25 16:41:50 (GMT)
committerŁukasz Langa <lukasz@langa.pl>2013-05-25 16:41:50 (GMT)
commiteadd8cf507e876a6ea4c338a0004954d2d732ac0 (patch)
tree5231b12d19eacda81a3eb49f85265fd099619276 /Lib/abc.py
parentb961955e95107e7667944e91bea50bfb760285b7 (diff)
downloadcpython-eadd8cf507e876a6ea4c338a0004954d2d732ac0.zip
cpython-eadd8cf507e876a6ea4c338a0004954d2d732ac0.tar.gz
cpython-eadd8cf507e876a6ea4c338a0004954d2d732ac0.tar.bz2
Fix #16832 - expose cache validity checking support in ABCMeta
Diffstat (limited to 'Lib/abc.py')
-rw-r--r--Lib/abc.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/abc.py b/Lib/abc.py
index e807895..264c60c 100644
--- a/Lib/abc.py
+++ b/Lib/abc.py
@@ -5,6 +5,7 @@
from _weakrefset import WeakSet
+
def abstractmethod(funcobj):
"""A decorator indicating abstract methods.
@@ -124,6 +125,8 @@ class ABCMeta(type):
# A global counter that is incremented each time a class is
# registered as a virtual subclass of anything. It forces the
# negative cache to be cleared before its next use.
+ # Note: this counter is private. Use `abc.get_cache_token()` for
+ # external code.
_abc_invalidation_counter = 0
def __new__(mcls, name, bases, namespace):
@@ -227,8 +230,19 @@ class ABCMeta(type):
cls._abc_negative_cache.add(subclass)
return False
+
class ABC(metaclass=ABCMeta):
"""Helper class that provides a standard way to create an ABC using
inheritance.
"""
pass
+
+
+def get_cache_token():
+ """Returns the current ABC cache token.
+
+ The token is an opaque integer identifying the current version of
+ the ABC cache for virtual subclasses. This number changes with
+ every call to ``register()`` on any ABC.
+ """
+ return ABCMeta._abc_invalidation_counter