-
Notifications
You must be signed in to change notification settings - Fork 287
Open
Copy link
Labels
narrowingIssues with narrowing - root cause is usually narrowing, flow handling, or bothIssues with narrowing - root cause is usually narrowing, flow handling, or bothscoping-control-flowissues related to scoping and control flowissues related to scoping and control flowtypechecking
Description
Describe the Bug
from typing import *
def something_that_might_throw() -> None:
raise Exception()
class Thing():
def something(self) -> None:
pass
def blah() -> None:
x = None
try:
something_that_might_throw()
if x is None:
x = Thing()
except Exception:
raise
finally:
reveal_type(x) # revealed type: Thing, but it could be `None`
x.something()Python: 3.12
Sandbox Link
(Only applicable for extension issues) IDE Information
I'm not sure what the desired behavior is, but clearly we're guessing wrong in this case by taking the refined type from the try.
If we take the original type before the try then it doesn't account for the fact that the try could have succeeded. I thought we created a flow branch at the beginning of the try-block and merging the two branches should have handled this, but something is going wrong.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
narrowingIssues with narrowing - root cause is usually narrowing, flow handling, or bothIssues with narrowing - root cause is usually narrowing, flow handling, or bothscoping-control-flowissues related to scoping and control flowissues related to scoping and control flowtypechecking