bazel-contrib / bazel-contrib/rules_mypy
MYPYPATH missing entries for pip deps behind local alias targets
- Dominant language
- Starlark
- Stars
- 12
- Forks
- 13
- PR merge metrics
- No merged PRs in 30d
Description
Pip packages that ship inline types (`py.typed` + `.pyi`) aren't discoverable by mypy when they're accessed through local `py_library` wrappers (the standard `rules_python` pattern for pip aliases).
The type stubs **are** in the sandbox (confirmed via `aquery`), but their directory never makes it onto `MYPYPATH`.
### Why
MYPYPATH construction in `_mypy_impl` decides how to handle a dep based on its label. There are two relevant branches:
- **External deps** (`workspace_root.startswith("external/")`) — correctly adds `external//site-packages` to the path.
- **Local deps** (`workspace_name == ""`) — assumes imports are first-party, strips the first path segment (expecting `_main/...`), and adds the remainder.
A pip alias like `//requirements/pip:whenever` looks local to Bazel (its label lives in the main repo), so it takes the second branch. But its `PyInfo.imports` are inherited from the actual external pip package and look like `rules_python++pip+pip_312_whenever_.../site-packages`. Stripping the first segment turns this into just `site-packages` — a meaningless path. The full path (`external/rules_python++pip+.../site-packages`) is never added.
==> The dep is local, but its imports are external.
Contributor guide
Research direction
Start in the _mypy_impl MYPYPATH construction described in the issue, comparing the external-dependency and local-dependency branches. Use aquery to inspect the local pip alias's PyInfo.imports and verify the sandbox path; done means mypy can discover the package's inline types through that alias.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 62/100