A WeakList class for storing objects using weak references in a list.
Table of Contents
Installation
Install it from pypi:
pip install weakreflist
or from sources:
git clone git@github.com:apieum/weakreflist.git cd weakreflist python setup.py install
Usage
Same as a list except that when a weakref-able variable is deleted, it is removed from the list.
Example for CPython:
from weakreflist import WeakList class A(object): """weakrefs don't function directly on object()""" objectA = A() my_list = WeakList([objectA]) assert len(my_list) == 1 del objectA assert len(my_list) == 0 # objectA removed from list
- Note:
Pypy (probably jython, cython…) have a different implementation of garbage collector and it is known that weakrefs doesn’t function the same way.
You need to explicitly call gc.collect() which has an impact on performance.
Example for other python implementations
from weakreflist import WeakList import gc class A(object): """weakrefs don't function directly on object()""" objectA = A() my_list = WeakList([objectA]) assert len(my_list) == 1 del objectA assert len(my_list) == 1 # gc not done gc.collect() # must be called assert len(my_list) == 0
Development
Your feedback, code review, improvements or bugs, and help to document is appreciated. You can contact me by mail: apieum [at] gmail [dot] com
Test recommended requirements:
pip install -r dev-requirements.txt
Sometimes –spec-color doesn’t function. Uninstall nosespec and nosecolor then reinstall nosecolor and nosespec separatly in this order (nosecolor first).
Launch tests:
git clone git@github.com:apieum/weakreflist.git cd weakreflist nosetests --with-spec --spec-color ./weakreflist # or with watch # nosetests --with-spec --spec-color --with-watch ./weakreflist
Contributors
- Thanks to BoonsNaibot to have contributed to:
extended slicing support
__reversed__, count, extend, insert methods.
Metadata
Release files for weakreflist 0.4
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 | |
|---|---|---|---|---|
| weakreflist-0.4.tar.gz | 7.5 kB | Without provenance | Details |
Release files / weakreflist-0.4.tar.gz
| Download URL | weakreflist-0.4.tar.gz |
|---|---|
| Size | 7.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
28bb41d87b8d4ae9ca9c388ef322c6f4473346d54985863d41ba4f29ba797a09
|
|
BLAKE2b-256 checksum How to use checksums |
221bd4716e0f52f026c8620a0c973a64907934068c41195cf18a9e123eae3066
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for weakreflist 0.4
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.