Skip to content

Commit

Permalink
New MyPy configuration for per-module type completeness (#1596)
Browse files Browse the repository at this point in the history
* Make River fully type-checked by default

Add an override for all modules while they are not annotated.

* 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.

* Enable more rules for all modules

These rules do not cause errors in the current code, meaning they can be
enabled without harm.
  • Loading branch information
e10e3 authored Sep 11, 2024
1 parent d310abb commit ba66ee7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
57 changes: 57 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ indent-style = "space"

[tool.mypy]
files = "river"
strict = true

[[tool.mypy.overrides]]
module = [
Expand All @@ -163,3 +164,59 @@ module = [
"polars.*"
]
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
check_untyped_defs = false
allow_subclassing_any = true
allow_any_generics = true
allow_untyped_calls = true
allow_incomplete_defs = true
allow_untyped_defs = true
implicit_reexport = true
warn_return_any = false
4 changes: 2 additions & 2 deletions river/bandit/envs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit ba66ee7

Please sign in to comment.