diff --git a/test-data/unit/check-attr.test b/test-data/unit/check-attr.test index 8c92f8f3a8c1..a0b933bf0bf2 100644 --- a/test-data/unit/check-attr.test +++ b/test-data/unit/check-attr.test @@ -1896,21 +1896,47 @@ c = attr.evolve(c, b=Other()) # E: Argument "b" to "evolve" has incompatible ty c = attr.evolve(c, name=42) # E: Argument "name" to "evolve" has incompatible type "int"; expected "str" c = attr.evolve(c, foobar=42) # E: Unexpected keyword argument "foobar" for "evolve" +# test passing instance as 'inst' kw +c = attr.evolve(inst=c, name='foo') + +# test determining type of first argument's expression from something that's not NameExpr def f() -> C: return c - -# Determining type of first argument's expression c = attr.evolve(f(), name='foo') -# First argument type check +# test 'inst' arg type check attr.evolve(42, name='foo') # E: Argument 1 to "evolve" has incompatible type "Literal[42]?"; expected an attrs class attr.evolve(None, name='foo') # E: Argument 1 to "evolve" has incompatible type "None"; expected an attrs class -# All bets are off for 'Any' +# test that all bets are off for 'Any' any: Any ret = attr.evolve(any, name='foo') reveal_type(ret) # N: Revealed type is "Any" -[builtins fixtures/dict.pyi] +[builtins fixtures/attr.pyi] +[typing fixtures/typing-medium.pyi] + +[case testEvolveVariants] +from typing import Any +import attr +import attrs + + +@attr.s(auto_attribs=True) +class C: + name: str + +c = C(name='foo') + +c = attr.assoc(c, name='test') +c = attr.assoc(c, name=42) # E: Argument "name" to "assoc" has incompatible type "int"; expected "str" + +c = attrs.evolve(c, name='test') +c = attrs.evolve(c, name=42) # E: Argument "name" to "evolve" has incompatible type "int"; expected "str" + +c = attrs.assoc(c, name='test') +c = attrs.assoc(c, name=42) # E: Argument "name" to "assoc" has incompatible type "int"; expected "str" + +[builtins fixtures/attr.pyi] [typing fixtures/typing-medium.pyi]