Skip to content

[JOSS REVIEW]: Static Type Hints #168

@dostuffthatmatters

Description

@dostuffthatmatters

This issue is part of the JOSS review of PyFive (openjournals/joss-reviews#9688)

Dear maintainers,

Currently you mainly use docstrings to document the type of your variables, but no type hints. This can cause issues for users calling the library (see image 1), and also for developers internally (see image 2). Static code analysis will have a hard time following the datatypes when no hints are given. Static analysis tools like Mypy or Pyright can catch many bugs not caught by the tests suite and make the code more readable by being self-documenting.

Image 3 shows a bug I noticed when opening a file with a mode not allowed. This would have been caught with a static code analyzer. I recommend Pyright with strict settings since it catches more bugs than Mypy.

You can add the static type checks as a Pytest so users don't have to run a separate command to run them (e.g., https://github.com/tum-esm/utils/blob/main/tests/test_static_types.py). I also recommend running these tests before any other tests.

Best,
Moritz Oliveira Makowski

Image 1:
Image

Image 2:
Image

Image 3:
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions