@@ -84,6 +84,8 @@ annotations. These include:
84
84
*Introducing * :data: `Self `
85
85
* :pep: `675 `: Arbitrary Literal String Type
86
86
*Introducing * :data: `LiteralString `
87
+ * :pep: `681 `: Data Class Transforms
88
+ *Introducing * the :func: `@dataclass_transform<dataclass_transform> ` decorator
87
89
88
90
.. _type-aliases :
89
91
@@ -2528,7 +2530,17 @@ Functions and decorators
2528
2530
For example, type checkers will assume these classes have
2529
2531
``__init__ `` methods that accept ``id `` and ``name ``.
2530
2532
2531
- The arguments to this decorator can be used to customize this behavior:
2533
+ The decorated class, metaclass, or function may accept the following bool
2534
+ arguments which type checkers will assume have the same effect as they
2535
+ would have on the
2536
+ :func: `@dataclasses.dataclass<dataclasses.dataclass> ` decorator: ``init ``,
2537
+ ``eq ``, ``order ``, ``unsafe_hash ``, ``frozen ``, ``match_args ``,
2538
+ ``kw_only ``, and ``slots ``. It must be possible for the value of these
2539
+ arguments (``True `` or ``False ``) to be statically evaluated.
2540
+
2541
+ The arguments to the ``dataclass_transform `` decorator can be used to
2542
+ customize the default behaviors of the decorated class, metaclass, or
2543
+ function:
2532
2544
2533
2545
* ``eq_default `` indicates whether the ``eq `` parameter is assumed to be
2534
2546
``True `` or ``False `` if it is omitted by the caller.
@@ -2541,6 +2553,28 @@ Functions and decorators
2541
2553
* Arbitrary other keyword arguments are accepted in order to allow for
2542
2554
possible future extensions.
2543
2555
2556
+ Type checkers recognize the following optional arguments on field
2557
+ specifiers:
2558
+
2559
+ * ``init `` indicates whether the field should be included in the
2560
+ synthesized ``__init__ `` method. If unspecified, ``init `` defaults to
2561
+ ``True ``.
2562
+ * ``default `` provides the default value for the field.
2563
+ * ``default_factory `` provides a runtime callback that returns the
2564
+ default value for the field. If neither ``default `` nor
2565
+ ``default_factory `` are specified, the field is assumed to have no
2566
+ default value and must be provided a value when the class is
2567
+ instantiated.
2568
+ * ``factory `` is an alias for ``default_factory ``.
2569
+ * ``kw_only `` indicates whether the field should be marked as
2570
+ keyword-only. If ``True ``, the field will be keyword-only. If
2571
+ ``False ``, it will not be keyword-only. If unspecified, the value of
2572
+ the ``kw_only `` parameter on the object decorated with
2573
+ ``dataclass_transform `` will be used, or if that is unspecified, the
2574
+ value of ``kw_only_default `` on ``dataclass_transform `` will be used.
2575
+ * ``alias `` provides an alternative name for the field. This alternative
2576
+ name is used in the synthesized ``__init__ `` method.
2577
+
2544
2578
At runtime, this decorator records its arguments in the
2545
2579
``__dataclass_transform__ `` attribute on the decorated object.
2546
2580
It has no other runtime effect.
0 commit comments