-
Notifications
You must be signed in to change notification settings - Fork 7.2k
pin python version for mypy checks #5755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
[mypy] | ||
|
||
files = torchvision | ||
python_version = 3.10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type_check_python
job it self runs on Python 3.7 at the moment. Does it make sense to change the version of the job to 3.10 or you think it's totally fine to leave as is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would keep it 3.7 to make sure contributors can develop with >= 3.7 and are not required to have a higher Python version as base.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the docs https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-python-version
This flag will attempt to find a Python executable of the corresponding version to search for PEP 561 compliant packages. If you’d like to disable this, use the --no-site-packages flag (see Import discovery for more details).
Do you know how that works in practice? I wonder how that can actually work if torchvision isn't installed in 3.10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know how that works in practice?
I don't, sorry. What I get from this is that will actually run mypy
with a 3.10 executable if it finds one. In my local setup (and CI as well) it doesn't and so just runs with the regular interpreter. This seems to work out fine.
Note that you posted the docs for the command line option. The docs for the configuration file do not mention this behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I assume that if mypy cannot find a 3.10 executable, it won't be able to properly type check code like that of notusedforsecurity
, unless it comes from a package that is PEP 561 compliant (i.e. it distributes typing stubs)?
I assume that's fine.
But what a F***ing mess :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've asked for clarification. I'll hold the merge until someone got back to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you have a chance to make progress on this @pmeier ? It'd be nice to fix this for those of us who develop on >= 3.8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't get a definitive answer, but all my local tests suggest that the wording is just wrong. Even if you have for example a 3.7 and 3.10 interpreter on path and python_version = 3.10
set, if invoked from the 3.7 interpreter, mypy
will stick with it. Thus, we should be good here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving. But this is the kind of problems we could avoid having.
While thinking about #5942, I realized that pinning For example, as of |
Yes, supporting type annotations adds another layer of dependency issues. |
Right now the only case we have as reference is a BC change: using from typing_extensions import Literal
def np_pad_lt_38(padding_mode: str):
pass
def np_pad_ge_38(padding_mode: Literal["foo", "bar", "baz"]):
pass
padding_mode: Literal["foo", "bar"] = "foo"
np_pad_lt_38(padding_mode)
np_pad_ge_38(padding_mode) This is why our current annotation from #5301 also works on Python 3.7. That being said, I have no idea if projects commit to BC of annotations. IMO the best we can do is too run our workflow on 3.10 to cover all Python versions. At the same time we should still set |
Without this option,
mypy
uses the current interpreter version. This can lead some issues like the one fixed in this PR:hashlib
only got type annotations starting in Python 3.8. Since our CI workflow runs on 3.7, the default behavior ofmypy
is to accept everything in case no annotations are present. Thus, CI was green in #5717 (and for example in my local setup), whereas users running Python >= 3.8 will see an error.With this patch,
mypy
now always uses the most up-to-date annotations of the standard library regardless of the interpreter version.