Skip to content

Commit 794542a

Browse files
committed
Manually fix remaining issues
1 parent 216d780 commit 794542a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+327
-230
lines changed

esmvalcore/_main.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,15 @@
3535
import sys
3636
from importlib.metadata import entry_points
3737
from pathlib import Path
38+
from typing import TYPE_CHECKING
3839

3940
import fire
4041

4142
from esmvalcore.config._config import warn_if_old_extra_facets_exist
4243

44+
if TYPE_CHECKING:
45+
from esmvalcore.config import Session
46+
4347
# set up logging
4448
logger = logging.getLogger(__name__)
4549

@@ -80,7 +84,7 @@ def parse_resume(resume, recipe):
8084
return resume
8185

8286

83-
def process_recipe(recipe_file: Path, session) -> None:
87+
def process_recipe(recipe_file: Path, session: Session) -> None:
8488
"""Process recipe."""
8589
import datetime
8690
import shutil
@@ -634,7 +638,7 @@ def _create_session_dir(session):
634638
def _run(
635639
self,
636640
recipe: Path,
637-
session,
641+
session: Session,
638642
cli_config_dir: Path | None,
639643
) -> None:
640644
"""Run `recipe` using `session`."""
@@ -697,7 +701,7 @@ def _clean_preproc(session):
697701
shutil.rmtree(session.preproc_dir)
698702

699703
@staticmethod
700-
def _get_recipe(recipe) -> Path:
704+
def _get_recipe(recipe: str) -> Path:
701705
from esmvalcore.config._diagnostics import DIAGNOSTICS
702706

703707
if not os.path.isfile(recipe):

esmvalcore/_provenance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,11 @@ def __repr__(self) -> str:
194194
"""Return representation string (e.g., used by ``pformat``)."""
195195
return f"{self.__class__.__name__}: {self.filename}"
196196

197-
def __eq__(self, other) -> bool:
197+
def __eq__(self, other: object) -> bool:
198198
"""Check if `other` equals `self`."""
199199
return hasattr(other, "filename") and self.filename == other.filename
200200

201-
def __lt__(self, other) -> bool:
201+
def __lt__(self, other: object) -> bool:
202202
"""Check if `other` should be sorted before `self`."""
203203
return hasattr(other, "filename") and self.filename < other.filename
204204

esmvalcore/_recipe/check.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def _verify_span_value(span: str) -> None:
364364
raise RecipeError(msg)
365365

366366

