Skip to content

False positive "Statement is unreachable" when variable is untyped #8337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dpinol opened this issue Jan 27, 2020 · 1 comment
Closed

False positive "Statement is unreachable" when variable is untyped #8337

dpinol opened this issue Jan 27, 2020 · 1 comment

Comments

@dpinol
Copy link

dpinol commented Jan 27, 2020

  • Are you reporting a bug, or opening a feature request?
    A bug

  • Please insert below the code you are checking with mypy,

throw = None
for i in range(0, 2):
    if i == 1:
        if throw is None:
            raise Exception(2)
        print("I reached")
    throw = True
  • What is the actual behavior/output?
organization/task/kk.py:6: error: Statement is unreachable  [misc]
  • What is the behavior/output you expect?
    No error, since line 6 is reached when executing the code

  • What are the versions of mypy and Python you are using?
    mypy 0.761 and python 3.7.5.
    Also fails with mypy from Git master?

  • What are the mypy flags you are using? (For example --strict-optional)
    --warn-unreachable

Mypy does not cause false positive when typing the flag "throw"

from typing import Optional

throw: Optional[bool] = None
for i in range(0, 2):
    if i == 1:
        if throw is None:
            raise Exception(2)
        print("I reached")
    throw = True
@Michael0x2a
Copy link
Collaborator

Yeah, this is a pretty annoying limitation -- thanks for the report!

This is currently being tracked in #5423; closing this as a dupe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants