Skip to content
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

use Literal[_MISSING_TYPE.MISSING] for dataclasses.field defaults #13256

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 0 additions & 2 deletions stdlib/@tests/stubtest_allowlists/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,6 @@ _?ctypes.Union.__getattr__ # doesn't exist, but makes things easy if we pretend
# These would ideally be special-cased by type checkers; see https://github.com/python/mypy/issues/2220
_?ctypes.Array.__iter__

dataclasses.field # White lies around defaults

# __all__-related weirdness (see #6523)
email.__all__
email.base64mime
Expand Down
14 changes: 11 additions & 3 deletions stdlib/dataclasses.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -152,40 +152,45 @@ if sys.version_info >= (3, 10):
def field(
*,
default: _T,
default_factory: Literal[_MISSING_TYPE.MISSING] = ...,
init: bool = True,
repr: bool = True,
hash: bool | None = None,
compare: bool = True,
metadata: Mapping[Any, Any] | None = None,
kw_only: bool = ...,
kw_only: bool | Literal[_MISSING_TYPE.MISSING] = ...,
) -> _T: ...
@overload
def field(
*,
default: Literal[_MISSING_TYPE.MISSING] = ...,
default_factory: Callable[[], _T],
init: bool = True,
repr: bool = True,
hash: bool | None = None,
compare: bool = True,
metadata: Mapping[Any, Any] | None = None,
kw_only: bool = ...,
kw_only: bool | Literal[_MISSING_TYPE.MISSING] = ...,
) -> _T: ...
@overload
def field(
*,
default: Literal[_MISSING_TYPE.MISSING] = ...,
default_factory: Literal[_MISSING_TYPE.MISSING] = ...,
init: bool = True,
repr: bool = True,
hash: bool | None = None,
compare: bool = True,
metadata: Mapping[Any, Any] | None = None,
kw_only: bool = ...,
kw_only: bool | Literal[_MISSING_TYPE.MISSING] = ...,
) -> Any: ...

else:
@overload # `default` and `default_factory` are optional and mutually exclusive.
def field(
*,
default: _T,
default_factory: Literal[_MISSING_TYPE.MISSING] = ...,
init: bool = True,
repr: bool = True,
hash: bool | None = None,
Expand All @@ -195,6 +200,7 @@ else:
@overload
def field(
*,
default: Literal[_MISSING_TYPE.MISSING] = ...,
default_factory: Callable[[], _T],
init: bool = True,
repr: bool = True,
Expand All @@ -205,6 +211,8 @@ else:
@overload
def field(
*,
default: Literal[_MISSING_TYPE.MISSING] = ...,
default_factory: Literal[_MISSING_TYPE.MISSING] = ...,
init: bool = True,
repr: bool = True,
hash: bool | None = None,
Expand Down
Loading