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
eadd8cf5
Kaydet (Commit)
eadd8cf5
authored
May 25, 2013
tarafından
Łukasz Langa
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fix #16832 - expose cache validity checking support in ABCMeta
üst
b961955e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
0 deletions
+34
-0
abc.rst
Doc/library/abc.rst
+17
-0
abc.py
Lib/abc.py
+14
-0
test_abc.py
Lib/test/test_abc.py
+3
-0
No files found.
Doc/library/abc.rst
Dosyayı görüntüle @
eadd8cf5
...
@@ -58,6 +58,10 @@ This module provides the following classes:
...
@@ -58,6 +58,10 @@ This module provides the following classes:
.. versionchanged:: 3.3
.. versionchanged:: 3.3
Returns the registered subclass, to allow usage as a class decorator.
Returns the registered subclass, to allow usage as a class decorator.
.. versionchanged:: 3.4
To detect calls to :meth:`register`, you can use the
:func:`get_cache_token` function.
You can also override this method in an abstract base class:
You can also override this method in an abstract base class:
.. method:: __subclasshook__(subclass)
.. method:: __subclasshook__(subclass)
...
@@ -308,6 +312,19 @@ The :mod:`abc` module also provides the following decorators:
...
@@ -308,6 +312,19 @@ The :mod:`abc` module also provides the following decorators:
:func:`abstractmethod`, making this decorator redundant.
:func:`abstractmethod`, making this decorator redundant.
The :mod:`abc` module also provides the following functions:
.. function:: get_cache_token()
Returns the current abstract base class cache token.
The token is an opaque integer identifying the current version of the
abstract base class cache for virtual subclasses. This number changes
with every call to :meth:`ABCMeta.register` on any ABC.
.. versionadded:: 3.4
.. rubric:: Footnotes
.. rubric:: Footnotes
.. [#] C++ programmers should note that Python's virtual base class
.. [#] C++ programmers should note that Python's virtual base class
...
...
Lib/abc.py
Dosyayı görüntüle @
eadd8cf5
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
from
_weakrefset
import
WeakSet
from
_weakrefset
import
WeakSet
def
abstractmethod
(
funcobj
):
def
abstractmethod
(
funcobj
):
"""A decorator indicating abstract methods.
"""A decorator indicating abstract methods.
...
@@ -124,6 +125,8 @@ class ABCMeta(type):
...
@@ -124,6 +125,8 @@ class ABCMeta(type):
# A global counter that is incremented each time a class is
# A global counter that is incremented each time a class is
# registered as a virtual subclass of anything. It forces the
# registered as a virtual subclass of anything. It forces the
# negative cache to be cleared before its next use.
# 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
_abc_invalidation_counter
=
0
def
__new__
(
mcls
,
name
,
bases
,
namespace
):
def
__new__
(
mcls
,
name
,
bases
,
namespace
):
...
@@ -227,8 +230,19 @@ class ABCMeta(type):
...
@@ -227,8 +230,19 @@ class ABCMeta(type):
cls
.
_abc_negative_cache
.
add
(
subclass
)
cls
.
_abc_negative_cache
.
add
(
subclass
)
return
False
return
False
class
ABC
(
metaclass
=
ABCMeta
):
class
ABC
(
metaclass
=
ABCMeta
):
"""Helper class that provides a standard way to create an ABC using
"""Helper class that provides a standard way to create an ABC using
inheritance.
inheritance.
"""
"""
pass
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
Lib/test/test_abc.py
Dosyayı görüntüle @
eadd8cf5
...
@@ -329,7 +329,10 @@ class TestABC(unittest.TestCase):
...
@@ -329,7 +329,10 @@ class TestABC(unittest.TestCase):
b
=
B
()
b
=
B
()
self
.
assertFalse
(
isinstance
(
b
,
A
))
self
.
assertFalse
(
isinstance
(
b
,
A
))
self
.
assertFalse
(
isinstance
(
b
,
(
A
,)))
self
.
assertFalse
(
isinstance
(
b
,
(
A
,)))
token_old
=
abc
.
get_cache_token
()
A
.
register
(
B
)
A
.
register
(
B
)
token_new
=
abc
.
get_cache_token
()
self
.
assertNotEqual
(
token_old
,
token_new
)
self
.
assertTrue
(
isinstance
(
b
,
A
))
self
.
assertTrue
(
isinstance
(
b
,
A
))
self
.
assertTrue
(
isinstance
(
b
,
(
A
,)))
self
.
assertTrue
(
isinstance
(
b
,
(
A
,)))
...
...
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