Skip to main content
https://travis-ci.org/TriOptima/tri.named-struct.svg?branch=master http://codecov.io/github/TriOptima/tri.named-struct/coverage.svg?branch=master

tri.named_struct

tri.named_struct supplies classes that can be used like dictionaries, but with a predefined set of possible key values.

Example

from tri_named_struct import NamedStruct

class MyNamedStruct(NamedStruct):
    foo = NamedStructField()
    bar = NamedStructField()

m = MyNamedStruct(17, 42)
assert m['foo'] == 17
assert m.foo == 17
assert m == dict(foo=17, bar=42)

m.not_foo  # Will raise an AttributeError

Default values can be provided:

from tri_named_struct import NamedStruct

class MyNamedStruct(NamedStruct):
    foo = NamedStructField()
    bar = NamedStructField()
    baz = NamedStructField(default='default')

assert MyNamedStruct(17) == dict(foo=17, bar=None, baz='default')

Default values can alternatively be provided by a factory method:

from tri_named_struct import NamedStruct

class MyNamedStruct(NamedStruct):
    foo = NamedStructField(default_factory=list)

assert MyNamedStruct().foo == []

There is also a functional way to defined a NamedStruct subclass:

from tri_named_struct import named_struct

MyNamedStruct = named_struct('foo, bar')
m = MyNamedStruct(17, 42)
assert m.foo == 17
assert m.bar == 42

Running tests

You need tox installed then just make test.

License

BSD

Documentation

http://trinamed_struct.readthedocs.org.

Changelog

1.2.0 (2020-04-24)

  • Upped dependency tri.declarative to 5.x

1.1.0 (2019-10-15)

  • Upped dependency tri.declarative to 4.x

1.0.0 (2019-06-10)

  • Renamed package from tri.named_struct to tri_named_struct

  • Dropped python2 support

0.12.0 (2016-08-30)

  • Fix class level override of named struct fields.

0.11.0 (2016-05-06)

  • Fix default values shadowing values set explicitly in subclass __init__ method.

0.10.0 (2016-01-12)

  • Added default_factory argument to specify default values via a callback.

Metadata

Release files for tri.named-struct 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tri.named-struct 1.2.0
File Size Uploaded Provenance Actions
tri.named-struct-1.2.0.tar.gz 5.7 kB Without provenance Details for tri.named-struct-1.2.0.tar.gz

Release files / tri.named-struct-1.2.0.tar.gz

Download URL tri.named-struct-1.2.0.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5737bc7d104b485f6ac0c33afb23e36048d3f7b73c5d5988026a34f21f83dd1e
BLAKE2b-256 checksum
How to use checksums
c18c03b678ca460a82f9271deae384a406739ebc69b4e0425e2652621c694608
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.7

Security for tri.named-struct 1.2.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page