dataclasses that import quickly
Project description
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).
pip install lazydataclasses
Compatability/Completeness
Included are a copy of the stdlib tests as of 3.14.
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
InitVarsupport. 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
uv run pytest
uv run mypy src tests --strict
Updating test suite
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 *`
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lazydataclasses-0.0.1.tar.gz.
File metadata
- Download URL: lazydataclasses-0.0.1.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95002ddb58d74d73c5cdcbe9712489b8b642425a06b25954332391da04ab80f7
|
|
| MD5 |
33eaa5dc426bea67864f796e6593b16f
|
|
| BLAKE2b-256 |
5bcb0861eb37bf7582690c458c884ffab542ba850ba5d02c5b34d9ac93e6a133
|
File details
Details for the file lazydataclasses-0.0.1-py3-none-any.whl.
File metadata
- Download URL: lazydataclasses-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62d4cd57e21593668b6aead24aae653b367b322f468fb327ba365fb21f29ada4
|
|
| MD5 |
57c429655d97b8593b957a707d72ee51
|
|
| BLAKE2b-256 |
8cd78356281501ce5550dd87ec47c4a83d13f8fa3963f3dc4c52d8e00c0b1643
|