From aeb4de0db06226c365c5f73adfdac1bcd94a8b61 Mon Sep 17 00:00:00 2001 From: s-weigand Date: Sun, 6 Nov 2022 23:11:46 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=E2=8C=A8=EF=B8=8F=20Made=20mypy=20?= =?UTF-8?q?optout=20instead=20of=20opt=20in=20and=20fixed=20some=20typing?= =?UTF-8?q?=20issues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 1 - .../unit/analysis/bench_optimize.py | 7 +++- glotaran/builtin/io/yml/utils.py | 1 + .../test/test_coherent_artifact.py | 6 ++- .../decay/test/test_decay_megacomplex.py | 4 +- glotaran/model/model.py | 3 +- .../sequential_spectral_decay.py | 4 +- setup.cfg | 38 ++++--------------- 8 files changed, 24 insertions(+), 40 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 25313dc65..48125821b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -114,7 +114,6 @@ repos: rev: v0.982 hooks: - id: mypy - files: "^glotaran/(plugin_system|utils|deprecation|testing|optimization|parameter|project|simulation|model|builtin/io/pandas)" exclude: "docs" additional_dependencies: [types-all, types-attrs] diff --git a/benchmark/benchmarks/unit/analysis/bench_optimize.py b/benchmark/benchmarks/unit/analysis/bench_optimize.py index 24ea523af..dbc47f3d3 100644 --- a/benchmark/benchmarks/unit/analysis/bench_optimize.py +++ b/benchmark/benchmarks/unit/analysis/bench_optimize.py @@ -12,7 +12,12 @@ from glotaran.simulation import simulate try: - from glotaran.optimization.test.models import MultichannelMulticomponentDecay + # isort: off + from glotaran.optimization.test.models import ( # type: ignore[attr-defined] + MultichannelMulticomponentDecay, + ) + + # isort: on except ImportError: # 0.7.0 from glotaran.optimization.test.suites import MultichannelMulticomponentDecay diff --git a/glotaran/builtin/io/yml/utils.py b/glotaran/builtin/io/yml/utils.py index 0eed4b548..f6a882a5d 100644 --- a/glotaran/builtin/io/yml/utils.py +++ b/glotaran/builtin/io/yml/utils.py @@ -30,6 +30,7 @@ def write_dict( stream = StringIO() yaml.dump(data, stream) return stream.getvalue() + return None def load_dict(source: str | Path, is_file: bool) -> dict[str, Any]: diff --git a/glotaran/builtin/megacomplexes/coherent_artifact/test/test_coherent_artifact.py b/glotaran/builtin/megacomplexes/coherent_artifact/test/test_coherent_artifact.py index fcbff5e0b..989634cf1 100644 --- a/glotaran/builtin/megacomplexes/coherent_artifact/test/test_coherent_artifact.py +++ b/glotaran/builtin/megacomplexes/coherent_artifact/test/test_coherent_artifact.py @@ -1,3 +1,5 @@ +from typing import Any + import numpy as np import pytest import xarray as xr @@ -18,7 +20,7 @@ ("none", "dispersed", "shifted"), ) def test_coherent_artifact(spectral_dependence: str): - model_dict = { + model_dict: dict[str, dict[str, Any]] = { "initial_concentration": { "j1": {"compartments": ["s1"], "parameters": ["irf_center"]}, }, @@ -80,7 +82,7 @@ def test_coherent_artifact(spectral_dependence: str): **model_dict ) - parameters = Parameters.from_list(parameter_list) + parameters = Parameters.from_list(parameter_list) # type: ignore[arg-type] time = np.arange(0, 50, 1.5) spectral = np.asarray([200, 300, 400]) diff --git a/glotaran/builtin/megacomplexes/decay/test/test_decay_megacomplex.py b/glotaran/builtin/megacomplexes/decay/test/test_decay_megacomplex.py index 3251d7763..a08c77271 100644 --- a/glotaran/builtin/megacomplexes/decay/test/test_decay_megacomplex.py +++ b/glotaran/builtin/megacomplexes/decay/test/test_decay_megacomplex.py @@ -163,7 +163,7 @@ class ThreeComponentParallel: ["1", 501e-3], ["2", 202e-4], ["3", 105e-5], - {"non-negative": True}, + {"non-negative": True}, # type: ignore[list-item] ], "irf": [["center", 1.3], ["width", 7.8]], } @@ -223,7 +223,7 @@ class ThreeComponentSequential: ["1", 501e-3], ["2", 202e-4], ["3", 105e-5], - {"non-negative": True}, + {"non-negative": True}, # type: ignore[list-item] ], "irf": [["center", 1.3], ["width", 7.8]], } diff --git a/glotaran/model/model.py b/glotaran/model/model.py index 9956b81f0..40176aa78 100644 --- a/glotaran/model/model.py +++ b/glotaran/model/model.py @@ -3,6 +3,7 @@ from collections.abc import Callable from collections.abc import Generator +from collections.abc import Iterable from collections.abc import Mapping from typing import Any from typing import ClassVar @@ -256,7 +257,7 @@ def create_class(cls, attributes: dict[str, Attribute]) -> type[Model]: @classmethod def create_class_from_megacomplexes( - cls, megacomplexes: list[type[Megacomplex]] + cls, megacomplexes: Iterable[type[Megacomplex]] ) -> type[Model]: """Create model class for megacomplexes. diff --git a/glotaran/testing/simulated_data/sequential_spectral_decay.py b/glotaran/testing/simulated_data/sequential_spectral_decay.py index 8a95943c0..60f060d9f 100644 --- a/glotaran/testing/simulated_data/sequential_spectral_decay.py +++ b/glotaran/testing/simulated_data/sequential_spectral_decay.py @@ -10,13 +10,13 @@ SIMULATION_MODEL_YML = generate_model_yml( generator_name="spectral_decay_sequential", - generator_arguments={"nr_compartments": 3, "irf": True}, # type:ignore[arg-type] + generator_arguments={"nr_compartments": 3, "irf": True}, ) SIMULATION_MODEL = load_model(SIMULATION_MODEL_YML, format_name="yml_str") MODEL_YML = generate_model_yml( generator_name="decay_sequential", - generator_arguments={"nr_compartments": 3, "irf": True}, # type:ignore[arg-type] + generator_arguments={"nr_compartments": 3, "irf": True}, ) MODEL = load_model(MODEL_YML, format_name="yml_str") diff --git a/setup.cfg b/setup.cfg index 4a3cd6cd2..409ab43e3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -96,38 +96,14 @@ show_error_codes = True warn_unused_configs = True warn_unused_ignores = True -[mypy-glotaran.*] +[mypy-glotaran.builtin.megacomplexes.*] ignore_errors = True -[mypy-glotaran.plugin_system.*] -ignore_errors = False - -[mypy-glotaran.utils.*] -ignore_errors = False - -[mypy-glotaran.deprecation.*] -ignore_errors = False - -[mypy-glotaran.optimization.*] -ignore_errors = False - -[mypy-glotaran.optimization.test.*] -ignore_errors = False - -[mypy-glotaran.project.generators.test.*] -ignore_errors = False - -[mypy-glotaran.parameter.*] -ignore_errors = False - -[mypy-glotaran.project.*] -ignore_errors = False - -[mypy-glotaran.simulation.*] -ignore_errors = False +[mypy-glotaran.builtin.io.ascii.*] +ignore_errors = True -[mypy-glotaran.model.*] -ignore_errors = False +[mypy-glotaran.cli.*] +ignore_errors = True -[mypy-glotaran.builtin.io.pandas.*] -ignore_errors = False +[mypy-benchmark.*] +ignore_errors = True