semvec/pypi-packages huggingface dataset:
tri.named-struct 1.2.0
tri.named-struct supplies a class that can be used like dictionaries (or via attribute access), but with a predefined set of possible key values
License: BSD
Keywords: tri.named-struct

.. image:: https://travis-ci.org/TriOptima/tri.named-struct.svg?branch=master
    :target: https://travis-ci.org/TriOptima/tri.named-struct
.. image:: http://codecov.io/github/TriOptima/tri.named-struct/coverage.svg?branch=master
    :target: http://codecov.io/github/TriOptima/tri.named-struct?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
-------

.. code:: python

    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:

.. code:: python

    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:

.. code:: python

    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 :code:`NamedStruct` subclass:

.. code:: python

    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 :code:`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.