https://pantsbuild.org/ logo
#general
Title
# general
b

brash-student-40401

11/30/2022, 7:45 PM
I need some help getting my first-party type checks working. I have a directory structured like this:
Copy code
src
├── common
│   ├── auth
|       ├── BUILD
|       ├── auth1.py
|       ├── auth2.py
│       └── mypy-stubs
|           ├── BUILD
|           ├── auth1.pyi
│           └── auth2.pyi
├── services
│   ├── app
|       ├── BUILD
│       └── app.py
I want to run type-checking on
app
, which imports `auth1`/`auth2`. When I list dependencies for
auth
, I see the `pyi`s, but I don't see them in dependencies for
app
. I have tried explicitly listing them app's
BUILD
, and they will be listed as dependencies when I do, but the type check still fails with
error: Cannot find implementation or library stub for module named "common.auth.auth1"
(same error for
auth2
). I feel like I've gotten this to work in the past - what am I missing here?
I'll note that both BUILDs in the auth directory only have
python_sources()
defined. The docs say
Copy code
You can use .pyi files for both first-party and third-party code. Include the .pyi files in the sources field for python_source / python_sources and python_test / python_tests targets. MyPy will use these stubs rather than looking at the implementation.
but I cannot find a place to put the `pyi`s where I do not get the missing stub error.
w

wide-midnight-78598

11/30/2022, 7:50 PM
Do you have all your initpys in the right place?
And does mypy know where to look for your stubs?
b

brash-student-40401

11/30/2022, 7:54 PM
1. Which initpys? I have an init in the
auth
and
app
directories, and an
__init__.pyi
in the
mypy-stubs
directory. 2. I'm using mypy through the
./pants check
goal. My understanding is that it will use standard dependency inference to find the stubs, but clearly that is not the case. How else can I get it to find them?
h

happy-kitchen-89482

11/30/2022, 8:25 PM
What are your source roots here?
b

brash-student-40401

11/30/2022, 8:30 PM
Nothing in these directories. I just tried adding
src/common/auth/mypy-stubs/
as a root, but still got the error.
h

happy-kitchen-89482

11/30/2022, 8:35 PM
Dep inference does rely on source roots being set up correctly. Are
auth
and
services
the top-level packages? If so then
src/
should be a source root (and it may already be one, I just want to verify). You can see your source roots with
./pants roots
b

brash-student-40401

11/30/2022, 8:45 PM
Yes,
src/
is a source root
2 Views