Closed
Description
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?