-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugmypy got something wrongmypy got something wrongtopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder
Description
from typing import Any, Final
CONSTANT: Final = 2015
def good(result: dict[str, Any]) -> None:
code = 'asdf'
if isinstance(result, dict):
code = result.get('code', code)
reveal_type(code) # N: Revealed type is "Any"
if code == CONSTANT:
reveal_type(code) # N: Revealed type is "Any"
def bad(result: Any) -> None:
code = 'asdf'
if isinstance(result, dict):
code = result.get('code', code)
reveal_type(code) # N: Revealed type is "builtins.str"
if code == CONSTANT:
reveal_type(code) # N: Revealed type is "builtins.str"
Based on real world code for rotki
This feels a little inconsistent / violating of gradual typing
Not exactly sure what if anything we should do, though
Found this via #20660 which makes --warn-unreachable flag raise a diagnostic on the second comparison
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder