ruff
48a4d9d7 - [ty] remove `static_expression_truthiness` and improve reachability analysis (#22971)

Commit
8 days ago
[ty] remove `static_expression_truthiness` and improve reachability analysis (#22971) ## Summary cf: https://github.com/astral-sh/ruff/pull/19579, https://github.com/astral-sh/ruff/pull/20566#discussion_r2553196955 Currently, we use the query `static_expression_truthiness` to determine the truthiness of an expression. This always determines the truthinesses of non-definitely-bound places as `Ambiguous`, preventing cycles that occur when their reachabilities depend on themselves. However, this can lead to inaccurate analysis of code like the following. ```python def _(flag: bool): if flag: ALWAYS_TRUE_IF_BOUND = True # error: [possibly-unresolved-reference] "Name `ALWAYS_TRUE_IF_BOUND` used when possibly not defined" if ALWAYS_TRUE_IF_BOUND: x = 1 else: x = 2 # If `ALWAYS_TRUE_IF_BOUND` were not defined, an error would occur, and therefore the `x = 2` branch would never be executed. reveal_type(x) # expected: Literal[1], but: Literal[1, 2] ``` Since #20566, we can determine the `Place` by looking at the previous cycle result. Therefore, we can now remove `static_expression_truthiness`, improving reachability analysis of the above code. ## Test Plan mdtest updated
Author
Parents
Loading