You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Generic type parameters to Argument 1 of attrs.evolve only unify under very specific circumstances (mypy 1.2) #15088
(A clear and concise description of what the bug is.)
To Reproduce
from __future__ importannotationsfromattrsimportevolve, frozenfromtypingimportGeneric, TypeVarT1=TypeVar("T1")
T2=TypeVar("T2")
@frozenclassTest(Generic[T1]):
var: T1# Can't substitute equivalent typevar in method.defupdate(self: Test[T2], var: T2) ->Test[T2]:
returnevolve(self, var=var)
# Can't use *same* typevar in function.defupdate_t1(test: Test[T1], var: T1) ->Test[T1]:
returnevolve(test, var=var)
# Can't use equivalent typevar in function.defupdate_t2(test: Test[T2], var: T2) ->Test[T2]:
returnevolve(test, var=var)
Actual Behavior
test_mypy.py:16: error: Argument 1 to "evolve" of "Test[T2]" has incompatible type "Test[T2]"; expected "Test[T1]" [arg-type]
test_mypy.py:16: error: Argument "var" to "evolve" of "Test[T2]" has incompatible type "T2"; expected "T1" [arg-type]
test_mypy.py:21: error: Argument 1 to "evolve" of "Test[T1]" has incompatible type "Test[T1]"; expected "Test[T1]" [arg-type]
test_mypy.py:21: error: Argument "var" to "evolve" of "Test[T1]" has incompatible type "T1"; expected "T1" [arg-type]
test_mypy.py:26: error: Argument 1 to "evolve" of "Test[T2]" has incompatible type "Test[T2]"; expected "Test[T1]" [arg-type]
test_mypy.py:26: error: Argument "var" to "evolve" of "Test[T2]" has incompatible type "T2"; expected "T1" [arg-type]
Found 6 errors in 1 file (checked 1 source file)
This gets worse when using constrained typevars, because the typevar on the function/method gets expanded to every constraint, but the typevar on the class isn't expanded, so it only accepts the typevar, even though it's passing the concrete type.
Your Environment
Mypy version used: mypy 1.2.0 (compiled: yes) (passes with mypy 1.1.1 (compiled: yes))
Mypy command-line flags:
Mypy configuration options from mypy.ini (and other config files): (these approximate some past version of --strict, and a bunch of project-specific stuff that shouldn't be relevant)
Activity
ikonst commentedon Apr 20, 2023
Should be addressed in #15050 (tested, no errors)
attrs.evolve: support generics and unions (#15050)
mwchase commentedon Apr 24, 2023
Confirmed against my codebase. With master, it just has the errors that got newly raised starting in version 1.