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

Add a tox environment to run mypy for static type checking #15815

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

namurphy
Copy link
Contributor

@namurphy namurphy commented Jan 5, 2024

Blocked by:

This exploratory pull request would add a tox environment for running mypy for static type checking of type hint annotations. It could be run using:

tox -e mypy

This PR is based off of PlasmaPy/PlasmaPy#2431. A similar PR to add mypy to PlasmaPy's CI suite is PlasmaPy/PlasmaPy#2432. I'm not adding mypy to the CI suite in this PR because that would be a much bigger step than adding a tox environment.

This PR would need to go along with a PR to add a mypy.ini file (e.g., #12971 or #15769) that ignores all current errors, since running mypy without it leads to ∼1–2K errors (depending on the settings we choose).

There has been a great discussion about typing in #15170.

Copy link

github-actions bot commented Jan 5, 2024

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • Is a milestone set? Milestone must be set but we cannot check for it on Actions; do not let the green checkmark fool you.
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

Copy link

github-actions bot commented Jan 5, 2024

👋 Thank you for your draft pull request! Do you know that you can use [ci skip] or [skip ci] in your commit messages to skip running continuous integration tests until you are ready?

@pllim
Copy link
Member

pllim commented Jan 5, 2024

Does this supersede #15794 ?

@namurphy
Copy link
Contributor Author

namurphy commented Jan 5, 2024

Thank you for the question! It's more like this PR depends on #15794 rather than superseding it. These PRs are two of the three steps that we took for adding mypy to PlasmaPy's CI suite:

  1. Configure mypy.ini so that running mypy ignores all current errors, which could be done with either of these PRs:
  1. Add a tox environment for running mypy (this PR)
  2. Add a GitHub Action that uses the tox environment (akin to Add mypy to continuous integration suite PlasmaPy/PlasmaPy#2432)

I wanted to separate the PRs in case there's a decision to take a different approach than #15794.

deps =
mypy
commands =
mypy {tox_root}/astropy --install-types --non-interactive
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are some packages that aren't typed themselves, but have created type stub packages that contain type information. The --install-types flag "causes mypy to install known missing stub packages for third-party libraries using pip", which means that mypy would have access to verified type information for packages like pandas, PyYAML, beautifulsoup4, etc. We could also manually add other type stub packages here, or otherwise specify mypy not to follow certain imports.

@namurphy
Copy link
Contributor Author

namurphy commented Jan 8, 2024

A follow-up to this exploratory PR: I mentioned in this post that it's worth considering alternatives to mypy such as pyright.

@astrofrog astrofrog modified the milestones: v6.1.0, v7.0.0 Apr 4, 2024
@nstarman
Copy link
Member

@namurphy, I'm in favor of this! mypy and pyright are sufficiently similar we can start with one and switch to the other, should the need arise. Since mypy is considered the baseline, I think it's good to start with it. This would be a good PR to get in for v7, so maintainers test their type hints!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants