Use dataclasses without variable annotations.
Project description
typeless-dataclasses: use dataclasses without variable annotations
Have you ever wanted to use dataclasses, but don't like type annotations?
@dataclass class Data: one: Any two: Any = 2
... and don't want to resort to any ugly hacks like this one?
@dataclass class Data: one: ... two: ... = 2
With the power of typeless-dataclasses, now you can!
@dataclass @typeless class Data: one = field() two = field(default=2)
Compare with attrs:
@attr.s class Data: one = attr.ib() two = attr.ib(default=2)
Installing
Install and update using pip:
$ pip install --upgrade typeless-dataclasses
typeless-dataclasses offers a type-annotation-free experience for Python 3.6* and newer, and PyPy.
(On 3.6, you also need to install the dataclasses backport.)
A Simple Example
Using typeless-dataclasses is easy!
Just add @typeless to your class before @dataclass, and use field() as you normally would; field() attributes become instance variables, and all others remain class variables.
>>> from dataclasses import dataclass, field >>> from typeless_dataclasses import typeless >>> >>> @dataclass ... @typeless ... class Data: ... one = field() ... two = field(default=2) ... three = 3 ... >>> Data(1) Data(one=1, two=2)
Links
- Documentation: https://github.com/lemon24/typeless-dataclasses/blob/master/README.md
- Changes: https://github.com/lemon24/typeless-dataclasses/blob/master/CHANGES.md
- PyPI Releases: https://pypi.org/project/typeless-dataclasses/
- Source Code: https://github.com/lemon24/typeless-dataclasses
- Issue Tracker: https://github.com/lemon24/typeless-dataclasses/issues
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for typeless_dataclasses-1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a71e86787ee4b043b3f84f9ce9da5d2e0148d37226c513641ed2e5639450d2e7 |
|
MD5 | 79322ad10d0b17c51668b1308d77a215 |
|
BLAKE2-256 | a2bce249f705a2da3b20b929f8000f6c58a64b50231f8e238366336f12f4e776 |