darlog-dataclass
A tiny module with ABSOLUTELY essential utils for dataclasses, that should've always been there.
Despite the whole point of built-in dataclasses is to prevent boilerplate code - counter-intuitively, this is exactly what they lead to if you try to write clean, pythonic and - especially - type-hinted code.
To avoid heavy dependencies, I kept reimplementing basically the same stuff for dataclasses in many of my python projects, until I got sick of it. So, here's this package. I made it just for myself (to share the heavily reused code between the projects), but feel free to use it.
Type-hints
Defines:
_P_Dataclassas dataclass protocol;_T_Dataclassas its respective (bound)TypeVar;_Tas a bonus (just an arbitraryTypeVar).
They're deliberately named as protected members (start with _), but still imported with:
from darlog.dataclass import *
Conditional kwargs
dataclass decorator has different sets of arguments for various python versions. Infamously, slots was added only in 3.10. The following static classes behave like dicts that specify (or not) a specific argument, depending on the current version of python interpreter.
| Class | What adds | If python is... |
|---|---|---|
Slots |
slots=True |
3.10+ |
KWOnly |
kw_only=True |
3.10+ |
NotMatchArgs |
match_args=False |
3.10+ |
WeakrefSlot |
weakref_slot=True |
3.11+ |
Usage is simple: just pass them as unpacked kwargs:
from darlog.dataclass import *
@dataclass(frozen=True, **Slots)
class DataClassWithSlotsWhenPossible: ...
@dataclass(**Slots, **WeakrefSlot)
class DataClassWithWeakrefSlotsWhenPossible: ...
The metaclass they're made with - _OptionalKwargsMeta - is also available to make your own python-version-dependent kwargs. But it's imported only explicitly:
from darlog.dataclass import _OptionalKwargsMeta
class FrozenOnlySince39(metaclass=_OptionalKwargsMeta):
kwargs = dict(frozen=True)
min_python = (3, 9)
@dataclass(**FrozenOnlySince39)
class MyDataClass: ...
Utility functions
dc_fields_dict: Return all the field names/values from the dataclass instance - as dict. No deep-copy.dc_override: Copy a dataclass instance to a new one, with optional overrides.
Base classes to inherit from
The following ABC classes define class-level methods:
FieldAccessPropsDC- adds:fields- tuple ofField,field_names- tuple ofstr,field_names_set- frozenset ofstr.
UnsafeInitDC- addsunsafe_init, which silently swallows any invalid keyword arguments and creates the instance anyway (as long as required arguments passed).
Metadata
Release files for darlog-dataclass 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| darlog_dataclass-0.0.2.tar.gz | 15.6 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| darlog_dataclass-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 27.6 kB
Release files / darlog_dataclass-0.0.2.tar.gz
| Download URL | darlog_dataclass-0.0.2.tar.gz |
|---|---|
| Size | 15.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4725f2a3f1d6231844e17fd1727578089b1081f25d734c0daaa72afb11eb893b
|
|
BLAKE2b-256 checksum How to use checksums |
3d05824f48192d15591541cb2521f8a9827dec0e69f8deaa951379e846004ef1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.
Transparency logRelease files / darlog_dataclass-0.0.2-py3-none-any.whl
| Download URL | darlog_dataclass-0.0.2-py3-none-any.whl |
|---|---|
| Size | 12.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f451dcee559ec3145ad6966d29dea7ba7d4206d529abe6dfdccdf0dbd5f9d557
|
|
BLAKE2b-256 checksum How to use checksums |
282826f096f9bc43c2d91f152f779fcd2ca0c8b67cdc00852ebd37d0e9fc1bcf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.
Transparency logSecurity for darlog-dataclass 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for darlog_dataclass-0.0.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.