annotate Lib/abc.py @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents 5b17d5ca2ff1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42087
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 # Copyright 2007 Google, Inc. All Rights Reserved.
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 # Licensed to PSF under a Contributor Agreement.
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 """Abstract Base Classes (ABCs) according to PEP 3119."""
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
45159
e6069b24031e Moved WeakSet into a bootstap module use by abc.py.
Raymond Hettinger <python@rcn.com>
parents: 44568
diff changeset
6 from _weakrefset import WeakSet
42087
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
83929
5b17d5ca2ff1 Fix #16832 - expose cache validity checking support in ABCMeta
Łukasz Langa <lukasz@langa.pl>
parents: 80840
diff changeset
8
42087
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 def abstractmethod(funcobj):
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 """A decorator indicating abstract methods.
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 Requires that the metaclass is ABCMeta or derived from it. A
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 class that has a metaclass derived from ABCMeta cannot be
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 instantiated unless all of its abstract methods are overridden.
53738
73af90206cbe Merged revisions 72280 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 48960
diff changeset
15 The abstract methods can be called using any of the normal
42087
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 'super' call mechanisms.
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
17
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 Usage:
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
19
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 class C(metaclass=ABCMeta):
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 @abstractmethod
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 def my_abstract_method(self, ...):
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 ...
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 """
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 funcobj.__isabstractmethod__ = True
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 return funcobj
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
27
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
28
64094
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
29 class abstractclassmethod(classmethod):
73984
e979b26a9172 improve abstract property support (closes #11610)
Benjamin Peterson <benjamin@python.org>
parents: 68125
diff changeset
30 """
e979b26a9172 improve abstract property support (closes #11610)
Benjamin Peterson <benjamin@python.org>
parents: 68125
diff changeset
31 A decorator indicating abstract classmethods.
64094
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
32
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
33 Similar to abstractmethod.
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
34
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
35 Usage:
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
36
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
37 class C(metaclass=ABCMeta):
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
38 @abstractclassmethod
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
39 def my_abstract_classmethod(cls, ...):
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
40 ...
73984
e979b26a9172 improve abstract property support (closes #11610)
Benjamin Peterson <benjamin@python.org>
parents: 68125
diff changeset
41
e979b26a9172 improve abstract property support (closes #11610)
Benjamin Peterson <benjamin@python.org>
parents: 68125
diff changeset
42 'abstractclassmethod' is deprecated. Use 'classmethod' with
e979b26a9172 improve abstract property support (closes #11610)
Benjamin Peterson <benjamin@python.org>
parents: 68125
diff changeset
43 'abstractmethod' instead.
64094
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
44 """
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
45
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
46 __isabstractmethod__ = True
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
47
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
48 def __init__(self, callable):
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
49 callable.__isabstractmethod__ = True
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
50 super().__init__(callable)
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
51
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
52
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
53 class abstractstaticmethod(staticmethod):
73984
e979b26a9172 improve abstract property support (closes #11610)
Benjamin Peterson <benjamin@python.org>
parents: 68125
diff changeset
54 """
e979b26a9172 improve abstract property support (closes #11610)
Benjamin Peterson <benjamin@python.org>
parents: 68125
diff changeset
55 A decorator indicating abstract staticmethods.
64094
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
56
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
57 Similar to abstractmethod.
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
58
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
59 Usage:
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
60
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
61 class C(metaclass=ABCMeta):
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
62 @abstractstaticmethod
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
63 def my_abstract_staticmethod(...):
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
64 ...
73984
e979b26a9172 improve abstract property support (closes #11610)
Benjamin Peterson <benjamin@python.org>
parents: 68125
diff changeset
65
e979b26a9172 improve abstract property support (closes #11610)
Benjamin Peterson <benjamin@python.org>
parents: 68125
diff changeset
66 'abstractstaticmethod' is deprecated. Use 'staticmethod' with
e979b26a9172 improve abstract property support (closes #11610)
Benjamin Peterson <benjamin@python.org>
parents: 68125
diff changeset
67 'abstractmethod' instead.
64094
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
68 """
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
69
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
70 __isabstractmethod__ = True
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
71
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
72 def __init__(self, callable):
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
73 callable.__isabstractmethod__ = True
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
74 super().__init__(callable)
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
75
b91059e59d0d add support for abstract class and static methods #5867
Benjamin Peterson <benjamin@python.org>
parents: 58533
diff changeset
76
42413
392f98221d13 Add @abstractproperty.
Guido van Rossum <guido@python.org>
parents: 42092
diff changeset
77 class abstractproperty(property):
73984
e979b26a9172 improve abstract property support (closes #11610)
Benjamin Peterson <benjamin@python.org>
parents: 68125
diff changeset
78 """
e979b26a9172 improve abstract property support (closes #11610)
Benjamin Peterson <benjamin@python.org>
parents: 68125
diff changeset
79 A decorator indicating abstract properties.
42413
392f98221d13 Add @abstractproperty.
Guido van Rossum <guido@python.org>
parents: 42092
diff changeset
80
392f98221d13 Add @abstractproperty.
Guido van Rossum <guido@python.org>
parents: 42092
diff changeset
81 Requires that the metaclass is ABCMeta or derived from it. A
392f98221d13 Add @abstractproperty.
Guido van Rossum <guido@python.org>
parents: 42092
diff changeset
82 class that has a metaclass derived from ABCMeta cannot be
392f98221d13 Add @abstractproperty.
Guido van Rossum <guido@python.org>
parents: 42092
diff changeset
83 instantiated unless all of its abstract properties are overridden.
53738
73af90206cbe Merged revisions 72280 via svnmerge from
Walter Dörwald <walter@livinglogic.de>
parents: 48960
diff changeset
84 The abstract properties can be called using any of the normal
42415
a6d26a4d672d Tests for @abstractproperty by Jeffrey Yasskin.
Guido van Rossum <guido@python.org>
parents: 42413
diff changeset
85 'super' call mechanisms.
42413
392f98221d13 Add @abstractproperty.
Guido van Rossum <guido@python.org>
parents: 42092
diff changeset
86
392f98221d13 Add @abstractproperty.
Guido van Rossum <guido@python.org>
parents: 42092
diff changeset
87 Usage:
392f98221d13 Add @abstractproperty.
Guido van Rossum <guido@python.org>
parents: 42092
diff changeset
88
392f98221d13 Add @abstractproperty.
Guido van Rossum <guido@python.org>
parents: 42092
diff changeset
89 class C(metaclass=ABCMeta):
392f98221d13 Add @abstractproperty.
Guido van Rossum <guido@python.org>
parents: 42092
diff changeset
90 @abstractproperty
392f98221d13 Add @abstractproperty.
Guido van Rossum <guido@python.org>
parents: 42092
diff changeset
91 def my_abstract_property(self):
392f98221d13 Add @abstractproperty.
Guido van Rossum <guido@python.org>
parents: 42092
diff changeset
92 ...
392f98221d13 Add @abstractproperty.
Guido van Rossum <guido@python.org>
parents: 42092
diff changeset
93
392f98221d13 Add @abstractproperty.
Guido van Rossum <guido@python.org>
parents: 42092
diff changeset
94 This defines a read-only property; you can also define a read-write
392f98221d13 Add @abstractproperty.
Guido van Rossum <guido@python.org>
parents: 42092
diff changeset
95 abstract property using the 'long' form of property declaration:
392f98221d13 Add @abstractproperty.
Guido van Rossum <guido@python.org>
parents: 42092
diff changeset
96
392f98221d13 Add @abstractproperty.
Guido van Rossum <guido@python.org>
parents: 42092
diff changeset
97 class C(metaclass=ABCMeta):
392f98221d13 Add @abstractproperty.
Guido van Rossum <guido@python.org>
parents: 42092
diff changeset
98 def getx(self): ...
392f98221d13 Add @abstractproperty.
Guido van Rossum <guido@python.org>
parents: 42092
diff changeset
99 def setx(self, value): ...
392f98221d13 Add @abstractproperty.
Guido van Rossum <guido@python.org>
parents: 42092
diff changeset
100 x = abstractproperty(getx, setx)
73984
e979b26a9172 improve abstract property support (closes #11610)
Benjamin Peterson <benjamin@python.org>
parents: 68125
diff changeset
101
e979b26a9172 improve abstract property support (closes #11610)
Benjamin Peterson <benjamin@python.org>
parents: 68125
diff changeset
102 'abstractproperty' is deprecated. Use 'property' with 'abstractmethod'
e979b26a9172 improve abstract property support (closes #11610)
Benjamin Peterson <benjamin@python.org>
parents: 68125
diff changeset
103 instead.
42413
392f98221d13 Add @abstractproperty.
Guido van Rossum <guido@python.org>
parents: 42092
diff changeset
104 """
73984
e979b26a9172 improve abstract property support (closes #11610)
Benjamin Peterson <benjamin@python.org>
parents: 68125
diff changeset
105
42413
392f98221d13 Add @abstractproperty.
Guido van Rossum <guido@python.org>
parents: 42092
diff changeset
106 __isabstractmethod__ = True
392f98221d13 Add @abstractproperty.
Guido van Rossum <guido@python.org>
parents: 42092
diff changeset
107
392f98221d13 Add @abstractproperty.
Guido van Rossum <guido@python.org>
parents: 42092
diff changeset
108
42087
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 class ABCMeta(type):
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
110
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 """Metaclass for defining Abstract Base Classes (ABCs).
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
112
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 Use this metaclass to create an ABC. An ABC can be subclassed
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 directly, and then acts as a mix-in class. You can also register
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 unrelated concrete classes (even built-in classes) and unrelated
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 ABCs as 'virtual subclasses' -- these and their descendants will
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 be considered subclasses of the registering ABC by the built-in
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 issubclass() function, but the registering ABC won't show up in
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 their MRO (Method Resolution Order) nor will method
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 implementations defined by the registering ABC be callable (not
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 even via super()).
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
122
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 """
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
124
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 # A global counter that is incremented each time a class is
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 # registered as a virtual subclass of anything. It forces the
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 # negative cache to be cleared before its next use.
83929
5b17d5ca2ff1 Fix #16832 - expose cache validity checking support in ABCMeta
Łukasz Langa <lukasz@langa.pl>
parents: 80840
diff changeset
128 # Note: this counter is private. Use `abc.get_cache_token()` for
5b17d5ca2ff1 Fix #16832 - expose cache validity checking support in ABCMeta
Łukasz Langa <lukasz@langa.pl>
parents: 80840
diff changeset
129 # external code.
42680
2f4679301132 Rename __whatever variables defined by ABCMeta to _abc_whatever, so as
Guido van Rossum <guido@python.org>
parents: 42662
diff changeset
130 _abc_invalidation_counter = 0
42087
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
131
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 def __new__(mcls, name, bases, namespace):
42092
d17a27247986 Modernize the super() call in ABCMeta.__new__() -- I had messed with
Guido van Rossum <guido@python.org>
parents: 42087
diff changeset
133 cls = super().__new__(mcls, name, bases, namespace)
42087
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 # Compute set of abstract method names
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 abstracts = {name
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 for name, value in namespace.items()
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 if getattr(value, "__isabstractmethod__", False)}
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 for base in bases:
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 for name in getattr(base, "__abstractmethods__", set()):
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 value = getattr(cls, name, None)
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 if getattr(value, "__isabstractmethod__", False):
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 abstracts.add(name)
45549
8dd30fe11a4b Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45333
diff changeset
143 cls.__abstractmethods__ = frozenset(abstracts)
42087
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 # Set up inheritance registry
43644
95d8c913e8bf #1061 (mainly by Thomas Wouters): use weak sets for abc caches.
Georg Brandl <georg@python.org>
parents: 43334
diff changeset
145 cls._abc_registry = WeakSet()
95d8c913e8bf #1061 (mainly by Thomas Wouters): use weak sets for abc caches.
Georg Brandl <georg@python.org>
parents: 43334
diff changeset
146 cls._abc_cache = WeakSet()
95d8c913e8bf #1061 (mainly by Thomas Wouters): use weak sets for abc caches.
Georg Brandl <georg@python.org>
parents: 43334
diff changeset
147 cls._abc_negative_cache = WeakSet()
42680
2f4679301132 Rename __whatever variables defined by ABCMeta to _abc_whatever, so as
Guido van Rossum <guido@python.org>
parents: 42662
diff changeset
148 cls._abc_negative_cache_version = ABCMeta._abc_invalidation_counter
42087
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 return cls
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
150
44067
3cebde478cc4 Backmerge -r59233:59232
Christian Heimes <christian@cheimes.de>
parents: 44065
diff changeset
151 def register(cls, subclass):
68125
db7ef34eedaf Allow usage of SomeABC.register as a class decorator. Patch by Edoardo Spadolini (#10868).
Éric Araujo <merwok@netwok.org>
parents: 64094
diff changeset
152 """Register a virtual subclass of an ABC.
db7ef34eedaf Allow usage of SomeABC.register as a class decorator. Patch by Edoardo Spadolini (#10868).
Éric Araujo <merwok@netwok.org>
parents: 64094
diff changeset
153
db7ef34eedaf Allow usage of SomeABC.register as a class decorator. Patch by Edoardo Spadolini (#10868).
Éric Araujo <merwok@netwok.org>
parents: 64094
diff changeset
154 Returns the subclass, to allow usage as a class decorator.
db7ef34eedaf Allow usage of SomeABC.register as a class decorator. Patch by Edoardo Spadolini (#10868).
Éric Araujo <merwok@netwok.org>
parents: 64094
diff changeset
155 """
58533
e660cb52bf00 Merged revisions 77789 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 53738
diff changeset
156 if not isinstance(subclass, type):
42087
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 raise TypeError("Can only register classes")
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 if issubclass(subclass, cls):
68125
db7ef34eedaf Allow usage of SomeABC.register as a class decorator. Patch by Edoardo Spadolini (#10868).
Éric Araujo <merwok@netwok.org>
parents: 64094
diff changeset
159 return subclass # Already a subclass
42087
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 # Subtle: test for cycles *after* testing for "already a subclass";
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 # this means we allow X.register(X) and interpret it as a no-op.
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 if issubclass(cls, subclass):
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 # This would create a cycle, which is bad for the algorithm below
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 raise RuntimeError("Refusing to create an inheritance cycle")
42680
2f4679301132 Rename __whatever variables defined by ABCMeta to _abc_whatever, so as
Guido van Rossum <guido@python.org>
parents: 42662
diff changeset
165 cls._abc_registry.add(subclass)
2f4679301132 Rename __whatever variables defined by ABCMeta to _abc_whatever, so as
Guido van Rossum <guido@python.org>
parents: 42662
diff changeset
166 ABCMeta._abc_invalidation_counter += 1 # Invalidate negative cache
68125
db7ef34eedaf Allow usage of SomeABC.register as a class decorator. Patch by Edoardo Spadolini (#10868).
Éric Araujo <merwok@netwok.org>
parents: 64094
diff changeset
167 return subclass
42087
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
168
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 def _dump_registry(cls, file=None):
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 """Debug helper to print the ABC registry."""
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
171 print("Class: %s.%s" % (cls.__module__, cls.__name__), file=file)
42680
2f4679301132 Rename __whatever variables defined by ABCMeta to _abc_whatever, so as
Guido van Rossum <guido@python.org>
parents: 42662
diff changeset
172 print("Inv.counter: %s" % ABCMeta._abc_invalidation_counter, file=file)
42087
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
173 for name in sorted(cls.__dict__.keys()):
42680
2f4679301132 Rename __whatever variables defined by ABCMeta to _abc_whatever, so as
Guido van Rossum <guido@python.org>
parents: 42662
diff changeset
174 if name.startswith("_abc_"):
42087
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 value = getattr(cls, name)
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 print("%s: %r" % (name, value), file=file)
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
177
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 def __instancecheck__(cls, instance):
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 """Override for isinstance(instance, cls)."""
45333
e70f56cf6972 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60766,60769-60786 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45159
diff changeset
180 # Inline the cache checking
e70f56cf6972 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60766,60769-60786 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45159
diff changeset
181 subclass = instance.__class__
e70f56cf6972 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60766,60769-60786 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45159
diff changeset
182 if subclass in cls._abc_cache:
e70f56cf6972 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60766,60769-60786 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45159
diff changeset
183 return True
e70f56cf6972 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60766,60769-60786 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45159
diff changeset
184 subtype = type(instance)
e70f56cf6972 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60766,60769-60786 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45159
diff changeset
185 if subtype is subclass:
e70f56cf6972 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60766,60769-60786 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45159
diff changeset
186 if (cls._abc_negative_cache_version ==
e70f56cf6972 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60766,60769-60786 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45159
diff changeset
187 ABCMeta._abc_invalidation_counter and
e70f56cf6972 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60766,60769-60786 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45159
diff changeset
188 subclass in cls._abc_negative_cache):
e70f56cf6972 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60766,60769-60786 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45159
diff changeset
189 return False
e70f56cf6972 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60766,60769-60786 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45159
diff changeset
190 # Fall back to the subclass check.
e70f56cf6972 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60766,60769-60786 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45159
diff changeset
191 return cls.__subclasscheck__(subclass)
e70f56cf6972 Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60766,60769-60786 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45159
diff changeset
192 return any(cls.__subclasscheck__(c) for c in {subclass, subtype})
42087
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
193
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
194 def __subclasscheck__(cls, subclass):
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 """Override for issubclass(subclass, cls)."""
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 # Check cache
42680
2f4679301132 Rename __whatever variables defined by ABCMeta to _abc_whatever, so as
Guido van Rossum <guido@python.org>
parents: 42662
diff changeset
197 if subclass in cls._abc_cache:
42087
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
198 return True
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 # Check negative cache; may have to invalidate
42680
2f4679301132 Rename __whatever variables defined by ABCMeta to _abc_whatever, so as
Guido van Rossum <guido@python.org>
parents: 42662
diff changeset
200 if cls._abc_negative_cache_version < ABCMeta._abc_invalidation_counter:
42087
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
201 # Invalidate the negative cache
43644
95d8c913e8bf #1061 (mainly by Thomas Wouters): use weak sets for abc caches.
Georg Brandl <georg@python.org>
parents: 43334
diff changeset
202 cls._abc_negative_cache = WeakSet()
42680
2f4679301132 Rename __whatever variables defined by ABCMeta to _abc_whatever, so as
Guido van Rossum <guido@python.org>
parents: 42662
diff changeset
203 cls._abc_negative_cache_version = ABCMeta._abc_invalidation_counter
2f4679301132 Rename __whatever variables defined by ABCMeta to _abc_whatever, so as
Guido van Rossum <guido@python.org>
parents: 42662
diff changeset
204 elif subclass in cls._abc_negative_cache:
42087
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 return False
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 # Check the subclass hook
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 ok = cls.__subclasshook__(subclass)
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
208 if ok is not NotImplemented:
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
209 assert isinstance(ok, bool)
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
210 if ok:
42680
2f4679301132 Rename __whatever variables defined by ABCMeta to _abc_whatever, so as
Guido van Rossum <guido@python.org>
parents: 42662
diff changeset
211 cls._abc_cache.add(subclass)
42087
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 else:
42680
2f4679301132 Rename __whatever variables defined by ABCMeta to _abc_whatever, so as
Guido van Rossum <guido@python.org>
parents: 42662
diff changeset
213 cls._abc_negative_cache.add(subclass)
42087
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
214 return ok
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
215 # Check if it's a direct subclass
44568
305d7d2ce047 Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents: 44067
diff changeset
216 if cls in getattr(subclass, '__mro__', ()):
42680
2f4679301132 Rename __whatever variables defined by ABCMeta to _abc_whatever, so as
Guido van Rossum <guido@python.org>
parents: 42662
diff changeset
217 cls._abc_cache.add(subclass)
42087
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 return True
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 # Check if it's a subclass of a registered class (recursive)
42680
2f4679301132 Rename __whatever variables defined by ABCMeta to _abc_whatever, so as
Guido van Rossum <guido@python.org>
parents: 42662
diff changeset
220 for rcls in cls._abc_registry:
42087
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 if issubclass(subclass, rcls):
48960
7a6e6a04e28d Merged revisions 66144 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents: 45549
diff changeset
222 cls._abc_cache.add(subclass)
42087
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
223 return True
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
224 # Check if it's a subclass of a subclass (recursive)
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 for scls in cls.__subclasses__():
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
226 if issubclass(subclass, scls):
48960
7a6e6a04e28d Merged revisions 66144 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents: 45549
diff changeset
227 cls._abc_cache.add(subclass)
42087
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 return True
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
229 # No dice; update negative cache
42680
2f4679301132 Rename __whatever variables defined by ABCMeta to _abc_whatever, so as
Guido van Rossum <guido@python.org>
parents: 42662
diff changeset
230 cls._abc_negative_cache.add(subclass)
42087
973992a7440a Somehow this needed adding.
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 return False
80840
9347869d1066 Issue #16049: add abc.ABC helper class.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents: 73984
diff changeset
232
83929
5b17d5ca2ff1 Fix #16832 - expose cache validity checking support in ABCMeta
Łukasz Langa <lukasz@langa.pl>
parents: 80840
diff changeset
233
80840
9347869d1066 Issue #16049: add abc.ABC helper class.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents: 73984
diff changeset
234 class ABC(metaclass=ABCMeta):
9347869d1066 Issue #16049: add abc.ABC helper class.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents: 73984
diff changeset
235 """Helper class that provides a standard way to create an ABC using
9347869d1066 Issue #16049: add abc.ABC helper class.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents: 73984
diff changeset
236 inheritance.
9347869d1066 Issue #16049: add abc.ABC helper class.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents: 73984
diff changeset
237 """
9347869d1066 Issue #16049: add abc.ABC helper class.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents: 73984
diff changeset
238 pass
83929
5b17d5ca2ff1 Fix #16832 - expose cache validity checking support in ABCMeta
Łukasz Langa <lukasz@langa.pl>
parents: 80840
diff changeset
239
5b17d5ca2ff1 Fix #16832 - expose cache validity checking support in ABCMeta
Łukasz Langa <lukasz@langa.pl>
parents: 80840
diff changeset
240
5b17d5ca2ff1 Fix #16832 - expose cache validity checking support in ABCMeta
Łukasz Langa <lukasz@langa.pl>
parents: 80840
diff changeset
241 def get_cache_token():
5b17d5ca2ff1 Fix #16832 - expose cache validity checking support in ABCMeta
Łukasz Langa <lukasz@langa.pl>
parents: 80840
diff changeset
242 """Returns the current ABC cache token.
5b17d5ca2ff1 Fix #16832 - expose cache validity checking support in ABCMeta
Łukasz Langa <lukasz@langa.pl>
parents: 80840
diff changeset
243
5b17d5ca2ff1 Fix #16832 - expose cache validity checking support in ABCMeta
Łukasz Langa <lukasz@langa.pl>
parents: 80840
diff changeset
244 The token is an opaque integer identifying the current version of
5b17d5ca2ff1 Fix #16832 - expose cache validity checking support in ABCMeta
Łukasz Langa <lukasz@langa.pl>
parents: 80840
diff changeset
245 the ABC cache for virtual subclasses. This number changes with
5b17d5ca2ff1 Fix #16832 - expose cache validity checking support in ABCMeta
Łukasz Langa <lukasz@langa.pl>
parents: 80840
diff changeset
246 every call to ``register()`` on any ABC.
5b17d5ca2ff1 Fix #16832 - expose cache validity checking support in ABCMeta
Łukasz Langa <lukasz@langa.pl>
parents: 80840
diff changeset
247 """
5b17d5ca2ff1 Fix #16832 - expose cache validity checking support in ABCMeta
Łukasz Langa <lukasz@langa.pl>
parents: 80840
diff changeset
248 return ABCMeta._abc_invalidation_counter