-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Complete typing of noxfile.py #9411
Conversation
noxfile.py
Outdated
@@ -34,6 +32,7 @@ | |||
|
|||
|
|||
def run_with_protected_pip(session, *arguments): | |||
# type: (nox.Sessions, *str) -> None |
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.
Typo?
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.
Why does mypy not blow up 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.
Typo?
Yes! Thanks for catching.
Why does mypy not blow up here?
Good question. This is due to using pre-commit and the mypy import configuration.
mypy runs in pre-commit which builds a virtual environment that has only mypy installed. It does not have nox installed. Therefore, nox's types aren't really available for mypy. The nox types are also not available in typeshed.
mypy is configured with:
ignore_missing_imports = True
So, when the import fails, mypy treats the module as Any
and all its attributes (even ones that don't exist) as Any
. I was able to confirm this using reveal_type()
To get around this, I can install third party libraries to the pre-commit virtual environment using the additional_dependencies
option. Unfortunately, this adds yet another place to configure dependencies.
Changes:
wntrblm/nox#376 Removed configuration |
os.chdir() has supported PathLib since Python 3.6. Discovered while adding types pip's noxfile.py: pypa/pip#9411
Fixes errors when running mypy on a project's noxfile.py: noxfile.py:42: error: "ProcessEnv" has no attribute "location" Discovered while adding types pip's noxfile.py: pypa/pip#9411
Allows removing a "mypy: disallow-untyped-defs=False" comment. To workaround a mypy bug, map(os.path.basename, distribution_files) was changed to use a generator expression. See: python/mypy#9864 To verify correct usage of the nox API, it is now a dependency during pre-commit mypy runs. The mypy configuration "follow_imports = silent" allowed erroneous code to pass, so it has been removed. Now, all imports must be available during type.
Thanks! ^.^ |
Allows removing a
mypy: disallow-untyped-defs=False
comment.To workaround a mypy bug,
map(os.path.basename, distribution_files)
was changed to use a generator expression. See:python/mypy#9864