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 commented on Feb 7, 2017
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.