Skip to content
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

[mypy] explicitly exclude files instead of ignoring errors by modules #12199

Merged
merged 7 commits into from
Mar 28, 2024

Conversation

picnixz
Copy link
Member

@picnixz picnixz commented Mar 25, 2024

After merging #12173, I suggest we change the [[tool.mypy.overrides]] into a true exclusion list.

The rationale is that, with ignore-errors, if you mypy the file without removing the module from the overrides list, you will not do anything. However, if you mypy the file and that file is excluded by default, mypy runs normally.

@jayaddison
Copy link
Contributor

To check my understanding of this:

Before

  • Exclude three directories (tests/roots, ...) during mypy typechecking.
  • For a large set of modules, override and set ignore_errors to true (check them, but don't report any problems).
  • When checking an individual file (mypy <path/to/module.py), the overrides were ignored, so errors would be reported.

After

  • Exclude three directories (tests/roots, ...) as before.
  • Additionally exclude a series of fixed file paths.

And a question:

Will we forget to update the paths if we move files around? (equally could happen for module names; are inconsistencies in either approach reported by mypy as errors?)

@picnixz
Copy link
Member Author

picnixz commented Mar 25, 2024

When checking an individual file (mypy <path/to/module.py), the overrides were ignored, so errors would be reported.

The issue was: if you don't remove the file you are checking from the list of overrides, there won't be an error (even if you mypy it explicitly). So you needed to first remove from the override list AND then you could mypy it.

Now, with my PR, you can directly mypy it since an excluded file is only ignored if it is not explicitly passed.

Will we forget to update the paths if we move files around? (equally could happen for module names; are inconsistencies in either approach reported by mypy as errors?)

Yes.. but the same would have been the case for the module approach. Note that with an explicit exclusion, we also do not typecheck some files (possibly caching some results).

Copy link
Member

@chrisjsewell chrisjsewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when I first saw the title, I was thinking perhaps there is a difference in mypy behaviour, when these modules are imported into another module, ... but then I saw that we are only doing this for test files, so that does not apply 😄

All good then
(maybe could change the PR / commit message to reflect this is only for tests, but not a blocker)

@picnixz picnixz merged commit d5baa46 into sphinx-doc:master Mar 28, 2024
7 checks passed
@picnixz picnixz deleted the pyproject-update branch March 28, 2024 08:11
@picnixz
Copy link
Member Author

picnixz commented Mar 28, 2024

I hate myself. I made a typo in the commit message (it's time for me to actually change my glasses).

(I also don't like the fact that I can't preview the commit message on Github...)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 30, 2024
@AA-Turner AA-Turner added this to the 7.3.0 milestone Jul 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants