Skip to content

Commit 0b95f3e

Browse files
committed
move DataclassInstance to dataclasses.pyi
1 parent a657d10 commit 0b95f3e

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

test-data/unit/check-dataclass-transform.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ class Person:
853853
name: str
854854

855855
p = Person('John')
856-
y = replace(p, name='Bob') # E: Argument 1 to "replace" has incompatible type "Person"; expected a dataclass
856+
y = replace(p, name='Bob')
857857

858858
[typing fixtures/typing-full.pyi]
859859
[builtins fixtures/dataclasses.pyi]

test-data/unit/lib-stub/_typeshed.pyi

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
from dataclasses import Field
2-
from typing import Any, ClassVar, Protocol, TypeVar, Iterable
1+
from typing import Protocol, TypeVar, Iterable
32

43
_KT = TypeVar("_KT")
54
_VT_co = TypeVar("_VT_co", covariant=True)
65

76
class SupportsKeysAndGetItem(Protocol[_KT, _VT_co]):
87
def keys(self) -> Iterable[_KT]: pass
98
def __getitem__(self, __key: _KT) -> _VT_co: pass
10-
11-
class DataclassInstance(Protocol):
12-
__dataclass_fields__: ClassVar[dict[str, Field[Any]]]

test-data/unit/lib-stub/dataclasses.pyi

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
from _typeshed import DataclassInstance
2-
from typing import Any, Callable, Generic, Literal, Mapping, Optional, TypeVar, overload, Type
1+
from typing import Any, Callable, Generic, Literal, Mapping, Optional, TypeVar, overload, Type, \
2+
Protocol, ClassVar
33
from typing_extensions import TypeGuard
44

5+
# DataclassInstance is in _typeshed.pyi normally, but alas we can't do the same for lib-stub
6+
# due to test-data/unit/lib-stub/builtins.pyi not having 'tuple'.
7+
class DataclassInstance(Protocol):
8+
__dataclass_fields__: ClassVar[dict[str, Field[Any]]]
9+
510
_T = TypeVar('_T')
611
_DataclassT = TypeVar("_DataclassT", bound=DataclassInstance)
712

0 commit comments

Comments
 (0)