@@ -1896,21 +1896,47 @@ c = attr.evolve(c, b=Other()) # E: Argument "b" to "evolve" has incompatible ty
1896
1896
c = attr.evolve(c, name=42) # E: Argument "name" to "evolve" has incompatible type "int"; expected "str"
1897
1897
c = attr.evolve(c, foobar=42) # E: Unexpected keyword argument "foobar" for "evolve"
1898
1898
1899
+ # test passing instance as 'inst' kw
1900
+ c = attr.evolve(inst=c, name='foo')
1901
+
1902
+ # test determining type of first argument's expression from something that's not NameExpr
1899
1903
def f() -> C:
1900
1904
return c
1901
1905
1902
-
1903
- # Determining type of first argument's expression
1904
1906
c = attr.evolve(f(), name='foo')
1905
1907
1906
- # First argument type check
1908
+ # test 'inst' arg type check
1907
1909
attr.evolve(42, name='foo') # E: Argument 1 to "evolve" has incompatible type "Literal[42]?"; expected an attrs class
1908
1910
attr.evolve(None, name='foo') # E: Argument 1 to "evolve" has incompatible type "None"; expected an attrs class
1909
1911
1910
- # All bets are off for 'Any'
1912
+ # test that all bets are off for 'Any'
1911
1913
any: Any
1912
1914
ret = attr.evolve(any, name='foo')
1913
1915
reveal_type(ret) # N: Revealed type is "Any"
1914
1916
1915
- [builtins fixtures/dict.pyi]
1917
+ [builtins fixtures/attr.pyi]
1918
+ [typing fixtures/typing-medium.pyi]
1919
+
1920
+ [case testEvolveVariants]
1921
+ from typing import Any
1922
+ import attr
1923
+ import attrs
1924
+
1925
+
1926
+ @attr.s(auto_attribs=True)
1927
+ class C:
1928
+ name: str
1929
+
1930
+ c = C(name='foo')
1931
+
1932
+ c = attr.assoc(c, name='test')
1933
+ c = attr.assoc(c, name=42) # E: Argument "name" to "assoc" has incompatible type "int"; expected "str"
1934
+
1935
+ c = attrs.evolve(c, name='test')
1936
+ c = attrs.evolve(c, name=42) # E: Argument "name" to "evolve" has incompatible type "int"; expected "str"
1937
+
1938
+ c = attrs.assoc(c, name='test')
1939
+ c = attrs.assoc(c, name=42) # E: Argument "name" to "assoc" has incompatible type "int"; expected "str"
1940
+
1941
+ [builtins fixtures/attr.pyi]
1916
1942
[typing fixtures/typing-medium.pyi]
0 commit comments