Skip to content

Commit 5c19050

Browse files
authored
gh-99957: Add frozen_default parameter on dataclass_transform (#99958)
1 parent bed15f8 commit 5c19050

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

Doc/library/typing.rst

+4
Original file line numberDiff line numberDiff line change
@@ -2575,6 +2575,10 @@ Functions and decorators
25752575
assumed to be True or False if it is omitted by the caller.
25762576
* ``kw_only_default`` indicates whether the ``kw_only`` parameter is
25772577
assumed to be True or False if it is omitted by the caller.
2578+
* ``frozen_default`` indicates whether the ``frozen`` parameter is
2579+
assumed to be True or False if it is omitted by the caller.
2580+
2581+
.. versionadded:: 3.12
25782582
* ``field_specifiers`` specifies a static list of supported classes
25792583
or functions that describe fields, similar to ``dataclasses.field()``.
25802584
* Arbitrary other keyword arguments are accepted in order to allow for

Lib/test/test_typing.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -7719,6 +7719,7 @@ class CustomerModel:
77197719
"eq_default": True,
77207720
"order_default": False,
77217721
"kw_only_default": True,
7722+
"frozen_default": False,
77227723
"field_specifiers": (),
77237724
"kwargs": {},
77247725
}
@@ -7749,6 +7750,7 @@ class CustomerModel(Decorated, frozen=True):
77497750
"eq_default": True,
77507751
"order_default": True,
77517752
"kw_only_default": False,
7753+
"frozen_default": False,
77527754
"field_specifiers": (),
77537755
"kwargs": {"make_everything_awesome": True},
77547756
}
@@ -7765,7 +7767,7 @@ def __new__(
77657767
return super().__new__(cls, name, bases, namespace)
77667768

77677769
Decorated = dataclass_transform(
7768-
order_default=True, field_specifiers=(Field,)
7770+
order_default=True, frozen_default=True, field_specifiers=(Field,)
77697771
)(ModelMeta)
77707772

77717773
class ModelBase(metaclass=Decorated): ...
@@ -7780,6 +7782,7 @@ class CustomerModel(ModelBase, init=False):
77807782
"eq_default": True,
77817783
"order_default": True,
77827784
"kw_only_default": False,
7785+
"frozen_default": True,
77837786
"field_specifiers": (Field,),
77847787
"kwargs": {},
77857788
}

Lib/typing.py

+4
Original file line numberDiff line numberDiff line change
@@ -3363,6 +3363,7 @@ def dataclass_transform(
33633363
eq_default: bool = True,
33643364
order_default: bool = False,
33653365
kw_only_default: bool = False,
3366+
frozen_default: bool = False,
33663367
field_specifiers: tuple[type[Any] | Callable[..., Any], ...] = (),
33673368
**kwargs: Any,
33683369
) -> Callable[[T], T]:
@@ -3416,6 +3417,8 @@ class CustomerModel(ModelBase):
34163417
assumed to be True or False if it is omitted by the caller.
34173418
- ``kw_only_default`` indicates whether the ``kw_only`` parameter is
34183419
assumed to be True or False if it is omitted by the caller.
3420+
- ``frozen_default`` indicates whether the ``frozen`` parameter is
3421+
assumed to be True or False if it is omitted by the caller.
34193422
- ``field_specifiers`` specifies a static list of supported classes
34203423
or functions that describe fields, similar to ``dataclasses.field()``.
34213424
- Arbitrary other keyword arguments are accepted in order to allow for
@@ -3432,6 +3435,7 @@ def decorator(cls_or_fn):
34323435
"eq_default": eq_default,
34333436
"order_default": order_default,
34343437
"kw_only_default": kw_only_default,
3438+
"frozen_default": frozen_default,
34353439
"field_specifiers": field_specifiers,
34363440
"kwargs": kwargs,
34373441
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add ``frozen_default`` parameter to :func:`typing.dataclass_transform`.

0 commit comments

Comments
 (0)