8000 gh-99957: Add `frozen_default` parameter on `dataclass_transform` by debonte · Pull Request #99958 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-99957: Add frozen_default parameter on dataclass_transform #99958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update docs, typing.py, tests
  • Loading branch information
debonte committed Dec 2, 2022
commit ab0ee4da7059e5cc43fe1c48120ecc1f018f2d9d
4 changes: 4 additions & 0 deletions Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2575,6 +2575,10 @@ Functions and decorators
assumed to be True or False if it is omitted by the caller.
* ``kw_only_default`` indicates whether the ``kw_only`` parameter is
assumed to be True or False if it is omitted by the caller.
* ``frozen_default`` indicates whether the ``frozen`` parameter is
assumed to be True or False if it is omitted by the caller.

.. versionadded:: 3.12
* ``field_specifiers`` specifies a static list of supported classes
or functions that describe fields, similar to ``dataclasses.field()``.
* Arbitrary other keyword arguments are accepted in order to allow for
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7719,6 +7719,7 @@ class CustomerModel:
"eq_default": True,
"order_default": False,
"kw_only_default": True,
"frozen_default": False,
"field_specifiers": (),
"kwargs": {},
}
Expand Down Expand Up @@ -7749,6 +7750,7 @@ class CustomerModel(Decorated, frozen=True):
"eq_default": True,
"order_default": True,
"kw_only_default": False,
"frozen_default": False,
"field_specifiers": (),
"kwargs": {"make_everything_awesome": True},
}
Expand Down Expand Up @@ -7780,6 +7782,7 @@ class CustomerModel(ModelBase, init=False):
"eq_default": True,
"order_default": True,
"kw_only_default": False,
"frozen_default": False,
"field_specifiers": (Field,),
"kwargs": {},
}
Expand Down
5 changes: 5 additions & 0 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3363,6 +3363,7 @@ def dataclass_transform(
eq_default: bool = True,
order_default: bool = False,
kw_only_default: bool = False,
frozen_default: bool = False,
field_specifiers: tuple[type[Any] | Callable[..., Any], ...] = (),
**kwargs: Any,
) -> Callable[[T], T]:
Expand Down Expand Up @@ -3416,6 +3417,9 @@ class CustomerModel(ModelBase):
assumed to be True or False if it is omitted by the caller.
- ``kw_only_default`` indicates whether the ``kw_only`` parameter is
assumed to be True or False if it is omitted by the caller.
- ``frozen_default`` indicates whether the ``frozen`` parameter is
assumed to be True or False if it is omitted by the caller. Only
supported in Python 3.12+.
- ``field_specifiers`` specifies a static list of supported classes
or functions that describe fields, similar to ``dataclasses.field()``.
- Arbitrary other keyword arguments are accepted in order to allow for
Expand All @@ -3432,6 +3436,7 @@ def decorator(cls_or_fn):
"eq_default": eq_default,
"order_default": order_default,
"kw_only_default": kw_only_default,
"frozen_default": frozen_default,
"field_specifiers": field_specifiers,
"kwargs": kwargs,
}
Expand Down
0