ruff/crates/ty_python_semantic/src/module_resolver
Aria Desires 45ac30a4d7
[ty] Teach `ty` the meaning of desperation (try ancestor `pyproject.toml`s as search-paths if module resolution fails) (#21745)
## Summary

This makes an importing file a required argument to module resolution,
and if the fast-path cached query fails to resolve the module, take the
slow-path uncached (could be cached if we want)
`desperately_resolve_module` which will walk up from the importing file
until it finds a `pyproject.toml` (arbitrary decision, we could try
every ancestor directory), at which point it takes one last desperate
attempt to use that directory as a search-path. We do not continue
walking up once we've found a `pyproject.toml` (arbitrary decision, we
could keep going up).

Running locally, this fixes every broken-for-workspace-reasons import in
pyx's workspace!

* Fixes https://github.com/astral-sh/ty/issues/1539
* Improves https://github.com/astral-sh/ty/issues/839

## Test Plan

The workspace tests see a huge improvement on most absolute imports.
2025-12-03 15:04:36 -05:00
..
import-resolution-diagram.dot [ty] Update module resolution diagram to account for typeshed `VERSIONS` file 2025-07-30 10:34:58 -04:00
import-resolution-diagram.svg [ty] Update module resolution diagram to account for typeshed `VERSIONS` file 2025-07-30 10:34:58 -04:00
list.rs [ty] Exclude `typing_extensions` from completions unless it's really available 2025-12-01 11:24:16 -05:00
mod.rs [ty] Teach `ty` the meaning of desperation (try ancestor `pyproject.toml`s as search-paths if module resolution fails) (#21745) 2025-12-03 15:04:36 -05:00
module.rs [ty] Enable LRU collection for parsed module (#21749) 2025-12-03 12:16:18 +01:00
path.rs [ty] Teach `ty` the meaning of desperation (try ancestor `pyproject.toml`s as search-paths if module resolution fails) (#21745) 2025-12-03 15:04:36 -05:00
resolver.rs [ty] Teach `ty` the meaning of desperation (try ancestor `pyproject.toml`s as search-paths if module resolution fails) (#21745) 2025-12-03 15:04:36 -05:00
testing.rs [ty] Re-arrange "list modules" implementation for Salsa caching 2025-08-20 10:41:47 -04:00
typeshed.rs [ty] Disallow std::env and io methods in most ty crates (#20046) 2025-08-22 11:13:47 -07:00