From 3d28d1e5de6bc9d5c88ec8396885d60784b9139a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Quentin=20Gallou=C3=A9dec?= <45557362+qgallouedec@users.noreply.github.com> Date: Mon, 28 Nov 2022 23:00:31 +0100 Subject: [PATCH] Mypy type checking (#119) * Update Makefile * Update changelog * gitignore mypy cache * mypy config * Add color to mypy output Co-authored-by: Antonin Raffin --- .github/workflows/ci.yml | 3 +++ .gitignore | 1 + Makefile | 7 ++++++- docs/misc/changelog.rst | 1 + setup.cfg | 27 +++++++++++++++++++++++++++ 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 101e67b..0e3f179 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,9 @@ on: jobs: build: + env: + TERM: xterm-256color + FORCE_COLOR: 1 # Skip CI if [ci skip] in the commit message if: "! contains(toJSON(github.event.commits.*.message), '[ci skip]')" runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index 9f54889..1aca03f 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ _build/ *.npz *.pth .pytype/ +.mypy_cache git_rewrite_commit_history.sh # Setuptools distribution and build folders. diff --git a/Makefile b/Makefile index d36ad2e..1d3b794 100644 --- a/Makefile +++ b/Makefile @@ -4,9 +4,14 @@ LINT_PATHS=sb3_contrib/ tests/ setup.py pytest: ./scripts/run_tests.sh -type: +pytype: pytype -j auto +mypy: + mypy ${LINT_PATHS} + +type: pytype mypy + lint: # stop the build if there are Python syntax errors or undefined names # see https://lintlyci.github.io/Flake8Rules/ diff --git a/docs/misc/changelog.rst b/docs/misc/changelog.rst index d279055..7a9bdf1 100644 --- a/docs/misc/changelog.rst +++ b/docs/misc/changelog.rst @@ -14,6 +14,7 @@ Breaking Changes: New Features: ^^^^^^^^^^^^^ +- Introduced mypy type checking Bug Fixes: ^^^^^^^^^^ diff --git a/setup.cfg b/setup.cfg index e9edb55..75afed5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -19,6 +19,33 @@ markers = [pytype] inputs = sb3_contrib +[mypy] +ignore_missing_imports = True +follow_imports = silent +show_error_codes = True +exclude = (?x)( + sb3_contrib/ppo_recurrent/ppo_recurrent.py$ + | sb3_contrib/ars/ars.py$ + | sb3_contrib/ars/policies.py$ + | sb3_contrib/qrdqn/qrdqn.py$ + | sb3_contrib/qrdqn/policies.py$ + | sb3_contrib/common/recurrent/type_aliases.py$ + | sb3_contrib/common/recurrent/policies.py$ + | sb3_contrib/common/recurrent/buffers.py$ + | sb3_contrib/common/utils.py$ + | sb3_contrib/common/maskable/distributions.py$ + | sb3_contrib/common/maskable/callbacks.py$ + | sb3_contrib/common/maskable/policies.py$ + | sb3_contrib/common/maskable/buffers.py$ + | sb3_contrib/common/envs/invalid_actions_env.py$ + | sb3_contrib/common/vec_env/async_eval.py$ + | sb3_contrib/tqc/tqc.py$ + | sb3_contrib/tqc/policies.py$ + | sb3_contrib/trpo/trpo.py$ + | sb3_contrib/ppo_mask/ppo_mask.py$ + | tests/test_train_eval_mode.py$ + ) + [flake8] # line breaks before and after binary operators ignore = W503,W504,E203,E231