@@ -1970,47 +1970,19 @@ reveal_type(ret) # N: Revealed type is "Any"
1970
1970
1971
1971
[typing fixtures/typing-medium.pyi]
1972
1972
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]
1995
1974
import attrs
1996
1975
from typing import TypeVar
1997
1976
1998
-
1999
1977
@attrs.define
2000
1978
class A:
2001
1979
x: int
2002
1980
2003
-
2004
1981
@attrs.define
2005
1982
class B(A):
2006
1983
pass
2007
1984
2008
-
2009
1985
TA = TypeVar('TA', bound=A)
2010
- TInt = TypeVar('TInt', bound=int)
2011
- TAny = TypeVar('TAny')
2012
- TNone = TypeVar('TNone', bound=None)
2013
-
2014
1986
2015
1987
def f(t: TA) -> TA:
2016
1988
t2 = attrs
10000
.evolve(t, x=42)
@@ -2021,58 +1993,41 @@ def f(t: TA) -> TA:
2021
1993
f(A(x=42))
2022
1994
f(B(x=42))
2023
1995
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
-
2033
1996
[builtins fixtures/attr.pyi]
2034
- [typing fixtures/typing-medium.pyi]
2035
1997
2036
- [case testEvolveTypeVarWithAttrsGenericUpperBound ]
1998
+ [case testEvolveTypeVarBoundNonAttrs ]
2037
1999
import 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
2046
2001
2047
- T = TypeVar('T', bound=A[str])
2002
+ TInt = TypeVar('TInt', bound=int)
2003
+ TAny = TypeVar('TAny')
2004
+ TNone = TypeVar('TNone', bound=None)
2048
2005
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
2049
2008
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
2053
2011
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
2055
2014
2056
2015
[builtins fixtures/attr.pyi]
2057
- [typing fixtures/typing-medium.pyi]
2058
2016
2059
- [case testEvolveTypeVarWithAttrsValueRestrictions ]
2017
+ [case testEvolveTypeVarConstrained ]
2060
2018
import attrs
2061
2019
from typing import TypeVar
2062
2020
2063
2021
@attrs.define
2064
2022
class A:
2065
2023
x: int
2066
2024
2067
-
2068
2025
@attrs.define
2069
2026
class B:
2070
2027
x: str # conflicting with A.x
2071
2028
2072
-
2073
2029
T = TypeVar('T', A, B)
2074
2030
2075
-
2076
2031
def f(t: T) -> T:
2077
2032
t2 = attrs.evolve(t, x=42) # E: Argument "x" to "evolve" of "B" has incompatible type "int"; expected "str"
2078
2033
reveal_type(t2) # N: Revealed type is "__main__.A" # N: Revealed type is "__main__.B"
@@ -2083,7 +2038,6 @@ f(A(x=42))
2083
2038
f(B(x='42'))
2084
2039
2085
2040
[builtins fixtures/attr.pyi]
2086
- [typing fixtures/typing-medium.pyi]
2087
2041
2088
2042
[case testEvolveVariants]
2089
2043
from typing import Any
0 commit comments