ruff
ruff copied to clipboard
[red-knot] PEP 561 compliant module resolver
(Or intentional choices to diverge from PEP 561 compliance.)
Subtasks:
- [x] Vendor typeshed's stubs: https://github.com/astral-sh/ruff/pull/11340
- [x] Add automation for keeping typeshed's stubs up to date: https://github.com/astral-sh/ruff/pull/11427
- [x] Implement
--custom-typeshed-dirinternally: https://github.com/astral-sh/ruff/pull/11767 - [x] Implement the typing spec's module resolution order:
- https://github.com/astral-sh/ruff/pull/11767
- Proposal for tweaking the spec posted at https://discuss.python.org/t/pep-561-s-module-resolution-order-seems-incorrect/55048/1
- [x] Make vendored typeshed stubs available from the built Ruff binary: https://github.com/astral-sh/ruff/pull/11779
- [ ] Use vendored typeshed stubs at runtime to resolve symbols to stdlib definitions if
--custom-typeshed-diris not passed- [x] Add a
VendoredFileSystemimplementation: https://github.com/astral-sh/ruff/pull/11863 - [ ] Use the
VendoredFileSystemimplementation to resolve stdlib stubs: #12224
- [x] Add a
- [ ] Add support for stubs packages suffixed with
-stubsinstalled intosite-packages(must take priority over other packages installed intosite-packages) - [x] Add support for typeshed's
VERSIONSfile: we shouldn't fallback to a typeshed module if theVERSIONSfile specifies it does not exist with the--target-versionthe user passes.- [x] Add a parser for
VERSIONS: https://github.com/astral-sh/ruff/pull/11836 - [x] Use the
VERSIONSfile when resolving stdlib modules: https://github.com/astral-sh/ruff/pull/12141
- [x] Add a parser for
- [ ] Audit mypy's and pyright's module resolvers to see if there's anything that's not in the spec that still needs to be implemented
One thing that we need to implement as part of this is a vendored filesystem. It's not a functionality but a task to complete on our way to get there.
One thing that we need to implement as part of this is a vendored filesystem. It's not a functionality but a task to complete on our way to get there.
Right. I was considering that part of
Use vendored typeshed stubs at runtime to resolve symbols to stdlib definitions if --custom-typeshed-dir is not passed
since, as you say, it's necessary to implement a vendored filesystem in order to be able to do that
@AlexWaygood is there more work that needs doing or can we consider this done?
We can't call ourself PEP-561-compliant until we do this, which is still outstanding, and important. It's not huge, but also not trivial:
* [ ] Add support for stubs packages suffixed with `-stubs` installed into `site-packages
But we decided to defer work on it for now because the type-inference work is more important.
We should also add support for py.typed files that explicitly mark type annotations as partial, which is specified by the PEP but not listed in the tasks above; I'll add that now.
Finer-grained issues are easier to manage for prioritizing and tracking work to be done, so I've created https://github.com/astral-sh/ruff/issues/16612 and https://github.com/astral-sh/ty/issues/184 for the last two items here.
I don't think "audit mypy and pyright resolvers" is likely worth the trouble, it will be more efficient to discover issues from encountering them in the wild. If someone disagrees, feel free to create an issue for it! (Or just do it and create issues for anything observed.)