This is a fun one: Pants puts all the code's requi...
# general
h
This is a fun one: Pants puts all the code's requirements in the venv when running mypy, which I believe is the correct thing to do. But I'm now adopting Pants in a repo that already runs mypy in a standalone venv that has a bespoke subset of the code's full requirements. So mypy passes quickly in that setup (and they have a few
# type: ignore
to help it along), but fails slowly under Pants (partly because those
# type: ignore
are unneeded)
Yeah, mypy docs say " if you are running your code in a virtualenv, make sure to install and use mypy within the virtualenv"
So Pants is doing the right thing
That repo is not
b
Why does it fail "slowly under Pants" ? Mypy cache, or because
mypy
is doing additional work?
h
AFAICT because mypy is doing a lot more work, analyzing all those requirements
But I will do some timing and nuke the mypy cache to verify
b
I would expect
mypy
to only look at types when required. That's easily measured. Have
mypy
run in a sandbox with a bunch of reqs, but the file is empty. That should be fast. Then do the same thing, but with a file with a bunch of imports all `# type: ignore`d. I would expect that to be fast as well
h
It's faster on a clean run, and much faster on a second run with mypy cache
But even without mypy cache it's considerably faster
AFAICT the only difference is the presence of those other requirements, but I can confirm
After experimenting in a virtualenv entirely outside of Pants, yeah, without those requirements mypy takes 15 seconds and succeeds, with them it takes 60 seconds and fails
b
Thats unexpected.
at least IMHO
h
which is the same as the time that process takes under Pants
🤷‍♂️
b
bad dog
Oh I see. I think my point stands. On an empty file I'd expect perf to be speedy. What we're seeing is
mypy
is parsing types for the imports because they are there, and then after the fact complaining about the
type: ignore
because it does have types
You might be able to configure mypy to "do the wrong thing" in Pants if you care enough: https://mypy.readthedocs.io/en/stable/config_file.html