Skip to content

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

Closed
namurphy wants to merge 2 commits into
astropy:mainfrom
namurphy:add-tox-env-for-mypy
Closed

namurphy wants to merge 2 commits into
astropy:mainfrom
namurphy:add-tox-env-for-mypy

Conversation

@namurphy

@namurphy namurphy commented Jan 5, 2024 •

Copy link
Copy Markdown
Contributor

Blocked by:

This 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 configuration (e.g., #16312) 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.

@github-actions

github-actions Bot commented Jan 5, 2024

Copy link
Copy Markdown
Contributor

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.

@github-actions

github-actions Bot commented Jan 5, 2024

Copy link
Copy Markdown
Contributor

👋 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

pllim commented Jan 5, 2024

Copy link
Copy Markdown
Member

Does this supersede #15794 ?

@namurphy

namurphy commented Jan 5, 2024 •

Copy link
Copy Markdown
Contributor Author

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.

Comment thread tox.ini
deps =
mypy
commands =
mypy {tox_root}/astropy --install-types --non-interactive

Copy link
Copy Markdown
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

namurphy commented Jan 8, 2024

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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!

@mhvk mhvk added the typing related to type annotations label May 30, 2024
@github-actions github-actions Bot added the Close? Tell stale bot that this issue/PR is stale label Jun 4, 2024
@github-actions

github-actions Bot commented Jun 4, 2024

Copy link
Copy Markdown
Contributor

Hi humans 👋 - this pull request hasn't had any new commits for approximately 4 months. I plan to close this in 30 days if the pull request doesn't have any new commits by then.

In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary.

If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock.

If you believe I commented on this pull request incorrectly, please report this here.

@neutrinoceros neutrinoceros removed this from the v7.0.0 milestone Oct 17, 2024
@github-actions github-actions Bot added the closed-by-bot Closed by stale bot label Nov 2, 2024
@github-actions

github-actions Bot commented Nov 2, 2024

Copy link
Copy Markdown
Contributor

I'm going to close this pull request as per my previous message. If you think what is being added/fixed here is still important, please remember to open an issue to keep track of it. Thanks!

If this is the first time I am commenting on this issue, or if you believe I closed this issue incorrectly, please report this here.

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

Labels

Close? Tell stale bot that this issue/PR is stale closed-by-bot Closed by stale bot dev-automation no-changelog-entry-needed testing typing related to type annotations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants