ruff/crates/ty_python_semantic/resources/mdtest/narrow
David Peter db3dcd8ad6
[ty] Eagerly simplify 'True' and 'False' constraints (#18998)
## Summary

Simplifies literal `True` and `False` conditions to `ALWAYS_TRUE` /
`ALWAYS_FALSE` during semantic index building. This allows us to eagerly
evaluate more constraints, which should help with performance (looks
like there is a tiny 1% improvement in instrumented benchmarks), but
also allows us to eliminate definitely-unreachable branches in
control-flow merging. This can lead to better type inference in some
cases because it allows us to retain narrowing constraints without
solving https://github.com/astral-sh/ty/issues/690 first:
```py
def _(c: int | None):
    if c is None:
        assert False
    
    reveal_type(c)  # int, previously: int | None
```

closes https://github.com/astral-sh/ty/issues/713

## Test Plan

* Regression test for https://github.com/astral-sh/ty/issues/713
* Made sure that all ecosystem diffs trace back to removed false
positives
2025-06-30 13:11:52 +02:00
..
conditionals [ty] Type narrowing in comprehensions (#18934) 2025-06-25 11:30:28 +02:00
assert.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
assignment.md [ty] basic narrowing on attribute and subscript expressions (#17643) 2025-06-17 11:07:46 +02:00
bool-call.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
boolean.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
complex_target.md [ty] Homogeneous and mixed tuples (#18600) 2025-06-20 18:23:54 -04:00
hasattr.md [ty] Improve protocol member type checking and relation handling (#18847) 2025-06-29 10:46:33 +00:00
isinstance.md [ty] Support narrowing on isinstance()/issubclass() if the second argument is a dynamic, intersection, union or typevar type (#18900) 2025-06-24 10:55:26 +00:00
issubclass.md [ty] Support narrowing on isinstance()/issubclass() if the second argument is a dynamic, intersection, union or typevar type (#18900) 2025-06-24 10:55:26 +00:00
match.md [ty] Improve disjointness inference for NominalInstanceTypes and SubclassOfTypes (#18864) 2025-06-24 20:27:37 +00:00
post_if_statement.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
truthiness.md [ty] Reachability constraints (#18621) 2025-06-17 09:24:28 +02:00
type.md [ty] Surface matched overload diagnostic directly (#18452) 2025-06-20 08:36:49 +05:30
type_guards.md [ty] Improve disjointness inference for NominalInstanceTypes and SubclassOfTypes (#18864) 2025-06-24 20:27:37 +00:00
while.md [ty] Eagerly simplify 'True' and 'False' constraints (#18998) 2025-06-30 13:11:52 +02:00