tri.struct supplies classes that can be used like dictionaries and as objects with attribute access at the same time
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)
>>> from tri_struct import Struct >>> foo = Struct() >>> foo.a = 1 >>> foo['a'] 1 >>> foo['a'] = 2 >>> foo.a 2
You need tox installed then just make test.
- Avoid setting confusing context on AttributeError exceptions (from when not finding __missing__)
- Split c implementation to separate FastStruct. The native python implementation is now always the Struct
- Override __copy__ for Frozen. This is an optimization that was found in big uses of tri.token.
- Problems with pypi, this is the same as 3.0.1
- Renamed module from tri.struct to tri_struct. This is a breaking change.
- Dropped python2 support
- Fixed performance issue with Frozen/FrozenStruct: the hash was recalculated on each use instead of cached.
- Fixed release functionality
- Fixed segfault in repr when running under Python 3
- Added DefaultStruct in the spirit of the standard library defaultdict. Also added a to_default_struct for recursively converting dicts recursively.
- Fix use-after-free when repring a Struct that contains itself more than once.
- Fix make and tox targets for build and release.
- Fix lint issues.
- Bugfix: Fix compilation of the _cstruct module.
- Build changes.
- 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.
- 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.
- 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
- Add keyword arguments to merged function.
- 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.
- slim down interface to again match dict
- add tri.struct.merged function to join structs
- add optional C implementation to speed up instantiation
- Struct with attribute & dict interface
- __add__ and __or__ to combine structs
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size tri.struct-4.1.0-cp38-cp38-macosx_10_15_x86_64.whl (10.2 kB)||File type Wheel||Python version cp38||Upload date||Hashes View|
|Filename, size tri.struct-4.1.0.tar.gz (17.7 kB)||File type Source||Python version None||Upload date||Hashes View|
Hashes for tri.struct-4.1.0-cp38-cp38-macosx_10_15_x86_64.whl