367-
def _verify_groupby(groupby: Any) -> None:
367+
def _verify_groupby(groupby: list[str]) -> None:
368368
"""Raise error if groupby arguments cannot be verified."""
369369
if not isinstance(groupby, list):
370370
msg = (
@@ -375,7 +375,7 @@ def _verify_groupby(groupby: Any) -> None:
375375
raise RecipeError(msg)
376376

377377

378-
def _verify_keep_input_datasets(keep_input_datasets: Any) -> None:
378+
def _verify_keep_input_datasets(keep_input_datasets: bool) -> None:
379379
if not isinstance(keep_input_datasets, bool):
380380
msg = (
381381
f"Invalid value encountered for `keep_input_datasets`."
@@ -385,7 +385,7 @@ def _verify_keep_input_datasets(keep_input_datasets: Any) -> None:
385385
raise RecipeError(msg)
386386

387387

388-
def _verify_ignore_scalar_coords(ignore_scalar_coords: Any) -> None:
388+
def _verify_ignore_scalar_coords(ignore_scalar_coords: bool) -> None:
389389
if not isinstance(ignore_scalar_coords, bool):
390390
msg = (
391391
f"Invalid value encountered for `ignore_scalar_coords`."

esmvalcore/_recipe/recipe.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
if TYPE_CHECKING:
6060
from collections.abc import Iterable, Sequence
6161

62+
from prov.model import ProvEntity
63+
6264
from esmvalcore._task import BaseTask
6365
from esmvalcore.config import Session
6466
from esmvalcore.io.protocol import DataElement
@@ -965,7 +967,10 @@ def _need_ncl(raw_diagnostics: dict[str, Diagnostic]) -> bool:
965967
return True
966968
return False
967969

968-
def _initialize_provenance(self, raw_documentation: dict[str, Any]):
970+
def _initialize_provenance(
971+
self,
972+
raw_documentation: dict[str, Any],
973+
) -> ProvEntity:
969974
"""Initialize the recipe provenance."""
970975
doc = deepcopy(raw_documentation)
971976

@@ -1381,10 +1386,10 @@ def write_html_summary(self) -> None:
13811386
RecipeOutput,
13821387
)
13831388

1384-
output = self.get_output()
1385-
13861389
try:
1387-
output = RecipeOutput.from_core_recipe_output(output)
1390+
output = RecipeOutput.from_core_recipe_output(
1391+
self.get_output(),
1392+
)
13881393
except LookupError as error:
13891394
# See https://github.com/ESMValGroup/ESMValCore/issues/28
13901395
logger.warning("Could not write HTML report: %s", error)

esmvalcore/_task.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def flatten(self):
285285
tasks.add(self)
286286
return tasks
287287

288-
def run(self, input_files=None):
288+
def run(self, input_files: list[str] | None = None) -> None:
289289
"""Run task."""
290290
if not self.output_files:
291291
if input_files is None:
@@ -310,7 +310,7 @@ def run(self, input_files=None):
310310
return self.output_files
311311

312312
@abc.abstractmethod
313-
def _run(self, input_files):
313+
def _run(self, input_files: list[str]) -> list[str]:
314314
"""Run task."""
315315

316316
def get_product_attributes(self) -> dict:
@@ -364,7 +364,7 @@ def __init__(self, prev_preproc_dir, preproc_dir, name):
364364

365365
super().__init__(ancestors=None, name=name, products=products)
366366

367-
def _run(self, _):
367+
def _run(self, _: list[str]) -> list[str]:
368368
"""Return the result of a previous run."""
369369
metadata = self.get_product_attributes()
370370

esmvalcore/cmor/_fixes/fix.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import logging
99
import tempfile
1010
from pathlib import Path
11-
from typing import TYPE_CHECKING
11+
from typing import TYPE_CHECKING, Any
1212

1313
import dask
1414
import numpy as np
@@ -423,12 +423,12 @@ def _msg_suffix(cube: Cube) -> str:
423423
return f"\n(for file {cube.attributes['source_file']})"
424424
return f"\n(for variable {cube.var_name})"
425425

426-
def _debug_msg(self, cube: Cube, msg: str, *args) -> None:
426+
def _debug_msg(self, cube: Cube, msg: str, *args: Any) -> None:
427427
"""Print debug message."""
428428
msg += self._msg_suffix(cube)
429429
generic_fix_logger.debug(msg, *args)
430430

431-
def _warning_msg(self, cube: Cube, msg: str, *args) -> None:
431+
def _warning_msg(self, cube: Cube, msg: str, *args: Any) -> None:
432432
"""Print debug message."""
433433
msg += self._msg_suffix(cube)
434434
generic_fix_logger.warning(msg, *args)

esmvalcore/cmor/fix.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import logging
1111
from collections import defaultdict
12-
from typing import TYPE_CHECKING
12+
from typing import TYPE_CHECKING, Any
1313

1414
from iris.cube import CubeList
1515

@@ -38,7 +38,7 @@ def fix_file( # noqa: PLR0913
3838
add_unique_suffix: bool = False,
3939
session: Session | None = None,
4040
frequency: str | None = None,
41-
**extra_facets,
41+
**extra_facets: Any,
4242
) -> str | Path | xr.Dataset | ncdata.NcData:
4343
"""Fix files before loading them into a :class:`~iris.cube.CubeList`.
4444
@@ -121,7 +121,7 @@ def fix_metadata(
121121
mip: str,
122122
frequency: str | None = None,
123123
session: Session | None = None,
124-
**extra_facets,
124+
**extra_facets: Any,
125125
) -> CubeList:
126126
"""Fix cube metadata if fixes are required.
127127
@@ -205,7 +205,7 @@ def fix_data(
205205
mip: str,
206206
frequency: str | None = None,
207207
session: Session | None = None,
208-
**extra_facets,
208+
**extra_facets: Any,
209209
) -> Cube:
210210
"""Fix cube data if fixes are required.
211211

esmvalcore/config/_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def warn_if_old_extra_facets_exist() -> None:
9494
)
9595

9696

97-
def load_config_developer(cfg_file) -> dict:
97+
def load_config_developer(cfg_file: Path) -> dict:
9898
"""Read the developer's configuration file."""
9999
with open(cfg_file, encoding="utf-8") as file:
100100
cfg = yaml.safe_load(file)

esmvalcore/config/_config_validators.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from functools import lru_cache, partial
1010
from importlib.resources import files as importlib_files
1111
from pathlib import Path
12-
from typing import TYPE_CHECKING, Any
12+
from typing import TYPE_CHECKING, Any, Literal
1313

1414
from packaging import version
1515

@@ -49,7 +49,11 @@ class ValidationError(ValueError):
4949
# to fit the needs of ESMValCore. Matplotlib is licenced under the terms of
5050
# the the 'Python Software Foundation License'
5151
# (https://www.python.org/psf/license)
52-
def _make_type_validator(cls: Any, *, allow_none: bool = False) -> Any:
52+
def _make_type_validator(
53+
cls: Any, # noqa: ANN401
54+
*,
55+
allow_none: bool = False,
56+
) -> Callable:
5357
"""Construct a type validator for `cls`.
5458
5559
Return a validator that converts inputs to *cls* or raises (and
@@ -363,7 +367,9 @@ def validate_extra_facets_dir(value):
363367
return validate_pathlist(value)
364368

365369

366-
def validate_projects(value: Any) -> Any:
370+
def validate_projects(
371+
value: dict,
372+
) -> dict[str, dict[str, Any]]:
367373
"""Validate projects mapping."""
368374
mapping = validate_dict(value)
369375
options_for_project: dict[str, Callable[[Any], Any]] = {
@@ -446,8 +452,8 @@ def _handle_deprecation(
446452
# TODO: remove in v2.15.0
447453
def deprecate_extra_facets_dir(
448454
validated_config: ValidatedConfig,
449-
value: Any,
450-
validated_value: Any,
455+
value: str | Path,
456+
validated_value: str | Path,
451457
) -> None:
452458
"""Deprecate ``extra_facets_dir`` option.
453459
@@ -483,8 +489,8 @@ def deprecate_extra_facets_dir(
483489

484490
def deprecate_rootpath(
485491
validated_config: ValidatedConfig,
486-
value: Any,
487-
validated_value: Any,
492+
value: dict,
493+
validated_value: dict,
488494
) -> None:
489495
"""Deprecate ``rootpath`` option.
490496
@@ -510,8 +516,8 @@ def deprecate_rootpath(
510516

511517
def deprecate_drs(
512518
validated_config: ValidatedConfig, # noqa: ARG001
513-
value: Any, # noqa: ARG001
514-
validated_value: Any, # noqa: ARG001
519+
value: dict, # noqa: ARG001
520+
validated_value: dict, # noqa: ARG001
515521
) -> None:
516522
"""Deprecate ``drs`` option.
517523
@@ -531,8 +537,8 @@ def deprecate_drs(
531537

532538
def deprecate_download_dir(
533539
validated_config: ValidatedConfig, # noqa: ARG001
534-
value: Any, # noqa: ARG001
535-
validated_value: Any, # noqa: ARG001
540+
value: str | Path, # noqa: ARG001
541+
validated_value: str | Path, # noqa: ARG001
536542
) -> None:
537543
"""Deprecate ``download_dir`` option.
538544
@@ -552,8 +558,8 @@ def deprecate_download_dir(
552558

553559
def deprecate_search_esgf(
554560
validated_config: ValidatedConfig,
555-
value: Any, # noqa: ARG001
556-
validated_value: Any,
561+
value: Literal["never", "when_missing", "always"], # noqa: ARG001
562+
validated_value: Literal["never", "when_missing", "always"],
557563
) -> None:
558564
"""Deprecate ``search_esgf`` option.
559565

esmvalcore/config/_diagnostics.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import os
55
from pathlib import Path
6+
from typing import Self
67

78
import yaml
89

@@ -80,7 +81,7 @@ def __init__(self, *args, **kwargs):
8081
self.source_file = None
8182

8283
@classmethod
83-
def from_file(cls, filename: str):
84+
def from_file(cls, filename: str) -> Self:
8485
"""Load the reference tags used for provenance recording."""
8586
if os.path.exists(filename):
8687
logger.debug("Loading tags from %s", filename)
@@ -93,7 +94,7 @@ def from_file(cls, filename: str):
9394
logger.debug("No tags loaded, file %s not present", filename)
9495
return cls()
9596

96-
def set_tag_value(self, section: str, tag: str, value) -> None:
97+
def set_tag_value(self, section: str, tag: str, value: str) -> None:
9798
"""Set the value of a tag in a section.
9899
99100
Parameters
@@ -110,7 +111,7 @@ def set_tag_value(self, section: str, tag: str, value) -> None:
110111

111112
self[section][tag] = value
112113

113-
def set_tag_values(self, tag_values: dict) -> None:
114+
def set_tag_values(self, tag_values: dict[str, dict[str, str]]) -> None:
114115
"""Update tags from dict.
115116
116117
Parameters
@@ -122,7 +123,7 @@ def set_tag_values(self, tag_values: dict) -> None:
122123
for tag, value in tags.items():
123124
self.set_tag_value(section, tag, value)
124125

125-
def get_tag_value(self, section: str, tag: str):
126+
def get_tag_value(self, section: str, tag: str) -> str:
126127
"""Retrieve the value of a tag from a section.
127128
128129
Parameters
@@ -140,21 +141,19 @@ def get_tag_value(self, section: str, tag: str):
140141
if tag not in self[section]:
141142
postfix = f" of {self.source_file}" if self.source_file else ""
142143
msg = f"Tag '{tag}' does not exist in section '{section}'{postfix}"
143-
raise ValueError(
144-
msg,
145-
)
144+
raise ValueError(msg)
146145

147146
return self[section][tag]
148147

149-
def get_tag_values(self, section: str, tags: tuple):
148+
def get_tag_values(self, section: str, tags: tuple) -> tuple[str, ...]:
150149
"""Retrieve the values for a list of tags from a section.
151150
152151
Parameters
153152
----------
154-
section : str
153+
section
155154
Name of the subsection
156-
tags : tuple[str] or list[str]
157-
List or tuple with tag names
155+
tags
156+
Tuple with tag names
158157
"""
159158
return tuple(self.get_tag_value(section, tag) for tag in tags)
160159

0 commit comments

Comments
 (0)