Metadata-Version: 2.3
Name: lazydataclasses
Version: 0.0.1
Summary: dataclasses that import quickly
Author: Oli Russell
Author-email: Oli Russell <mrxoliver@gmail.com>
Requires-Python: >=3.12
Project-URL: repository, https://github.com/leontrolski/lazydataclasses
Description-Content-Type: text/markdown

# lazydataclasses

Dataclass constructor, but lazier.

This module exposes a decorator `@dataclass` that should return a class that looks like, smells like, behaves like a `dataclasses.dataclass`. The difference (for our purposes) is that its `__dataclass_fields__` are loaded lazily rather than at import time. This speeds up imports by around 5x at the expense of slowing down init time (around 10x slower).

```shell
pip install lazydataclasses
```

## Compatability/Completeness

Included are a copy of [the stdlib tests as of 3.14](./tests/test_dataclasses/test_stdlib.py).

Most stuff passes, however the following features are unsupported:

- No `__slots__` support.
- Some errors have moved from class-creation time to field-lookup time. Everywhere `dataclasses.fields(...)` appears it is because there is an error that no longer appears at class-creation time, most methods (eg. `__init__`)  do a field-lookup, so these should eventually get raised.
- No `InitVar` support. This is pure laziness, I've never seen one in the wild.
- No generated docstring support, again pure laziness.
- `inspect.signature(MyDataclass.__init__)` no longer works the same as the methods aren't codegenned at import time, there are `*args, **kwargs`.
- A few other very small things - see `@pytest.mark.xfail`.

## Development

```shell
uv run pytest
uv run mypy src tests --strict
```

### Updating test suite

```shell
rm -r tests/test_dataclasses
curl 'https://github.com/python/cpython/archive/refs/tags/v3.14.0b3.zip'
unzip ...
cp -r ../cpython/Lib/test/test_dataclasses tests/
mv tests/test_dataclasses/__init__.py tests/test_dataclasses/test_stdlib.py
# add `from lazydataclasses import dataclass` import below `from dataclasses import *`
```
