ruff/crates/ty_python_semantic/resources/mdtest/import
David Peter 3a77768f79
[ty] Reachability constraints (#18621)
## Summary



* Completely removes the concept of visibility constraints. Reachability
constraints are now used to model the static visibility of bindings and
declarations. Reachability constraints are *much* easier to reason about
/ work with, since they are applied at the beginning of a branch, and
not applied retroactively. Removing the duplication between visibility
and reachability constraints also leads to major code simplifications
[^1]. For an overview of how the new constraint system works, see the
updated doc comment in `reachability_constraints.rs`.
* Fixes a [control-flow modeling bug
(panic)](https://github.com/astral-sh/ty/issues/365) involving `break`
statements in loops
* Fixes a [bug where](https://github.com/astral-sh/ty/issues/624) where
`elif` branches would have wrong reachability constraints
* Fixes a [bug where](https://github.com/astral-sh/ty/issues/648) code
after infinite loops would not be considered unreachble
* Fixes a panic on the `pywin32` ecosystem project, which we should be
able to move to `good.txt` once this has been merged.
* Removes some false positives in unreachable code because we infer
`Never` more often, due to the fact that reachability constraints now
apply retroactively to *all* active bindings, not just to bindings
inside a branch.
* As one example, this removes the `division-by-zero` diagnostic from
https://github.com/astral-sh/ty/issues/443 because we now infer `Never`
for the divisor.
* Supersedes and includes similar test changes as
https://github.com/astral-sh/ruff/pull/18392


closes https://github.com/astral-sh/ty/issues/365
closes https://github.com/astral-sh/ty/issues/624
closes https://github.com/astral-sh/ty/issues/642
closes https://github.com/astral-sh/ty/issues/648

## Benchmarks

Benchmarks on black, pandas, and sympy showed that this is neither a
performance improvement, nor a regression.

## Test Plan

Regression tests for:
- [x] https://github.com/astral-sh/ty/issues/365
- [x] https://github.com/astral-sh/ty/issues/624
- [x] https://github.com/astral-sh/ty/issues/642
- [x] https://github.com/astral-sh/ty/issues/648

[^1]: I'm afraid this is something that @carljm advocated for since the
beginning, and I'm not sure anymore why we have never seriously tried
this before. So I suggest we do *not* attempt to do a historical deep
dive to find out exactly why this ever became so complicated, and just
enjoy the fact that we eventually arrived here.

---------

Co-authored-by: Carl Meyer <carl@astral.sh>
2025-06-17 09:24:28 +02:00
..
basic.md [ty] Improve diagnostics if the user attempts to import a stdlib module that does not exist on their configured Python version (#18403) 2025-06-02 10:52:26 +00:00
builtins.md Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
case_sensitive.md
conditional.md
conflicts.md
conventions.md [ty] Add support for __all__ (#17856) 2025-05-07 21:42:42 +05:30
cyclic.md [ty] Recognize submodules in self-referential imports (#18005) 2025-05-13 16:59:11 +02:00
dunder_all.md [ty] Understand classes that inherit from subscripted Protocol[] as generic (#17832) 2025-05-09 17:39:15 +01:00
errors.md Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
invalid_syntax.md
namespace.md [ty] Support import <namespace> and from <namespace> import module (#18137) 2025-05-21 07:28:33 +00:00
relative.md Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
site_packages_discovery.md [ty] Improve tests for site-packages discovery (#18374) 2025-05-30 07:32:21 +01:00
star.md [ty] Reachability constraints (#18621) 2025-06-17 09:24:28 +02:00
stub_packages.md [ty] Fix relative imports in stub packages (#18132) 2025-05-16 15:30:10 +02:00
stubs.md
tracking.md Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00