Add dataclass_factory
argument to dataclasses.make_dataclass
for custom dataclass transformation support
#118974
Labels
type-feature
A feature request or enhancement
Feature or enhancement
Proposal:
typing.dataclass_transform
(PEP 681 – Data Class Transforms) allows users define their owndataclass
decorator that can be recognized by the type checker.Here is a real-world example use case:
flax.struct.dataclass
Also,
dataclasses.asdict
anddataclasses.astuple
allow users pass an extra argument for the factory of the returned instance.cpython/Lib/dataclasses.py
Lines 1299 to 1317 in 0fb18b0
cpython/Lib/dataclasses.py
Lines 1380 to 1397 in 0fb18b0
However, the
make_dataclass
function does not support third-partydataclass
factory (e.g.,flax.struct.dataclass
):cpython/Lib/dataclasses.py
Lines 1441 to 1528 in 0fb18b0
It can only apply
dataclasses.dataclass
(see thereturn
statement above).This feature request issue will discuss the possibility of adding a new
dataclass_factory
argument to thedataclasses.make_dataclass
to support third-party dataclasss transformation, similar todict_factory
fordataclasses.asdict
.Has this already been discussed elsewhere?
https://discuss.python.org/t/add-dataclass-factory-argument-to-dataclasses-make-dataclass-for-custom-dataclass-transformation-support/53188
Links to previous discussion of this feature:
No response
The text was updated successfully, but these errors were encountered: