Data Records

URL:

Pypi: https://pypi.org/project/data-records/

Gitlab: https://gitlab.com/mc706/data-records

Description

A class decorator like @dataclass except only immutable options and type coercion and strict typing. It changes the less than desirable behavior of

1
2
3
4
5
6
7
8
9
>>> from dataclasses import dataclass, field

>>> @dataclass
... class Foo:
... bar: str
... baz: int

>>> Foo(1, 2)
Foo(bar=1, baz=2)

to either do what you would expect or fail at initialisation instead of downstream during usage.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
>>> from data_records import datarecord

>>> @datarecord
... class Foo:
... bar: str
... baz: int

>>> Foo(1, 2)
Foo(bar='1', baz=2)

>>> Foo("a", "b")
Traceback (most recent call last):
...
ValueError: invalid literal for int() with base 10: 'b'

Technologies:

  • Python
  • Macro Programming

Setup

1
$ pip install data-records

Documentation

ReadTheDocs