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
Below are four examples of impossible code that operates on nothing. The latter two continue silently, throwing no errors. Cpython says it's out of the scope of the language, but mypy could catch it. (https://bugs.python.org/issue47202)
x =
for x in : print("This code is never reached")
while(None): print("This code is never reached")
emptylist: list[int] = []
for x in emptylist:
if emptylist[x] == "This code is never reached":
print("This code is never reached")
else: print("This code is never reached")
I think the second two cases should throw a warning that they aren't doing anything and attached code will be thrown away. What do you think?
The text was updated successfully, but these errors were encountered:
The while(None) case is already caught by the --warn-unreachable option.
Iterating over an empty list isn't. Implementing this check would require significant work, because mypy doesn't currently track whether a list is always empty. It seems doable at least in simple cases like your example, but I'm not sure how valuable it is, since I don't think it's a common problem in real-world code.
I agree that checking for iteration over nothing would be a good feature in the future. I have nothing else to add because I can't build the feature ;)
Below are four examples of impossible code that operates on nothing. The latter two continue silently, throwing no errors. Cpython says it's out of the scope of the language, but mypy could catch it. (https://bugs.python.org/issue47202)
x =
for x in : print("This code is never reached")
while(None): print("This code is never reached")
I think the second two cases should throw a warning that they aren't doing anything and attached code will be thrown away. What do you think?
The text was updated successfully, but these errors were encountered: