From 6fd543b44d9fdace01056398544edfd9fc4e9c97 Mon Sep 17 00:00:00 2001 From: Ilya Priven Date: Sat, 26 Aug 2023 23:00:09 -0400 Subject: [PATCH] move DataclassInstance to dataclasses.pyi --- test-data/unit/check-dataclass-transform.test | 2 +- test-data/unit/lib-stub/_typeshed.pyi | 6 +----- test-data/unit/lib-stub/dataclasses.pyi | 9 +++++++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/test-data/unit/check-dataclass-transform.test b/test-data/unit/check-dataclass-transform.test index 9029582ece82a..58cd5e5a90f80 100644 --- a/test-data/unit/check-dataclass-transform.test +++ b/test-data/unit/check-dataclass-transform.test @@ -853,7 +853,7 @@ class Person: name: str p = Person('John') -y = replace(p, name='Bob') # E: Argument 1 to "replace" has incompatible type "Person"; expected a dataclass +y = replace(p, name='Bob') [typing fixtures/typing-full.pyi] [builtins fixtures/dataclasses.pyi] diff --git a/test-data/unit/lib-stub/_typeshed.pyi b/test-data/unit/lib-stub/_typeshed.pyi index 7ae427b3c7a61..054ad0ec0c464 100644 --- a/test-data/unit/lib-stub/_typeshed.pyi +++ b/test-data/unit/lib-stub/_typeshed.pyi @@ -1,5 +1,4 @@ -from dataclasses import Field -from typing import Any, ClassVar, Protocol, TypeVar, Iterable +from typing import Protocol, TypeVar, Iterable _KT = TypeVar("_KT") _VT_co = TypeVar("_VT_co", covariant=True) @@ -7,6 +6,3 @@ _VT_co = TypeVar("_VT_co", covariant=True) class SupportsKeysAndGetItem(Protocol[_KT, _VT_co]): def keys(self) -> Iterable[_KT]: pass def __getitem__(self, __key: _KT) -> _VT_co: pass - -class DataclassInstance(Protocol): - __dataclass_fields__: ClassVar[dict[str, Field[Any]]] diff --git a/test-data/unit/lib-stub/dataclasses.pyi b/test-data/unit/lib-stub/dataclasses.pyi index 2d0910e523399..325b33c465627 100644 --- a/test-data/unit/lib-stub/dataclasses.pyi +++ b/test-data/unit/lib-stub/dataclasses.pyi @@ -1,7 +1,12 @@ -from _typeshed import DataclassInstance -from typing import Any, Callable, Generic, Literal, Mapping, Optional, TypeVar, overload, Type +from typing import Any, Callable, Generic, Literal, Mapping, Optional, TypeVar, overload, Type, \ + Protocol, ClassVar from typing_extensions import TypeGuard +# DataclassInstance is in _typeshed.pyi in stdlib, but this brings too many deps +# into a too common of a file, which doesn't bode well with incomplete fixtures :/ +class DataclassInstance(Protocol): + __dataclass_fields__: ClassVar[dict[str, Field[Any]]] + _T = TypeVar('_T') _DataclassT = TypeVar("_DataclassT", bound=DataclassInstance)