bazel-contrib / bazel-contrib/rules_mypy

How to add stubs

Open
#86 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Starlark
Stars
12
Forks
13
PR merge metrics
No merged PRs in 30d

Description

In bazel-mypy-integration, you were able to specify `mypy_stub` targets to add stubs for third party libraries that dont have type hints. Now that bazel-mypy-integration is deprecated in favor of rules_mypy, how would we do the same here?

---

EDIT: I now see `py_library` has `pyi_srcs`, so I could add stubs as a normal `py_library` target. However, it seems like the third party dep appears in MYPYPATH before py_library deps, so the third party dep is found first.

I have a temporary workaround where I do
```starlark
stubs = {
requirement("foo"): "@@//stubs:foo",
}

mypy_aspect = mypy(
types = types | stubs,
)
```
which seems to work, but seems hacky

Contributor guide

Open the contributing guide

Research direction

Start with the rules_mypy mypy() entry point and the types mapping, then compare the deprecated bazel-mypy-integration behavior with py_library's pyi_srcs and dependency handling. The issue mentions a stubs mapping workaround; done would mean establishing a supported way for local stubs to take precedence over third-party dependencies.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.