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

ambitious-actor-36781

11/14/2021, 9:32 PM
I'm going through and adding
mypy
to my project. But continuously getting this error:
Copy code
š„‚ MyPy failed.
10:29:21.85 [ERROR] Completed: Typecheck using MyPy - MyPy failed (exit code 2).
test/python/gcloud/conftest.py: error: Duplicate module named "conftest" (also at "test/python/editor/score/conftest.py")
test/python/gcloud/conftest.py: note: Are you missing an __init__.py? Alternatively, consider using --exclude to avoid checking one of them.
Found 1 error in 1 file (errors prevented further checking)
So now (due to: https://github.com/pantsbuild/pants/issues/13615) I'm adding
overrides={"conftest.py": {"skip_mypy": True}}
to all my
python_test_utils
but it feels like I'm doing something wrong?
c

curved-television-6568

11/14/2021, 9:43 PM
Yeah, I think it would make sense to register the skip fields also for the
python_test_utils
test target. Working on a PR for that..
h

hundreds-father-404

11/14/2021, 9:45 PM
Hm what does
./pants roots
say? And thank you Andreas!! Definitely an oversight, I agree it should be registered
a

ambitious-actor-36781

11/14/2021, 9:46 PM
Copy code
ā•°ā”€āž¤  ./pants roots
10:46:13.06 [INFO] Initializing scheduler...
10:46:13.13 [INFO] Scheduler initialized.
build-support
pants-plugins
src/python
test/python
h

hundreds-father-404

11/14/2021, 9:48 PM
Hmmm I would not expect MyPy to see then those two conftest.py as duplicates. Toolchain's repo has the same source roots as you, and a conftest.py per dir, and we don't see this issue. So it should be solvable! Are you using
__init__.py
files or relying on PEP 440 420?
a

ambitious-actor-36781

11/14/2021, 9:49 PM
Copy code
test/python $  git ls-files | grep "\(__init__.py\|conftest.py\)"
editor/conftest.py
editor/score/conftest.py
editor/score/content_score_data/__init__.py
editor/integrations/conftest.py
i_admin/conftest.py
i_caching/conftest.py
i_gcloud/conftest.py
msglib/conftest.py
rest_api/conftest.py
sauth/conftest.py
s_app/conftest.py
s_app/s_app_test_package/__init__.py
but my
src/python
has a lot of
___init___
files
h

hundreds-father-404

11/14/2021, 9:53 PM
I suspect you will need an init.py in each of those directories. We need it for Toolchain to work properly That's what MyPy's hint is getting at
maybeee it will be enough to have one at the root of
tests/python
tho!
a

ambitious-actor-36781

11/14/2021, 9:55 PM
šŸ‘Œ I'll have a crack at that in a bit. Thanks for the help.
ā¤ļø 1
h

hundreds-father-404

11/14/2021, 9:57 PM
thank you for the bug report!
a

ambitious-actor-36781

11/15/2021, 2:43 AM
adding
__init__.py
files to test folders worked. But broke other things. so just gonna skip mypy on everything in
tests
can't seem to get stubs for
gunicorn.app.wsgiapp
working tho. Stubs folder work, i can add
import fake_module
and w/
src/mypy-stubs/fake_module.pyi
mypy doesn't even mention it.
Copy code
./pants dependencies src/python/infloai/util/django/service.py
3rdparty:django
3rdparty:gunicorn
src/mypy-stubs/gunicorn/app/wsgiapp.pyi:../../lib
src/python/infloai/util/django/gunicorn_conf.py
src/python/infloai/util/django/wsgi.py
Suspect it's something to do with the
__init__.pyi
files not being picked up?
Copy code
find src/mypy-stubs 
src/mypy-stubs
src/mypy-stubs/BUILD
src/mypy-stubs/gunicorn
src/mypy-stubs/gunicorn/app
src/mypy-stubs/gunicorn/app/wsgiapp.pyi
src/mypy-stubs/gunicorn/app/__init__.pyi
src/mypy-stubs/gunicorn/__init__.pyi
h

hundreds-father-404

11/15/2021, 4:34 PM
oh hmmm what happens if you change those to
__init__.py
? That very well could be Also are those empty?
a

ambitious-actor-36781

11/16/2021, 1:46 AM
yeah, they're empty
h

hundreds-father-404

11/16/2021, 2:14 AM
I checked our integration test and we're using
__init__.py
rather than
.pyi
. Are you able to use that? Fwict there's no difference?
a

ambitious-actor-36781

11/17/2021, 1:11 AM
changing those
__init__.pyi
files to
.py
didn't change anything, still getting
Copy code
14:05:31.26 [ERROR] Completed: Typecheck using MyPy - MyPy failed (exit code 1).
src/python/infloai/util/django/service.py:30: error: Skipping analyzing "gunicorn.app.wsgiapp": found module but no type hints or library stubs
src/python/util/django/service.py:30: note: See <https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports>
if I stick
import foobar
in a file and then make a
src/mypy-stubs/foobar.pyi
it works
šŸ‘€ 1
h

hundreds-father-404

11/17/2021, 1:30 AM
hmmm any idea what is different here?
a

ambitious-actor-36781

11/17/2021, 1:31 AM
one's a top-level package, the other's not? Found some other libs with no type hints, will try make that work
šŸ‘ 1
hm,
src/mypy-stubs/docker/_init_.pyi
seems to work šŸ¤·ā€ā™‚ļø might just
# type: ignore
that one gunicorn import
ohhh. weird
šŸ‘€ 1
h

hundreds-father-404

11/17/2021, 1:35 AM
The top-level package shouldn't make a difference I think. Pants's dep inference rules are basically, for an import
foo.bar.baz
, look up: ā€¢ Is there a first-party module called
foo.bar.baz
or
foo.bar
. Where we allow a parent module to accommodate imports like
from foo.bar import Baz
ā€¢ Is there a third-party module that exposes any of those modules, like
foo.bar.baz
,
foo.bar
, or
foo
? If both first-party and third-party, only allow first-party if it is exactly one type stub. Else, ambiguity
a

ambitious-actor-36781

11/17/2021, 1:35 AM
---
---
ok, so the stubs i've created for
docker
docker.errors
and
docker.models.images
all work
šŸ‘ 1
so I've probably done something dumb on the gunicorn one
would be so much nicer if mypy just let you create
docker.models.images.pyi
8 Views