reanahub / reana

REANA: Reusable research data analysis platform
https://docs.reana.io
MIT License
123 stars 54 forks source link

code quality: investigate Python type hints checkers #557

Open VMois opened 2 years ago

VMois commented 2 years ago

List of type checkers to investigate:

  1. Pyright, developed by Microsoft, detects types if no type annotations are present, is used in Pylance VS Code extension, which comes with the official Python extension.
  2. Mypy, the oldest type checker for Python, uses type annotations;
  3. Pytype, developed by Google, detects types if no type annotations are present;
  4. Pyre, developed by FB and Instagram, detects types, both type checker and static code analysis tool.

Criteria:

  1. support in the code editors: VS Code, PyCharm, ...;
  2. completeness of checks, what standards checker supports, how strict is checker;
  3. usage in GitHub actions.
tiborsimko commented 2 years ago

There are also other tools, for example pyanalyze.

VMois commented 2 years ago

Pyright has a nice getting started page. It follows several PEP conventions listed in the README.

Strictness can be controlled, some rules can be disabled, etc. similar to flake.

Support for VS Code, no direct support for PyCharm (but can be added as command-line tool).

Can be used in GitHub Actions in a similar way we use flake or pydocstyle.

mvidalgarcia commented 2 years ago

The circular import I faced some time ago: https://stackoverflow.com/questions/39740632/python-type-hinting-without-cyclic-imports

I think it was happening when trying to use Model type hints in the utils module of reana-db, thus causing circular imports as models.py does some imports from utils.py.

VMois commented 2 years ago

As an addition to the list, we can also try - https://sonarsource.com/open-source-editions/ for both personal uses and, as an integration, with GitHub for reviews.