Skip to main content

Use dataclasses without variable annotations.

Project description

typeless-dataclasses: use dataclasses without variable annotations

build codecov PyPI black

Have you ever wanted to use dataclasses, but don't like type annotations?

class Data:
    one: Any
    two: Any = 2

... and don't want to resort to any ugly hacks like this one?

class Data:
    one: ...
    two: ... = 2

With the power of typeless-dataclasses, now you can!

class Data:
    one = field()
    two = field(default=2)

Compare with attrs:

class Data:
    one = attr.ib()
    two = attr.ib(default=2)


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)


Project details

Release history Release notifications | RSS feed

This version


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

typeless-dataclasses-1.0.tar.gz (5.6 kB view hashes)

Uploaded Source

Built Distribution

typeless_dataclasses-1.0-py3-none-any.whl (4.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page