@@ -1970,47 +1970,19 @@ reveal_type(ret) # N: Revealed type is "Any"
19701970
19711971[typing fixtures/typing-medium.pyi]
19721972
1973- [case testEvolveGeneric]
1974- import attrs
1975- from typing import Generic, TypeVar
1976-
1977- T = TypeVar('T')
1978-
1979- @attrs.define
1980- class A(Generic[T]):
1981- x: T
1982-
1983-
1984- a = A(x=42)
1985- reveal_type(a) # N: Revealed type is "__main__.A[builtins.int]"
1986- a2 = attrs.evolve(a, x=42)
1987- reveal_type(a2) # N: Revealed type is "__main__.A[builtins.int]"
1988- a2 = attrs.evolve(a, x='42') # E: Argument "x" to "evolve" of "A[int]" has incompatible type "str"; expected "int"
1989- reveal_type(a2) # N: Revealed type is "__main__.A[builtins.int]"
1990-
1991- [builtins fixtures/attr.pyi]
1992- [typing fixtures/typing-medium.pyi]
1993-
1994- [case testEvolveTypeVarWithAttrsUpperBound]
1973+ [case testEvolveTypeVarBound]
19951974import attrs
19961975from typing import TypeVar
19971976
1998-
19991977@attrs.define
20001978class A:
20011979 x: int
20021980
2003-
20041981@attrs.define
20051982class B(A):
20061983 pass
20071984
2008-
20091985TA = TypeVar('TA', bound=A)
2010- TInt = TypeVar('TInt', bound=int)
2011- TAny = TypeVar('TAny')
2012- TNone = TypeVar('TNone', bound=None)
2013-
20141986
20151987def f(t: TA) -> TA:
20161988 t2 = attrs.evolve(t, x=42)
@@ -2021,58 +1993,41 @@ def f(t: TA) -> TA:
20211993f(A(x=42))
20221994f(B(x=42))
20231995
2024- def g(t: TInt) -> None:
2025- _ = attrs.evolve(t, x=42) # E: Argument 1 to "evolve" has a variable type "TInt" not bound to an attrs class
2026-
2027- def h(t: TAny) -> None:
2028- _ = attrs.evolve(t, x=42) # E: Argument 1 to "evolve" has a variable type "TAny" not bound to an attrs class
2029-
2030- def q(t: TNone) -> None:
2031- _ = attrs.evolve(t, x=42) # E: Argument 1 to "evolve" has a variable type "TNone" not bound to an attrs class
2032-
20331996[builtins fixtures/attr.pyi]
2034- [typing fixtures/typing-medium.pyi]
20351997
2036- [case testEvolveTypeVarWithAttrsGenericUpperBound ]
1998+ [case testEvolveTypeVarBoundNonAttrs ]
20371999import attrs
2038- from typing import Generic, TypeVar
2039-
2040- Q = TypeVar('Q', bound=str)
2041-
2042- @attrs.define
2043- class A(Generic[Q]):
2044- x: Q
2045-
2000+ from typing import TypeVar
20462001
2047- T = TypeVar('T', bound=A[str])
2002+ TInt = TypeVar('TInt', bound=int)
2003+ TAny = TypeVar('TAny')
2004+ TNone = TypeVar('TNone', bound=None)
20482005
2006+ def f(t: TInt) -> None:
2007+ _ = attrs.evolve(t, x=42) # E: Argument 1 to "evolve" has a variable type "TInt" not bound to an attrs class
20492008
2050- def f(t: T) -> T:
2051- t = attrs.evolve(t, x=42) # E: Argument "x" to "evolve" of "T" has incompatible type "int"; expected "str"
2052- return t
2009+ def g(t: TAny) -> None:
2010+ _ = attrs.evolve(t, x=42) # E: Argument 1 to "evolve" has a variable type "TAny" not bound to an attrs class
20532011
2054- f(A(x='42'))
2012+ def h(t: TNone) -> None:
2013+ _ = attrs.evolve(t, x=42) # E: Argument 1 to "evolve" has a variable type "TNone" not bound to an attrs class
20552014
20562015[builtins fixtures/attr.pyi]
2057- [typing fixtures/typing-medium.pyi]
20582016
2059- [case testEvolveTypeVarWithAttrsValueRestrictions ]
2017+ [case testEvolveTypeVarConstrained ]
20602018import attrs
20612019from typing import TypeVar
20622020
20632021@attrs.define
20642022class A:
20652023 x: int
20662024
2067-
20682025@attrs.define
20692026class B:
20702027 x: str # conflicting with A.x
20712028
2072-
20732029T = TypeVar('T', A, B)
20742030
2075-
20762031def f(t: T) -> T:
20772032 t2 = attrs.evolve(t, x=42) # E: Argument "x" to "evolve" of "B" has incompatible type "int"; expected "str"
20782033 reveal_type(t2) # N: Revealed type is "__main__.A" # N: Revealed type is "__main__.B"
@@ -2083,7 +2038,6 @@ f(A(x=42))
20832038f(B(x='42'))
20842039
20852040[builtins fixtures/attr.pyi]
2086- [typing fixtures/typing-medium.pyi]
20872041
20882042[case testEvolveVariants]
20892043from typing import Any
0 commit comments