-
Notifications
You must be signed in to change notification settings - Fork 135
Closed
astral-sh/ruff
#18750Milestone
Description
astral-sh/ruff#15676 currently has the following mdtest with incorrect results:
def top_level_return(cond1: bool, cond2: bool):
x = 1
def g():
reveal_type(x) # revealed: Unknown | Literal[1, 2, 3]
if cond1:
if cond2:
x = 2
else:
x = 3
return
def return_from_if(cond1: bool, cond2: bool):
x = 1
def g():
reveal_type(x) # revealed: Unknown | Literal[1]
if cond1:
if cond2:
x = 2
else:
x = 3
return
def return_from_nested_if(cond1: bool, cond2: bool):
x = 1
def g():
reveal_type(x) # revealed: Unknown | Literal[1, 3]
if cond1:
if cond2:
x = 2
return
else:
x = 3We should determine how we want to handle the assignments in this scope.
One possibility (which mimics our current behavior for module-level scopes) would be to reveal Literal[1, 2, 3] for all three. (This would require changes to our terminal statement support: we currently purposefully resolve the x use in the nested function relative to the end of f's scope, but the return statements are preventing some of the bindings from being visible there.)
DetachHead
Metadata
Metadata
Assignees
Labels
No labels