tri.struct
tri.struct supplies classes that can be used like dictionaries and as objects with attribute access at the same time. There are two versions:
Struct: mutable struct
FrozenStruct: immutable struct
Some niceties include:
Predictable repr() so it’s easy to write tests
merged function call to merge different types of dicts into a new: merged(Struct(a=1), FrozenStruct(b=1), c=1) == Struct(a=1, b=1, c=1))
Accelerated implementation in c for improved speed. (With python-only fallback reference implementation)
Example
>>> from tri_struct import Struct
>>> foo = Struct()
>>> foo.a = 1
>>> foo['a']
1
>>> foo['a'] = 2
>>> foo.a
2
Running tests
You need tox installed then just make test.
License
BSD
Documentation
Changelog
4.1.0 (2021-02-01)
Avoid setting confusing context on AttributeError exceptions (from when not finding __missing__)
4.0.0 (2020-12-20)
Split c implementation to separate FastStruct. The native python implementation is now always the Struct
3.1.0 (2019-08-14)
Override __copy__ for Frozen. This is an optimization that was found in big uses of tri.token.
3.0.1 (2019-06-12)
Problems with pypi, this is the same as 3.0.1
3.0.0 (2019-06-04)
Renamed module from tri.struct to tri_struct. This is a breaking change.
Dropped python2 support
2.5.7 (2018-11-16)
Fixed performance issue with Frozen/FrozenStruct: the hash was recalculated on each use instead of cached.
2.5.6 (2018-06-26)
Fixed release functionality
2.5.5 (2018-02-20)
Fixed segfault in repr when running under Python 3
2.5.4 (2017-06-13)
Added DefaultStruct in the spirit of the standard library defaultdict. Also added a to_default_struct for recursively converting dicts recursively.
2.5.3 (2017-02-10)
Fix use-after-free when repring a Struct that contains itself more than once.
2.5.2 (2016-04-07)
Fix make and tox targets for build and release.
Fix lint issues.
2.5.1 (2015-12-15)
Bugfix: Fix compilation of the _cstruct module.
2.5.0 (unreleased)
Build changes.
2.4.0 (2015-12-08)
Improvement: If a Struct subclass implements the __missing__ method, it will not be called before GetAttr on attribute access, but will be called before GetAttr on dict access.
2.3.1 (2015-12-07)
Bugfix: Clear KeyError in CStruct getattr before trying GetAttr, otherwise the KeyError may “leak out”. Also, only clear the error and attempt GetAttr if the original error was a KeyError.
2.3.0 (2015-12-02)
Add mixin class Frozen to make read-only versions of a dict-derived class (typically a Struct or a subclass there of.)
Use the Frozen mixin to implement FrozenStruct
2.2.0 (2015-11-12)
Add keyword arguments to merged function.
2.1.2 (2015-11-11)
Redo the C implementation to be a “heaptype”, and remove the hack of setting __dict__ = self. Instead, object will control the type storage, letting us “insert” attributes into the object without polluting the dict.
2.0 (unreleased)
slim down interface to again match dict
add tri.struct.merged function to join structs
add optional C implementation to speed up instantiation
1.0 (2015-09-29)
Struct with attribute & dict interface
__add__ and __or__ to combine structs
Metadata
Release files for tri.struct 4.1.0
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 |
|---|---|---|---|---|
| tri.struct-4.1.0.tar.gz | 17.7 kB | Without provenance | Details for tri.struct-4.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tri.struct-4.1.0-cp38-cp38-macosx_10_15_x86_64.whl | CPython 3.8 | CPython 3.8 | macOS 10.15+ x86-64 | Details for tri.struct-4.1.0-cp38-cp38-macosx_10_15_x86_64.whl |
Total release size: 27.9 kB
Release files / tri.struct-4.1.0.tar.gz
| Download URL | tri.struct-4.1.0.tar.gz |
|---|---|
| Size | 17.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2a1a2002feb7c2ba0a03b871356cf2f621fbbb649074dcb05bc467eb1988866d
|
|
BLAKE2b-256 checksum How to use checksums |
6cac7b87ee04fb3bf9bec912376a8dc1944e488a6eafc4062df4c0786ee7d70e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.8.6
|
Release files / tri.struct-4.1.0-cp38-cp38-macosx_10_15_x86_64.whl
| Download URL | tri.struct-4.1.0-cp38-cp38-macosx_10_15_x86_64.whl |
|---|---|
| Size | 10.2 kB |
| Tags | CPython 3.8 macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
e85cef0af189f78bbe061a5655c85856cae117cb499d582e08d9c5078029871e
|
|
BLAKE2b-256 checksum How to use checksums |
3f305dab7a398134e6cee051a29948cd418a7753d60240e66905ed69bbd6c117
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.8.6
|
Security for tri.struct 4.1.0
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.