diff --git a/stdlib/dataclasses.pyi b/stdlib/dataclasses.pyi index 00e0d31d0..c36112270 100644 --- a/stdlib/dataclasses.pyi +++ b/stdlib/dataclasses.pyi @@ -243,7 +243,7 @@ class InitVar(Generic[_T], metaclass=_InitVarMeta): if sys.version_info >= (3, 12): def make_dataclass( cls_name: str, - fields: Iterable[str | tuple[str, type] | tuple[str, type, Any]], + fields: Iterable[str | tuple[str, Any] | tuple[str, Any, Any]], *, bases: tuple[type, ...] = (), namespace: dict[str, Any] | None = None, @@ -263,7 +263,7 @@ if sys.version_info >= (3, 12): elif sys.version_info >= (3, 11): def make_dataclass( cls_name: str, - fields: Iterable[str | tuple[str, type] | tuple[str, type, Any]], + fields: Iterable[str | tuple[str, Any] | tuple[str, Any, Any]], *, bases: tuple[type, ...] = (), namespace: dict[str, Any] | None = None, @@ -282,7 +282,7 @@ elif sys.version_info >= (3, 11): elif sys.version_info >= (3, 10): def make_dataclass( cls_name: str, - fields: Iterable[str | tuple[str, type] | tuple[str, type, Any]], + fields: Iterable[str | tuple[str, Any] | tuple[str, Any, Any]], *, bases: tuple[type, ...] = (), namespace: dict[str, Any] | None = None, @@ -300,7 +300,7 @@ elif sys.version_info >= (3, 10): else: def make_dataclass( cls_name: str, - fields: Iterable[str | tuple[str, type] | tuple[str, type, Any]], + fields: Iterable[str | tuple[str, Any] | tuple[str, Any, Any]], *, bases: tuple[type, ...] = (), namespace: dict[str, Any] | None = None, diff --git a/test_cases/stdlib/check_dataclasses.py b/test_cases/stdlib/check_dataclasses.py index b06c4a9ff..76ce8e1bd 100644 --- a/test_cases/stdlib/check_dataclasses.py +++ b/test_cases/stdlib/check_dataclasses.py @@ -1,8 +1,8 @@ from __future__ import annotations import dataclasses as dc -from typing import TYPE_CHECKING, Any, Dict, Tuple, Type, Union -from typing_extensions import assert_type +from typing import TYPE_CHECKING, Any, Dict, FrozenSet, Tuple, Type, Union +from typing_extensions import Annotated, assert_type if TYPE_CHECKING: from _typeshed import DataclassInstance @@ -88,3 +88,14 @@ def check_other_isdataclass_overloads(x: type, y: object) -> None: assert_type(dc.asdict(y), Dict[str, Any]) assert_type(dc.astuple(y), Tuple[Any, ...]) dc.replace(y) + + +# Regression test for #11653 +D = dc.make_dataclass( + "D", [("a", Union[int, None]), "y", ("z", Annotated[FrozenSet[bytes], "metadata"], dc.field(default=frozenset({b"foo"})))] +) +# Check that it's inferred by the type checker as a class object of some kind +# (but don't assert the exact type that `D` is inferred as, +# in case a type checker decides to add some special-casing for +# `make_dataclass` in the future) +assert_type(D.__mro__, Tuple[type, ...])