Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
move DataclassInstance to dataclasses.pyi
  • Loading branch information
ikonst committed Aug 27, 2023
commit 0b95f3eaad6857d3b001d0278c8f2b40c16e11aa
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')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this can potentially introduce some new weak spots, but on other hand it can eventually work :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a false positive but it's due to #15974.


[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