Skip to content

Feature request: Catch operations on nothingness #12511

Closed
@LuminairPrime

Description

@LuminairPrime

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?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions