-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
bugmypy got something wrongmypy got something wrongfalse-positivemypy gave an error on correct codemypy gave an error on correct codepriority-1-normaltopic-reachabilityDetecting unreachable codeDetecting unreachable code
Description
- Are you reporting a bug, or opening a feature request?
A bug - Please insert below the code you are checking with mypy,
from typing import Any
def get_any() -> Any:
return {}
def fun(message_json) -> int:
messages = [get_any()]
messages = get_any()
if not isinstance(messages, list):
print(messages)
return 2
- What is the actual behavior/output?
:12 error: Statement is unreachable [unreachable]
print(messages)
- What is the behavior/output you expect?
I would expect one the following:
a) Either I get an error because "messages" is reassigned to Any afetr it was a list in the previous line
b) Or I don't get the "unreachable" error because before the "if", "messages" can indeed not be a list
Curiously with the code below, I don't get any error
from typing import Any
def get_any() -> Any:
return {}
def fun(message_json) -> int:
messages = [3] # <=== only this line changes
messages = get_any()
if not isinstance(messages, list):
print(messages)
return 2
-
What are the versions of mypy and Python you are using?
0.770 (with 0.761 I got the same error message but with "misc" code) -
What are the mypy flags you are using? (For example --strict-optional)
--show-error-codes --warn-unreachable
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongfalse-positivemypy gave an error on correct codemypy gave an error on correct codepriority-1-normaltopic-reachabilityDetecting unreachable codeDetecting unreachable code