Support including .pyi alongside .py files (eg. foo/bar.py and foo/bar.pyi)
Closed this issue · 3 comments
In MyPy if you have a .py
and .pyi
file in the same folder with the same name then MyPy says that the .pyi
should take precedence and the .py
is ignored completely during type-checking.
In a branch, https://github.com/thundergolfer/bazel-mypy-integration/tree/jonathon/supporting-pyi-files, I was passing in both to the --cache-map
and it was throwing out the error:
mypy_stubs/parse_name.pyi: error: Duplicate module named 'mypy_stubs.parse_name' (also at 'mypy_stubs/parse_name.py')
If could in my Starlark code check for this case and then ignore the .py
, but for now I think I just won't support those kinds of .pyi
files.
Open issue about this: python/mypy#3505
Now supported.
In my case, it still complains that there are 2 modules with the same name (.py
and .pyi
). I have a py_library
target that depends on a mypy_stubs
target, both files (e.g. x.py
and x.pyi
) in the same directory (stubs are not separate). I am using version 0.0.7. After some very short debugging I found in the template {SRCS} contains both .py
and .pyi
files.
Any ideas?
I think this might be a regression. So you have this?
load("@my_deps//:requirements.bzl", "requirement")
load("@mypy_integration//:rules.bzl", "mypy_stubs")
mypy_stubs(
name = "stubs",
srcs = glob(["*.pyi"]),
)
py_binary(
name = "foo",
srcs = glob(["*.py"]),
main = "foo.py",
python_version = "PY3",
deps = [
":stubs",
requirement("requests"),
],
)