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
556e94b8
Kaydet (Commit)
556e94b8
authored
Nis 13, 2013
tarafından
Mark Dickinson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #17643: Add __callback__ attribute to weakref.ref.
üst
548677bb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
3 deletions
+44
-3
weakref.rst
Doc/library/weakref.rst
+12
-2
test_weakref.py
Lib/test/test_weakref.py
+24
-0
NEWS
Misc/NEWS
+2
-0
weakrefobject.c
Objects/weakrefobject.c
+6
-1
No files found.
Doc/library/weakref.rst
Dosyayı görüntüle @
556e94b8
...
@@ -111,6 +111,15 @@ Extension types can easily be made to support weak references; see
...
@@ -111,6 +111,15 @@ Extension types can easily be made to support weak references; see
This is a subclassable type rather than a factory function.
This is a subclassable type rather than a factory function.
.. attribute:: __callback__
This read-only attribute returns the callback currently associated to the
weakref. If there is no callback or if the referent of the weakref is
no longer alive then this attribute will have value ``None``.
.. versionadded:: 3.4
Added the :attr:`__callback__` attribute.
.. function:: proxy(object[, callback])
.. function:: proxy(object[, callback])
...
@@ -261,8 +270,9 @@ These method have the same issues as the and :meth:`keyrefs` method of
...
@@ -261,8 +270,9 @@ These method have the same issues as the and :meth:`keyrefs` method of
Weak Reference Objects
Weak Reference Objects
----------------------
----------------------
Weak reference objects have no attributes or methods, but do allow the referent
Weak reference objects have no methods and no attributes besides
to be obtained, if it still exists, by calling it:
:attr:`ref.__callback__`. A weak reference object allows the referent to be
obtained, if it still exists, by calling it:
>>> import weakref
>>> import weakref
>>> class Object:
>>> class Object:
...
...
Lib/test/test_weakref.py
Dosyayı görüntüle @
556e94b8
...
@@ -802,6 +802,30 @@ class ReferencesTestCase(TestBase):
...
@@ -802,6 +802,30 @@ class ReferencesTestCase(TestBase):
del
root
del
root
gc
.
collect
()
gc
.
collect
()
def
test_callback_attribute
(
self
):
x
=
Object
(
1
)
callback
=
lambda
ref
:
None
ref1
=
weakref
.
ref
(
x
,
callback
)
self
.
assertIs
(
ref1
.
__callback__
,
callback
)
ref2
=
weakref
.
ref
(
x
)
self
.
assertIsNone
(
ref2
.
__callback__
)
def
test_callback_attribute_after_deletion
(
self
):
x
=
Object
(
1
)
ref
=
weakref
.
ref
(
x
,
self
.
callback
)
self
.
assertIsNotNone
(
ref
.
__callback__
)
del
x
support
.
gc_collect
()
self
.
assertIsNone
(
ref
.
__callback__
)
def
test_set_callback_attribute
(
self
):
x
=
Object
(
1
)
callback
=
lambda
ref
:
None
ref1
=
weakref
.
ref
(
x
,
callback
)
with
self
.
assertRaises
(
AttributeError
):
ref1
.
__callback__
=
lambda
ref
:
None
class
SubclassableWeakrefTestCase
(
TestBase
):
class
SubclassableWeakrefTestCase
(
TestBase
):
...
...
Misc/NEWS
Dosyayı görüntüle @
556e94b8
...
@@ -10,6 +10,8 @@ What's New in Python 3.4.0 Alpha 1?
...
@@ -10,6 +10,8 @@ What's New in Python 3.4.0 Alpha 1?
Core and Builtins
Core and Builtins
-----------------
-----------------
- Issue #17643: Add __callback__ attribute to weakref.ref.
- Issue #16447: Fixed potential segmentation fault when setting __name__ on a
- Issue #16447: Fixed potential segmentation fault when setting __name__ on a
class.
class.
...
...
Objects/weakrefobject.c
Dosyayı görüntüle @
556e94b8
...
@@ -338,6 +338,11 @@ weakref___init__(PyObject *self, PyObject *args, PyObject *kwargs)
...
@@ -338,6 +338,11 @@ weakref___init__(PyObject *self, PyObject *args, PyObject *kwargs)
}
}
static
PyMemberDef
weakref_members
[]
=
{
{
"__callback__"
,
T_OBJECT
,
offsetof
(
PyWeakReference
,
wr_callback
),
READONLY
},
{
NULL
}
/* Sentinel */
};
PyTypeObject
PyTypeObject
_PyWeakref_RefType
=
{
_PyWeakref_RefType
=
{
PyVarObject_HEAD_INIT
(
&
PyType_Type
,
0
)
PyVarObject_HEAD_INIT
(
&
PyType_Type
,
0
)
...
@@ -369,7 +374,7 @@ _PyWeakref_RefType = {
...
@@ -369,7 +374,7 @@ _PyWeakref_RefType = {
0
,
/*tp_iter*/
0
,
/*tp_iter*/
0
,
/*tp_iternext*/
0
,
/*tp_iternext*/
0
,
/*tp_methods*/
0
,
/*tp_methods*/
0
,
/*tp_members*/
weakref_members
,
/*tp_members*/
0
,
/*tp_getset*/
0
,
/*tp_getset*/
0
,
/*tp_base*/
0
,
/*tp_base*/
0
,
/*tp_dict*/
0
,
/*tp_dict*/
...
...
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