@@ -64,6 +64,12 @@ certain features or make small adjustments to the way they use them.
64
64
That's already true for the Mypy custom plugins, which
65
65
don't support every feature of every dataclass-like library.
66
66
67
+ As new features are added to dataclass in the future, we intend, when
68
+ appropriate, to add support for those features on
69
+ ``dataclass_transform `` as well. Keeping these two feature sets in
70
+ sync will make it easier for dataclass users to understand and use
71
+ ``dataclass_transform `` and will simplify the maintenance of dataclass
72
+ support in type checkers.
67
73
68
74
Specification
69
75
=============
@@ -185,8 +191,8 @@ the bool value (``True`` or ``False``) to be statically evaluated.
185
191
* ``eq ``. ``order ``, ``frozen ``, ``init `` and ``unsafe_hash `` are parameters
186
192
supported in the stdlib dataclass, with meanings defined in :pep: `557 <557#id7 >`.
187
193
* ``hash `` is an alias for the ``unsafe_hash `` parameter.
188
- * ``kw_only `` and ``slots `` are parameters supported in the stdlib dataclass,
189
- first introduced in Python 3.10.
194
+ * ``kw_only ``, `` match_args `` and ``slots `` are parameters supported
195
+ in the stdlib dataclass, first introduced in Python 3.10.
190
196
191
197
``dataclass_transform `` parameters
192
198
----------------------------------
@@ -366,6 +372,11 @@ descriptor classes typically use common parameter names to construct
366
372
these field descriptors. This specification formalizes the names and
367
373
meanings of the parameters that must be understood for static type
368
374
checkers. These standardized parameters must be keyword-only.
375
+
376
+ These parameters are a superset of those supported by
377
+ ``dataclasses.field ``, excluding those that do not have an impact on
378
+ type checking such as ``compare `` and ``hash ``.
379
+
369
380
Field descriptor classes are allowed to use other
370
381
parameters in their constructors, and those parameters can be
371
382
positional and may use other names.
@@ -386,6 +397,12 @@ positional and may use other names.
386
397
* ``factory `` is an alias for ``default_factory ``. Stdlib dataclasses
387
398
use the name ``default_factory ``, but attrs uses the name ``factory ``
388
399
in many scenarios, so this alias is necessary for supporting attrs.
400
+ * ``kw_only `` is an optional bool parameter that indicates whether the
401
+ field should be marked as keyword-only. If true, the field will be
402
+ keyword-only. If false, it will not be keyword-only. If unspecified,
403
+ the value of the ``kw_only `` parameter on the object decorated with
404
+ ``dataclass_transform `` will be used, or if that is unspecified, the
405
+ value of ``kw_only_default `` on ``dataclass_transform `` will be used.
389
406
* ``alias `` is an optional str parameter that provides an alternative
390
407
name for the field. This alternative name is used in the synthesized
391
408
``__init__ `` method.
@@ -612,13 +629,6 @@ a ``cmp`` parameter, since it only applies to attrs. Attrs users
612
629
should use the dataclass-standard ``eq `` and ``order `` parameter names
613
630
instead.
614
631
615
- ``kw_only `` field descriptor parameter
616
- --------------------------------------
617
-
618
- The attrs library supports a ``kw_only `` parameter for individual
619
- fields. We chose not to support a ``kw_only `` parameter, since it is
620
- specific to attrs.
621
-
622
632
Automatic field name aliasing
623
633
-----------------------------
624
634
@@ -629,7 +639,6 @@ underscore from the name of the corresponding ``__init__`` parameter.
629
639
This proposal omits that behavior since it is specific to attrs. Users
630
640
can manually alias these fields using the ``alias `` parameter.
631
641
632
-
633
642
Alternate field ordering algorithms
634
643
-----------------------------------
635
644
0 commit comments