Skip to content

Commit cf756d1

Browse files
committed
improve tests
1 parent 5148e5f commit cf756d1

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

test-data/unit/check-attr.test

+31-5
Original file line numberDiff line numberDiff line change
@@ -1896,21 +1896,47 @@ c = attr.evolve(c, b=Other()) # E: Argument "b" to "evolve" has incompatible ty
18961896
c = attr.evolve(c, name=42) # E: Argument "name" to "evolve" has incompatible type "int"; expected "str"
18971897
c = attr.evolve(c, foobar=42) # E: Unexpected keyword argument "foobar" for "evolve"
18981898

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
18991903
def f() -> C:
19001904
return c
19011905

1902-
1903-
# Determining type of first argument's expression
19041906
c = attr.evolve(f(), name='foo')
19051907

1906-
# First argument type check
1908+
# test 'inst' arg type check
19071909
attr.evolve(42, name='foo') # E: Argument 1 to "evolve" has incompatible type "Literal[42]?"; expected an attrs class
19081910
attr.evolve(None, name='foo') # E: Argument 1 to "evolve" has incompatible type "None"; expected an attrs class
19091911

1910-
# All bets are off for 'Any'
1912+
# test that all bets are off for 'Any'
19111913
any: Any
19121914
ret = attr.evolve(any, name='foo')
19131915
reveal_type(ret) # N: Revealed type is "Any"
19141916

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]
19161942
[typing fixtures/typing-medium.pyi]

0 commit comments

Comments
 (0)