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
I believe the following code should be fine, however mypy rejects the case where we're unpacking into the variable which was expanded:
foo: tuple[int, ...] = ()
# Okbar, *quox=foo# Incompatible types in assignment (expression has type "List[int]", variable has type "Tuple[int, ...]") [assignment]bar, *foo=foo
There are a number of similar issues reported, the closest being #9706, however I believe this is distinct as it reproduces when the generic type is int (though my original code was using str). This suggests a different root cause.
Your Environment
Mypy version used: 1.0.1
Mypy command-line flags: none
Mypy configuration options from mypy.ini (and other config files): none
Python version used: 3.10
The text was updated successfully, but these errors were encountered:
I'd say it's not a bug: you really have foo defined as a tuple and assign a list to it later, why should this be allowed? This code passes with --allow-redefinition, as expected.
Oh, huh. For some reason I thought that *foo would capture the values into a tuple not a list.
Happy to close, though I wonder if the error could be clearer about this?
The error position is on the RHS expression, not the LHS assignment, yet in this case the RHS expression has no control over the error and it's the LHS which will need updating to be correct.
Bug Report
I believe the following code should be fine, however mypy rejects the case where we're unpacking into the variable which was expanded:
There are a number of similar issues reported, the closest being #9706, however I believe this is distinct as it reproduces when the generic type is
int
(though my original code was usingstr
). This suggests a different root cause.Your Environment
mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: