Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ikonst committed Jan 27, 2023
1 parent 5148e5f commit cf756d1
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions test-data/unit/check-attr.test
Original file line number Diff line number Diff line change
Expand Up @@ -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]

0 comments on commit cf756d1

Please sign in to comment.