mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 04:45:01 +00:00
![]() ## Summary Adds more precise type inference for `… is …` and `… is not …` identity checks in some limited cases where we statically know the answer to be either `Literal[True]` or `Literal[False]`. I found this helpful while working on type inference for comparisons involving intersection types, but I'm not sure if this is at all useful for real world code (where the answer is most probably *not* statically known). Note that we already have *type narrowing* for identity tests. So while we are already able to generate constraints for things like `if x is None`, we can now — in some limited cases — make an even stronger conclusion and infer that the test expression itself is `Literal[False]` (branch never taken) or `Literal[True]` (branch always taken). ## Test Plan New Markdown tests |
||
---|---|---|
.. | ||
resources | ||
src | ||
tests | ||
build.rs | ||
Cargo.toml |