A Descriptor class implementing weakref properties in Python 2/3
Add a property that acts like a normal attribute, but keeps a weak reference to anything that is assigned to it.
Example:
First let’s define WeakValue using WeakProperty and SomeClass that will be weakly referenced:
>>> import weakref_property >>> import gc >>> class WeakValue(object): ... value = weakref_property.WeakProperty('value') >>> class SomeClass(object): ... passYou can assign and retrieve a value:
>>> a = SomeClass() >>> obj = WeakValue() >>> obj.value = a >>> obj.value # doctest: +ELLIPSIS <__main__.SomeClass object at ...>But it is kept as a weakref, so it can get collected. If it is collected, the property returns None:
>>> del a >>> gc.collect() # force gc to collect `a` object 0 >>> obj.valueYou can also delete the value completelly:
>>> del obj.value >>> obj.value Traceback (most recent call last): ... AttributeError: 'WeakValue' object has no attribute 'value'Sadly, weakrefs do not work on tuples, ints and not-subclassed lists and dicts:
>>> obj.value = [] Traceback (most recent call last): ... TypeError: cannot create weak reference to 'list' object
Metadata
Release files for weakref_property 0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| weakref_property-0.1.tar.gz | 14.4 kB | Without provenance | Details for weakref_property-0.1.tar.gz |
Release files / weakref_property-0.1.tar.gz
| Download URL | weakref_property-0.1.tar.gz |
|---|---|
| Size | 14.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
258180f09fc0eb19a4483b642796c9000a31e0f25491635cf4e91850b91ea32d
|
|
BLAKE2b-256 checksum How to use checksums |
d032fe976e59a132a52ff79e3a714b8f938a518205ddf490634dfac39aed2194
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for weakref_property 0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.