Mypy not picking up type stubs
# general
m
Mypy not picking up type stubs
Hi, I’ve been migrating our monorepo to support Pants. Currently I am working on converting our existing
mypy
setup. Within the repo we have several venvs managed by poetry. If a package does not include stubs, we add it as a dev dependency, e.g.
Copy code
[tool.poetry.dev-dependencies]
types-ujson = "^5.3.0"
in one of our venv’s
pyproject.toml
file. So far I have not been able to configure pants to pick up these stubs. Initially I thought I would be able to do so by including it in the
BUILD
like this:
Copy code
poetry_requirements(
    ...
    type_stubs_module_mapping={
        "types-ujson": ["some_venv:poetry#ujson"]
    }
}
but this did not help, I get an error
Copy code
foo/bar.py:5: error: Library stubs not installed for "ujson" (or incompatible with Python 3.9)
foo/bar.py:5: note: Hint: "python3 -m pip install types-ujson"
The only way I managed to remove the error is to add something like
["types-ujson==5.3.0"]
to
[mypy].extra_type_stubs
in
pants.toml
. I am not a fan of this approach, because now I have to keep track of this package’s version in both
pyproject.toml
and
pants.toml
. Is there a better way to do this? Thanks!
m
Thanks for the reply Joongi! I’m not sure I can use
python_requirements
as we use poetry for venv. From my understanding
python_requirements
require a
source
field value, eg.
requirements.txt
.
r
m
Oh I think I tried what you are referencing (in the example above), it had not unfortunately worked for me, the stubs are not found