Skip to content

Use mypy for static type checking in continuous integration #268

Description

@namurphy

Mypy uses function annotations to perform static type checking. Mypy has the potential to help us track down bugs without even running a program. Lately we've started to add type hints to functions and methods in a few of our subpackages (including atomic, for example) where we sometimes make use of the typing package as well. It would be great if we can use mypy in our suite of tests with Travis CI which would involve updating .travis.yml (which is also being edited in #264).

A potential problem is that some return annotations are given as units:

def func() -> u.eV:

I am not sure how mypy will handle that situation. Some function arguments are going to be annotated with the Particle class in order for @particle_input to know what to do with them. That may also make mypy grumpy. Another thing to worry about is that backwards compatibility is not guaranteed for mypy yet, so we might have to make some further adjustments later on. I personally am inexperienced with mypy, but projects such as zulip have added mypy to their Travis CI tests.

Many thanks to whoever ends up working on this! (And also thanks to @Cadair for letting us know about mypy!)

Activity

  1. added
    effort: mediumRequiring perhaps ∼1–3 days
    priority: mediumIssues & PRs of moderate urgency and importance
    help wantedUnassigned issues that would benefit from assistance or contributions needed from the community
    on Feb 17, 2018
  2. added this to the milestone on Feb 17, 2018
  3. StanczakDominik commented on Oct 3, 2018

    @StanczakDominik
    Member

    Probably best to close this one as we hadn't considered mypy and astropy.units clashing?

  4. added
    upstream fix requiredIssues & PRs that are blocked due to a problem with a dependency
    and removed
    effort: mediumRequiring perhaps ∼1–3 days
    help wantedUnassigned issues that would benefit from assistance or contributions needed from the community
    priority: mediumIssues & PRs of moderate urgency and importance
    on Oct 3, 2018
  5. 2 remaining items

  6. changed the title [-]Use mypy for static type checking in Travis CI[/-] [+]Use mypy for static type checking in continuous integration[/+] on Jan 31, 2022
  7. removed
    upstream fix requiredIssues & PRs that are blocked due to a problem with a dependency
    on Jan 31, 2022
  8. namurphy commented on Jan 31, 2022

    @namurphy
    MemberAuthor

    Re-opening this because there now exists a workaround for Quantity type annotations that preserve units (see #1413).

  9. added
    Python Lv4 | ExpertIssues that require in-depth knowledge of Python
    and removed
    Python Lv4 | ExpertIssues that require in-depth knowledge of Python
    on Aug 18, 2022
  10. modified the milestones: v0.2.0, v2025.9.0 on Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CIRelated to continuous integrationPlasma Lv0 | NoviceIssues that do not require knowledge of physicsPython Lv3 | ProficientIssues that require proficiency in Pythonstatic type checkingtestingupstream fix requiredIssues & PRs that are blocked due to a problem with a dependency

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions