-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
featuretopic-configurationConfiguration files and flagsConfiguration files and flagstopic-reachabilityDetecting unreachable codeDetecting unreachable code
Description
Feature
foo = None
def bar() -> str:
global foo
if foo is not None:
print("Hello")
else:
foo = "bar"
return "lol"
This program type-checks, even though it's obviously wrong. It's not a bug, it's a feature:
- Inferred type of
foo
isNone
, even thoughOptional[str]
was intended. - Because
foo
has typeNone
, theif foo is not None:
part is eliminated as dead code, and therefore the missing return isn't detected. - After setting
foo = "bar"
,reveal_type(foo)
showsstr
. Perhaps the assignment should be an error?
Pitch
A friend submitted a PR like this and thought it was fine.
oakkitten, KotlinIsland and brandonchinn178
Metadata
Metadata
Assignees
Labels
featuretopic-configurationConfiguration files and flagsConfiguration files and flagstopic-reachabilityDetecting unreachable codeDetecting unreachable code