Registry / devops / weakrefmethod

weakrefmethod

JSON →
library1.0.3pypypi✓ verified 85d ago

A WeakMethod class for storing bound methods using weak references. Current version 1.0.3, infrequently updated.

pip install weakrefmethod
INSTALL
IMPORT
SIG · WEAKREFMETHOD
W
weakrefmethod
devopspythonv1.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

WeakMethod
from weakrefmethod import WeakMethod
from weakref import WeakMethod
stdlib weakref does not export WeakMethod; only weakrefmethod provides it.

Create a weak reference to a bound method; call returns the method result or None if the object is garbage collected.

from weakrefmethod import WeakMethod class MyClass: def method(self): return 'hello' obj = MyClass() wm = WeakMethod(obj.method) print(wm() if wm() is not None else 'dead')
Debug
Known issues
gotchaWeakMethod only works on bound methods (instance.method). Passing an unbound method or a regular function will raise TypeError.
fix
Ensure the argument is a bound method: obj.method, not Class.method.
affects: all
gotchaThe WeakMethod object is not callable directly in the sense of a proxy; to call the underlying method you must call wm() which returns the bound method or None.
fix
Use wm() to call, not wm (which is a WeakMethod instance).
affects: all
deprecatedNo deprecated features as of 1.0.3; API is stable.
affects: all
Errors
Common errors & fixes
TypeError: cannot create weak reference to 'method' object
Passing an unbound function or a method from a C extension that does not support weak references.
fix
Ensure you pass a bound method from a Python-defined class. Alternatively, use weakref.WeakMethod from Python 3.4+ stdlib if on Python 3.4+.
ImportError: No module named 'weakrefmethod'
Package not installed or Python environment not correct.
fix
Run 'pip install weakrefmethod' and ensure you are using the correct Python interpreter.
Upgrade
Version history
1.0.3latest on PyPI · released Jul 18, 2016
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
5
Resources
weakrefmethod — pip install weakrefmethod · libregistry