Open dpinol opened 4 years ago
The issue here is that an assigning an Any
values does not update the inferred type of messages
. The current behavior is somewhat incorrect, but it increases type checking precision in the common case. We could try out the change on semantics and estimate whether the precision loss is small enough to make this worthwhile.
The second example not generating error seems to be a separate issue.
Sometimes --allow-redefinition
would help (but not in the above examples).
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
:12 error: Statement is unreachable [unreachable] print(messages)
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