From 4564f521781246d6af17ff1915d0ec7510919421 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20Royer?= Date: Tue, 20 Aug 2024 16:42:40 +0200 Subject: [PATCH 1/3] Make River fully type-checked by default Add an override for all modules while they are not annotated. --- pyproject.toml | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index b45f37e632..19b7ff52d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -127,6 +127,7 @@ required-imports = ["from __future__ import annotations"] [tool.mypy] files = "river" +strict = true [[tool.mypy.overrides]] module = [ @@ -144,3 +145,63 @@ module = [ "requests.*" ] ignore_missing_imports = true + +[[tool.mypy.overrides]] +# Disable strict mode for all non fully-typed modules +module = [ + "river.base.*", + "river.metrics.*", + "river.utils.*", + "river.stats.*", + "river.optim.*", + "river.datasets.*", + "river.tree.*", + "river.preprocessing.*", + "river.stream.*", + "river.linear_model.*", + "river.evaluate.*", + "river.drift.*", + "river.compose.*", + "river.bandit.*", + "river.cluster.*", + "river.anomaly.*", + "river.time_series.*", + "river.feature_extraction.*", + "river.ensemble.*", + "river.proba.*", + "river.multioutput.*", + "river.naive_bayes.*", + "river.checks.*", + "river.rules.*", + "river.model_selection.*", + "river.forest.*", + "river.neighbors.*", + "river.sketch.*", + "river.facto.*", + "river.covariance.*", + "river.compat.*", + "river.multiclass.*", + "river.reco.*", + "river.imblearn.*", + "river.feature_selection.*", + "river.misc.*", + "river.active.*", + "river.conf.*", + "river.neural_net.*", + "river.test_estimators", + "river.dummy", +] +# The strict option is global, the checks must be disabled one by one +warn_unused_ignores = false +strict_equality = false +strict_concatenate = false +check_untyped_defs = false +allow_subclassing_any = true +allow_untyped_decorators = true +allow_any_generics = true +allow_untyped_calls = true +allow_incomplete_defs = true +allow_untyped_defs = true +implicit_reexport = true +warn_return_any = false +extra_checks = false From e0b60141f33e45196fe454a9459703cb906b29bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20Royer?= Date: Wed, 21 Aug 2024 14:49:50 +0200 Subject: [PATCH 2/3] Use the true location of Gymnasium's registry The registry variable of Gymnasium environments is located in the 'registration' module. This variables is also imported by the 'envs' module, but not explictely re-exported. This means the previous code was correct at runtime, but MyPy raised easily-corrected warnings. --- river/bandit/envs/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/river/bandit/envs/__init__.py b/river/bandit/envs/__init__.py index 6c91fa9b71..673edc9277 100644 --- a/river/bandit/envs/__init__.py +++ b/river/bandit/envs/__init__.py @@ -15,13 +15,13 @@ RIVER_NAMESPACE = "river_bandits" - if (env_id := f"{RIVER_NAMESPACE}/CandyCaneContest-v0") not in gym.envs.registry: + if (env_id := f"{RIVER_NAMESPACE}/CandyCaneContest-v0") not in gym.envs.registration.registry: gym.envs.registration.register( id=env_id, entry_point="river.bandit.envs:CandyCaneContest", max_episode_steps=CandyCaneContest.n_steps, ) - if (env_id := f"{RIVER_NAMESPACE}/KArmedTestbed-v0") not in gym.envs.registry: + if (env_id := f"{RIVER_NAMESPACE}/KArmedTestbed-v0") not in gym.envs.registration.registry: gym.envs.registration.register( id=env_id, entry_point="river.bandit.envs:KArmedTestbed", From 17dadad2b9f9e152a9754ccc818784b5522d6826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20Royer?= Date: Thu, 22 Aug 2024 17:42:57 +0200 Subject: [PATCH 3/3] Enable more rules for all modules These rules do not cause errors in the current code, meaning they can be enabled without harm. --- pyproject.toml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 19b7ff52d5..c73d0a18f2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -193,15 +193,11 @@ module = [ ] # The strict option is global, the checks must be disabled one by one warn_unused_ignores = false -strict_equality = false -strict_concatenate = false check_untyped_defs = false allow_subclassing_any = true -allow_untyped_decorators = true allow_any_generics = true allow_untyped_calls = true allow_incomplete_defs = true allow_untyped_defs = true implicit_reexport = true warn_return_any = false -extra_checks = false