summaryrefslogtreecommitdiff
path: root/Doc/library/weakref.rst
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2013-03-23 16:06:06 -0700
committerGregory P. Smith <greg@krypto.org>2013-03-23 16:06:06 -0700
commitf20651c7878e3b37a7175922bf7a1ff4b428f818 (patch)
treeaae93c8833441f33e515a234e6e5b61090032844 /Doc/library/weakref.rst
parent09419f23ef7e459956abadb2834b14c553637abd (diff)
parent184eb1cba66def75440ee585826b437711ea5996 (diff)
downloadcpython-f20651c7878e3b37a7175922bf7a1ff4b428f818.tar.gz
Fixes issue4653 - Correctly specify the buffer size to FormatMessageW and
correctly check for errors on two CreateFileMapping calls.
Diffstat (limited to 'Doc/library/weakref.rst')
-rw-r--r--Doc/library/weakref.rst29
1 files changed, 29 insertions, 0 deletions
diff --git a/Doc/library/weakref.rst b/Doc/library/weakref.rst
index 224f442edd..1bf6b58770 100644
--- a/Doc/library/weakref.rst
+++ b/Doc/library/weakref.rst
@@ -192,6 +192,35 @@ These method have the same issues as the and :meth:`keyrefs` method of
discarded when no strong reference to it exists any more.
+.. class:: WeakMethod(method)
+
+ A custom :class:`ref` subclass which simulates a weak reference to a bound
+ method (i.e., a method defined on a class and looked up on an instance).
+ Since a bound method is ephemeral, a standard weak reference cannot keep
+ hold of it. :class:`WeakMethod` has special code to recreate the bound
+ method until either the object or the original function dies::
+
+ >>> class C:
+ ... def method(self):
+ ... print("method called!")
+ ...
+ >>> c = C()
+ >>> r = weakref.ref(c.method)
+ >>> r()
+ >>> r = weakref.WeakMethod(c.method)
+ >>> r()
+ <bound method C.method of <__main__.C object at 0x7fc859830220>>
+ >>> r()()
+ method called!
+ >>> del c
+ >>> gc.collect()
+ 0
+ >>> r()
+ >>>
+
+ .. versionadded:: 3.4
+
+
.. data:: ReferenceType
The type object for weak references objects.