Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
c1e315d2
Kaydet (Commit)
c1e315d2
authored
Agu 20, 2007
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Rename __whatever variables defined by ABCMeta to _abc_whatever, so as
to simplify legitimate use of these.
üst
d0648994
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
25 deletions
+25
-25
abc.py
Lib/abc.py
+21
-21
regrtest.py
Lib/test/regrtest.py
+4
-4
No files found.
Lib/abc.py
Dosyayı görüntüle @
c1e315d2
...
...
@@ -116,7 +116,7 @@ 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.
__invalidation_counter
=
0
_
abc
_invalidation_counter
=
0
def
__new__
(
mcls
,
name
,
bases
,
namespace
):
bases
=
_fix_bases
(
bases
)
...
...
@@ -132,10 +132,10 @@ class ABCMeta(type):
abstracts
.
add
(
name
)
cls
.
__abstractmethods__
=
abstracts
# Set up inheritance registry
cls
.
__registry
=
set
()
cls
.
__cache
=
set
()
cls
.
__negative_cache
=
set
()
cls
.
_
_negative_cache_version
=
ABCMeta
.
_
_invalidation_counter
cls
.
_
abc
_registry
=
set
()
cls
.
_
abc
_cache
=
set
()
cls
.
_
abc
_negative_cache
=
set
()
cls
.
_
abc_negative_cache_version
=
ABCMeta
.
_abc
_invalidation_counter
return
cls
def
register
(
cls
,
subclass
):
...
...
@@ -149,15 +149,15 @@ class ABCMeta(type):
if
issubclass
(
cls
,
subclass
):
# This would create a cycle, which is bad for the algorithm below
raise
RuntimeError
(
"Refusing to create an inheritance cycle"
)
cls
.
__registry
.
add
(
subclass
)
ABCMeta
.
__invalidation_counter
+=
1
# Invalidate negative cache
cls
.
_
abc
_registry
.
add
(
subclass
)
ABCMeta
.
_
abc
_invalidation_counter
+=
1
# Invalidate negative cache
def
_dump_registry
(
cls
,
file
=
None
):
"""Debug helper to print the ABC registry."""
print
(
"Class:
%
s.
%
s"
%
(
cls
.
__module__
,
cls
.
__name__
),
file
=
file
)
print
(
"Inv.counter:
%
s"
%
ABCMeta
.
__invalidation_counter
,
file
=
file
)
print
(
"Inv.counter:
%
s"
%
ABCMeta
.
_
abc
_invalidation_counter
,
file
=
file
)
for
name
in
sorted
(
cls
.
__dict__
.
keys
()):
if
name
.
startswith
(
"_
ABCMeta_
_"
):
if
name
.
startswith
(
"_
abc
_"
):
value
=
getattr
(
cls
,
name
)
print
(
"
%
s:
%
r"
%
(
name
,
value
),
file
=
file
)
...
...
@@ -169,38 +169,38 @@ class ABCMeta(type):
def
__subclasscheck__
(
cls
,
subclass
):
"""Override for issubclass(subclass, cls)."""
# Check cache
if
subclass
in
cls
.
__cache
:
if
subclass
in
cls
.
_
abc
_cache
:
return
True
# Check negative cache; may have to invalidate
if
cls
.
_
_negative_cache_version
<
ABCMeta
.
_
_invalidation_counter
:
if
cls
.
_
abc_negative_cache_version
<
ABCMeta
.
_abc
_invalidation_counter
:
# Invalidate the negative cache
cls
.
__negative_cache
=
set
()
cls
.
_
_negative_cache_version
=
ABCMeta
.
_
_invalidation_counter
elif
subclass
in
cls
.
__negative_cache
:
cls
.
_
abc
_negative_cache
=
set
()
cls
.
_
abc_negative_cache_version
=
ABCMeta
.
_abc
_invalidation_counter
elif
subclass
in
cls
.
_
abc
_negative_cache
:
return
False
# Check the subclass hook
ok
=
cls
.
__subclasshook__
(
subclass
)
if
ok
is
not
NotImplemented
:
assert
isinstance
(
ok
,
bool
)
if
ok
:
cls
.
__cache
.
add
(
subclass
)
cls
.
_
abc
_cache
.
add
(
subclass
)
else
:
cls
.
__negative_cache
.
add
(
subclass
)
cls
.
_
abc
_negative_cache
.
add
(
subclass
)
return
ok
# Check if it's a direct subclass
if
cls
in
subclass
.
__mro__
:
cls
.
__cache
.
add
(
subclass
)
cls
.
_
abc
_cache
.
add
(
subclass
)
return
True
# Check if it's a subclass of a registered class (recursive)
for
rcls
in
cls
.
__registry
:
for
rcls
in
cls
.
_
abc
_registry
:
if
issubclass
(
subclass
,
rcls
):
cls
.
__registry
.
add
(
subclass
)
cls
.
_
abc
_registry
.
add
(
subclass
)
return
True
# Check if it's a subclass of a subclass (recursive)
for
scls
in
cls
.
__subclasses__
():
if
issubclass
(
subclass
,
scls
):
cls
.
__registry
.
add
(
subclass
)
cls
.
_
abc
_registry
.
add
(
subclass
)
return
True
# No dice; update negative cache
cls
.
__negative_cache
.
add
(
subclass
)
cls
.
_
abc
_negative_cache
.
add
(
subclass
)
return
False
Lib/test/regrtest.py
Dosyayı görüntüle @
c1e315d2
...
...
@@ -680,7 +680,7 @@ def dash_R(the_module, test, indirect_test, huntrleaks):
fs
=
warnings
.
filters
[:]
ps
=
copy_reg
.
dispatch_table
.
copy
()
pic
=
sys
.
path_importer_cache
.
copy
()
abcs
=
{
obj
:
obj
.
_
ABCMeta_
_registry
.
copy
()
abcs
=
{
obj
:
obj
.
_
abc
_registry
.
copy
()
for
abc
in
[
getattr
(
_abcoll
,
a
)
for
a
in
_abcoll
.
__all__
]
for
obj
in
abc
.
__subclasses__
()
+
[
abc
]}
...
...
@@ -731,9 +731,9 @@ def dash_R_cleanup(fs, ps, pic, abcs):
# Clear ABC registries, restoring previously saved ABC registries.
for
abc
in
[
getattr
(
_abcoll
,
a
)
for
a
in
_abcoll
.
__all__
]:
for
obj
in
abc
.
__subclasses__
()
+
[
abc
]:
obj
.
_
ABCMeta_
_registry
=
abcs
.
get
(
obj
,
{})
.
copy
()
obj
.
_
ABCMeta_
_cache
.
clear
()
obj
.
_
ABCMeta_
_negative_cache
.
clear
()
obj
.
_
abc
_registry
=
abcs
.
get
(
obj
,
{})
.
copy
()
obj
.
_
abc
_cache
.
clear
()
obj
.
_
abc
_negative_cache
.
clear
()
# Clear assorted module caches.
_path_created
.
clear
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment