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
del followed by an assignment of an "incompatible" type shouldn't probably raise an error #2806
I'm posting this to here because PEP 482--484 didn't seem to mention either "scope" or del and this is probably an implementation detail.
Consider this example:
x=1delxx="a"
Mypy 0.470 raises an error for the above code, saying "Incompatible types in assignment (expression has type "str", variable has type "int")". But, shouldn't it be allowed because the xs before and after del are essentially different variables?
Compare it with
x=1x=Nonex="a"
which clearly is a type error (and mypy judges as such.)
Allowing the 1st pattern will open up the way to conveniently rewrite legacy codes like
# path: # type strpath=path.split(os.pathsep)
# path: # type List[str]
Mypy currently doesn't treat del as deleting a variable -- it rather treats it as deleting the value of a variable. We've discussed similar issues before -- this is basically a special case of #1174, so I'm closing this issue as duplicate. Feel free to add to the discussion in #1174 if you have new thoughts.
Activity
JukkaL commentedon Feb 7, 2017
Mypy currently doesn't treat
delas deleting a variable -- it rather treats it as deleting the value of a variable. We've discussed similar issues before -- this is basically a special case of #1174, so I'm closing this issue as duplicate. Feel free to add to the discussion in #1174 if you have new thoughts.