From e874734f946d8f0f1d9b85cf66745ba456b8edbb Mon Sep 17 00:00:00 2001 From: muxator Date: Sat, 24 Feb 2024 13:06:29 +0100 Subject: [PATCH] lint: since we moved to python 3.9, let's bump ruff's target to 3.9, too --- .ruff.toml | 4 ++-- black_it/calibrator.py | 3 ++- black_it/loss_functions/base.py | 5 ++++- black_it/plot/plot_results.py | 3 ++- black_it/samplers/halton.py | 4 +++- black_it/schedulers/base.py | 4 +++- black_it/schedulers/rl/rl_scheduler.py | 5 +++-- black_it/utils/json_pandas_checkpointing.py | 4 +++- black_it/utils/sqlite3_checkpointing.py | 4 +++- examples/models/economics/brock_hommes.py | 4 +++- examples/models/simple_models.py | 4 +++- tests/test_examples/base.py | 2 +- tests/test_plot/base.py | 5 ++++- tests/test_plot/test_plot_descriptive_statistics.py | 5 ++++- 14 files changed, 40 insertions(+), 16 deletions(-) diff --git a/.ruff.toml b/.ruff.toml index a2adefc2..141519ff 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -42,8 +42,8 @@ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" # Whether to enable preview mode. When preview mode is enabled, Ruff will use unstable rules and fixes. preview = true -# Assume Python 3.8 -target-version = "py38" +# Assume Python 3.9 +target-version = "py39" [per-file-ignores] "examples/docker-sir.py" = ["INP001", "T201"] diff --git a/black_it/calibrator.py b/black_it/calibrator.py index 78854490..419bd4a5 100644 --- a/black_it/calibrator.py +++ b/black_it/calibrator.py @@ -22,7 +22,7 @@ import time import warnings from pathlib import Path -from typing import TYPE_CHECKING, Callable, Sequence, cast +from typing import TYPE_CHECKING, Callable, cast import numpy as np from joblib import Parallel, delayed # type: ignore[import] @@ -39,6 +39,7 @@ if TYPE_CHECKING: import os + from collections.abc import Sequence from numpy.typing import NDArray diff --git a/black_it/loss_functions/base.py b/black_it/loss_functions/base.py index 09152b69..4da740d6 100644 --- a/black_it/loss_functions/base.py +++ b/black_it/loss_functions/base.py @@ -18,13 +18,16 @@ from __future__ import annotations from abc import ABC, abstractmethod -from typing import Callable, Optional, Sequence +from typing import TYPE_CHECKING, Callable, Optional import numpy as np from numpy.typing import NDArray from black_it.utils.base import _assert +if TYPE_CHECKING: + from collections.abc import Sequence + TimeSeriesFilter = Optional[Callable[[NDArray[np.float64]], NDArray[np.float64]]] """A filter that receives a time series and returns its filtered version. Used by the BaseLoss constructor.""" diff --git a/black_it/plot/plot_results.py b/black_it/plot/plot_results.py index a5d233f7..ed42c167 100644 --- a/black_it/plot/plot_results.py +++ b/black_it/plot/plot_results.py @@ -19,7 +19,7 @@ import pickle # nosec B403 from pathlib import Path -from typing import TYPE_CHECKING, Collection +from typing import TYPE_CHECKING import matplotlib.pyplot as plt # type: ignore[import] import numpy as np @@ -31,6 +31,7 @@ if TYPE_CHECKING: import os + from collections.abc import Collection from numpy.typing import NDArray diff --git a/black_it/samplers/halton.py b/black_it/samplers/halton.py index e4550f0c..3cc1b5a2 100644 --- a/black_it/samplers/halton.py +++ b/black_it/samplers/halton.py @@ -18,7 +18,7 @@ from __future__ import annotations import itertools -from typing import TYPE_CHECKING, Iterator +from typing import TYPE_CHECKING import numpy as np @@ -26,6 +26,8 @@ from black_it.utils.base import check_arg, digitize_data if TYPE_CHECKING: + from collections.abc import Iterator + from numpy.typing import NDArray from black_it.search_space import SearchSpace diff --git a/black_it/schedulers/base.py b/black_it/schedulers/base.py index 1af5aa6a..0ae00730 100644 --- a/black_it/schedulers/base.py +++ b/black_it/schedulers/base.py @@ -19,11 +19,13 @@ import contextlib from abc import ABC, abstractmethod -from typing import TYPE_CHECKING, Generator, Sequence +from typing import TYPE_CHECKING from black_it.utils.seedable import BaseSeedable if TYPE_CHECKING: + from collections.abc import Generator, Sequence + import numpy as np from numpy.typing import NDArray diff --git a/black_it/schedulers/rl/rl_scheduler.py b/black_it/schedulers/rl/rl_scheduler.py index 3c88b814..5235df72 100644 --- a/black_it/schedulers/rl/rl_scheduler.py +++ b/black_it/schedulers/rl/rl_scheduler.py @@ -18,7 +18,7 @@ from __future__ import annotations import threading -from typing import TYPE_CHECKING, List, Sequence, cast +from typing import TYPE_CHECKING, cast import numpy as np @@ -27,6 +27,7 @@ from black_it.schedulers.base import BaseScheduler if TYPE_CHECKING: + from collections.abc import Sequence from queue import Queue from numpy._typing import NDArray @@ -103,7 +104,7 @@ def _add_or_get_bootstrap_sampler( return samplers, sampler_types[HaltonSampler] new_sampler = HaltonSampler(batch_size=1) - return tuple(list(samplers) + cast(List[BaseSampler], [new_sampler])), len( + return tuple(list(samplers) + cast(list[BaseSampler], [new_sampler])), len( samplers, ) diff --git a/black_it/utils/json_pandas_checkpointing.py b/black_it/utils/json_pandas_checkpointing.py index b740e6ad..ab7289b6 100644 --- a/black_it/utils/json_pandas_checkpointing.py +++ b/black_it/utils/json_pandas_checkpointing.py @@ -20,7 +20,7 @@ import json import pickle # nosec B403 from pathlib import Path -from typing import TYPE_CHECKING, Mapping +from typing import TYPE_CHECKING import numpy as np import pandas as pd # type: ignore[import] @@ -29,6 +29,8 @@ from black_it.utils.base import NumpyArrayEncoder, PathLike if TYPE_CHECKING: + from collections.abc import Mapping + from numpy.typing import NDArray from black_it.loss_functions.base import BaseLoss diff --git a/black_it/utils/sqlite3_checkpointing.py b/black_it/utils/sqlite3_checkpointing.py index bde439c5..27a5be82 100644 --- a/black_it/utils/sqlite3_checkpointing.py +++ b/black_it/utils/sqlite3_checkpointing.py @@ -23,12 +23,14 @@ import pickle # nosec B403 import sqlite3 from pathlib import Path -from typing import TYPE_CHECKING, Mapping, Sequence +from typing import TYPE_CHECKING import numpy as np from numpy.typing import NDArray if TYPE_CHECKING: + from collections.abc import Mapping, Sequence + from black_it.loss_functions.base import BaseLoss from black_it.samplers.base import BaseSampler from black_it.utils.base import PathLike diff --git a/examples/models/economics/brock_hommes.py b/examples/models/economics/brock_hommes.py index 5bab458f..ccdb64fb 100644 --- a/examples/models/economics/brock_hommes.py +++ b/examples/models/economics/brock_hommes.py @@ -17,12 +17,14 @@ """Implementation of the model in (Brock and Hommes, 1998).""" from __future__ import annotations -from typing import TYPE_CHECKING, Sequence +from typing import TYPE_CHECKING import numpy as np from scipy.special import softmax if TYPE_CHECKING: + from collections.abc import Sequence + from numpy.typing import NDArray diff --git a/examples/models/simple_models.py b/examples/models/simple_models.py index 32853314..9ee8ef6e 100644 --- a/examples/models/simple_models.py +++ b/examples/models/simple_models.py @@ -28,12 +28,14 @@ """ from __future__ import annotations -from typing import TYPE_CHECKING, Sequence +from typing import TYPE_CHECKING import numpy as np from scipy.stats import alpha, bernoulli if TYPE_CHECKING: + from collections.abc import Sequence + from numpy.typing import NDArray diff --git a/tests/test_examples/base.py b/tests/test_examples/base.py index 3c2a9510..6dd89c27 100644 --- a/tests/test_examples/base.py +++ b/tests/test_examples/base.py @@ -16,8 +16,8 @@ """Base module for example tests.""" import sys +from collections.abc import Sequence from pathlib import Path -from typing import Sequence import pytest diff --git a/tests/test_plot/base.py b/tests/test_plot/base.py index a009aedb..57203290 100644 --- a/tests/test_plot/base.py +++ b/tests/test_plot/base.py @@ -20,11 +20,14 @@ import logging from pathlib import Path from tempfile import TemporaryDirectory -from typing import Any, Callable, Sequence +from typing import TYPE_CHECKING, Any, Callable import matplotlib.pyplot as plt # type: ignore[import] from matplotlib.testing.compare import compare_images # type: ignore[import] +if TYPE_CHECKING: + from collections.abc import Sequence + class BasePlotTest: """Base test class for plotting functions.""" diff --git a/tests/test_plot/test_plot_descriptive_statistics.py b/tests/test_plot/test_plot_descriptive_statistics.py index 6092edb3..2a0cb857 100644 --- a/tests/test_plot/test_plot_descriptive_statistics.py +++ b/tests/test_plot/test_plot_descriptive_statistics.py @@ -17,7 +17,7 @@ """This test module contains tests for the plot_descriptive_statistics.py module.""" from __future__ import annotations -from typing import Any, Sequence +from typing import TYPE_CHECKING, Any import numpy as np @@ -26,6 +26,9 @@ from tests.test_plot.base import BasePlotTest from tests.utils.base import skip_on_windows +if TYPE_CHECKING: + from collections.abc import Sequence + @skip_on_windows() class TestTsStats(BasePlotTest):