Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c1e315d

Browse files
committed
Rename __whatever variables defined by ABCMeta to _abc_whatever, so as
to simplify legitimate use of these.
1 parent d064899 commit c1e315d

2 files changed

Lines changed: 25 additions & 25 deletions

File tree

Lib/abc.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lib/test/regrtest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ def dash_R(the_module, test, indirect_test, huntrleaks):
680680
fs = warnings.filters[:]
681681
ps = copy_reg.dispatch_table.copy()
682682
pic = sys.path_importer_cache.copy()
683-
abcs = {obj: obj._ABCMeta__registry.copy()
683+
abcs = {obj: obj._abc_registry.copy()
684684
for abc in [getattr(_abcoll, a) for a in _abcoll.__all__]
685685
for obj in abc.__subclasses__() + [abc]}
686686

@@ -731,9 +731,9 @@ def dash_R_cleanup(fs, ps, pic, abcs):
731731
# Clear ABC registries, restoring previously saved ABC registries.
732732
for abc in [getattr(_abcoll, a) for a in _abcoll.__all__]:
733733
for obj in abc.__subclasses__() + [abc]:
734-
obj._ABCMeta__registry = abcs.get(obj, {}).copy()
735-
obj._ABCMeta__cache.clear()
736-
obj._ABCMeta__negative_cache.clear()
734+
obj._abc_registry = abcs.get(obj, {}).copy()
735+
obj._abc_cache.clear()
736+
obj._abc_negative_cache.clear()
737737

738738
# Clear assorted module caches.
739739
_path_created.clear()

0 commit comments

Comments
 (0)