Skip to content

Commit

Permalink
move DataclassInstance to dataclasses.pyi
Browse files Browse the repository at this point in the history
  • Loading branch information
ikonst committed Aug 27, 2023
1 parent a657d10 commit 0b95f3e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion test-data/unit/check-dataclass-transform.test
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 1 addition & 5 deletions test-data/unit/lib-stub/_typeshed.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
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)

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]]]
9 changes: 7 additions & 2 deletions test-data/unit/lib-stub/dataclasses.pyi
Original file line number Diff line number Diff line change
@@ -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 normally, but alas we can't do the same for lib-stub
# due to test-data/unit/lib-stub/builtins.pyi not having 'tuple'.
class DataclassInstance(Protocol):
__dataclass_fields__: ClassVar[dict[str, Field[Any]]]

_T = TypeVar('_T')
_DataclassT = TypeVar("_DataclassT", bound=DataclassInstance)

Expand Down

0 comments on commit 0b95f3e

Please sign in to comment.