@@ -116,7 +116,7 @@ class ABCMeta(type):
116116 # A global counter that is incremented each time a class is
117117 # registered as a virtual subclass of anything. It forces the
118118 # negative cache to be cleared before its next use.
119- __invalidation_counter = 0
119+ _abc_invalidation_counter = 0
120120
121121 def __new__ (mcls , name , bases , namespace ):
122122 bases = _fix_bases (bases )
@@ -132,10 +132,10 @@ def __new__(mcls, name, bases, namespace):
132132 abstracts .add (name )
133133 cls .__abstractmethods__ = abstracts
134134 # Set up inheritance registry
135- cls .__registry = set ()
136- cls .__cache = set ()
137- cls .__negative_cache = set ()
138- cls .__negative_cache_version = ABCMeta .__invalidation_counter
135+ cls ._abc_registry = set ()
136+ cls ._abc_cache = set ()
137+ cls ._abc_negative_cache = set ()
138+ cls ._abc_negative_cache_version = ABCMeta ._abc_invalidation_counter
139139 return cls
140140
141141 def register (cls , subclass ):
@@ -149,15 +149,15 @@ def register(cls, subclass):
149149 if issubclass (cls , subclass ):
150150 # This would create a cycle, which is bad for the algorithm below
151151 raise RuntimeError ("Refusing to create an inheritance cycle" )
152- cls .__registry .add (subclass )
153- ABCMeta .__invalidation_counter += 1 # Invalidate negative cache
152+ cls ._abc_registry .add (subclass )
153+ ABCMeta ._abc_invalidation_counter += 1 # Invalidate negative cache
154154
155155 def _dump_registry (cls , file = None ):
156156 """Debug helper to print the ABC registry."""
157157 print ("Class: %s.%s" % (cls .__module__ , cls .__name__ ), file = file )
158- print ("Inv.counter: %s" % ABCMeta .__invalidation_counter , file = file )
158+ print ("Inv.counter: %s" % ABCMeta ._abc_invalidation_counter , file = file )
159159 for name in sorted (cls .__dict__ .keys ()):
160- if name .startswith ("_ABCMeta__ " ):
160+ if name .startswith ("_abc_ " ):
161161 value = getattr (cls , name )
162162 print ("%s: %r" % (name , value ), file = file )
163163
@@ -169,38 +169,38 @@ def __instancecheck__(cls, instance):
169169 def __subclasscheck__ (cls , subclass ):
170170 """Override for issubclass(subclass, cls)."""
171171 # Check cache
172- if subclass in cls .__cache :
172+ if subclass in cls ._abc_cache :
173173 return True
174174 # Check negative cache; may have to invalidate
175- if cls .__negative_cache_version < ABCMeta .__invalidation_counter :
175+ if cls ._abc_negative_cache_version < ABCMeta ._abc_invalidation_counter :
176176 # Invalidate the negative cache
177- cls .__negative_cache = set ()
178- cls .__negative_cache_version = ABCMeta .__invalidation_counter
179- elif subclass in cls .__negative_cache :
177+ cls ._abc_negative_cache = set ()
178+ cls ._abc_negative_cache_version = ABCMeta ._abc_invalidation_counter
179+ elif subclass in cls ._abc_negative_cache :
180180 return False
181181 # Check the subclass hook
182182 ok = cls .__subclasshook__ (subclass )
183183 if ok is not NotImplemented :
184184 assert isinstance (ok , bool )
185185 if ok :
186- cls .__cache .add (subclass )
186+ cls ._abc_cache .add (subclass )
187187 else :
188- cls .__negative_cache .add (subclass )
188+ cls ._abc_negative_cache .add (subclass )
189189 return ok
190190 # Check if it's a direct subclass
191191 if cls in subclass .__mro__ :
192- cls .__cache .add (subclass )
192+ cls ._abc_cache .add (subclass )
193193 return True
194194 # Check if it's a subclass of a registered class (recursive)
195- for rcls in cls .__registry :
195+ for rcls in cls ._abc_registry :
196196 if issubclass (subclass , rcls ):
197- cls .__registry .add (subclass )
197+ cls ._abc_registry .add (subclass )
198198 return True
199199 # Check if it's a subclass of a subclass (recursive)
200200 for scls in cls .__subclasses__ ():
201201 if issubclass (subclass , scls ):
202- cls .__registry .add (subclass )
202+ cls ._abc_registry .add (subclass )
203203 return True
204204 # No dice; update negative cache
205- cls .__negative_cache .add (subclass )
205+ cls ._abc_negative_cache .add (subclass )
206206 return False
0 commit comments