Closed
Description
import dataclasses
from dataclasses import dataclass, replace
from typing import Any, ClassVar, Generic, Protocol, Self, TypeVar
class DataclassInstance(Protocol):
__dataclass_fields__: ClassVar[dict[str, dataclasses.Field[Any]]]
T = TypeVar('T')
@dataclass
class X(Generic[T]):
a: int
def f(self) -> Self:
reveal_type(self) # Self@X[T@X]
assert isinstance(self, DataclassInstance)
reveal_type(self) # X[T@X]
return replace(self, a=1) # Error, can't return X.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment