Describe the Bug
Summary
from typing import reveal_type
var = int(33)
my_list = [var:=str("some_str") for _ in [123]]
print(var) # "some_str"
reveal_type(var) # expected int|str, but got int
Names defined by walrus operators in child comprehension scope don't accumulate. Hence, pyrefly infers the wrong type.
Here it is skipping expressions which define a comprehension scope. We should consider adding names from inner comprehension scopes to the definition.
Version
Pyrefly 0.28.0
Sandbox Link
https://pyrefly.org/sandbox/?code=GYJw9gtgBALgngBwJYDsDmUkQWEMogCmAboQIYA2A%2BvAoQFDFkhQC8mKMAFAMw8CU9CHCoUkAZ3zsA2kxAAuVpJBcAROMiEqy1fyjBcUKhyjSAjACYeAXWv0EIVNzl6AxFHWbtMEKvpFSShpEQi4XKHdCAA86AGMYQgATDhgAH2UAGigAIwBXfDQwfCcgA&version=3.14
(Only applicable for extension issues) IDE Information
No response
Describe the Bug
Summary
Names defined by walrus operators in child comprehension scope don't accumulate. Hence, pyrefly infers the wrong type.
Here it is skipping expressions which define a comprehension scope. We should consider adding names from inner comprehension scopes to the definition.
Version
Pyrefly 0.28.0
Sandbox Link
https://pyrefly.org/sandbox/?code=GYJw9gtgBALgngBwJYDsDmUkQWEMogCmAboQIYA2A%2BvAoQFDFkhQC8mKMAFAMw8CU9CHCoUkAZ3zsA2kxAAuVpJBcAROMiEqy1fyjBcUKhyjSAjACYeAXWv0EIVNzl6AxFHWbtMEKvpFSShpEQi4XKHdCAA86AGMYQgATDhgAH2UAGigAIwBXfDQwfCcgA&version=3.14
(Only applicable for extension issues) IDE Information
No response