Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ repos:
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.812'
rev: 'v0.990'
hooks:
- id: mypy
additional_dependencies:
- 'types-PyYAML'
- 'types-pkg_resources'
- 'types-requests'
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies:
- esmpy!=8.1.0 # see github.com/ESMValGroup/ESMValCore/issues/1208
- geopy
- iris>=3.2.1
- mypy>=0.990
- nested-lookup
- netcdf4!=1.6.1 # github.com/ESMValGroup/ESMValCore/issues/1723
- pandas
Expand Down
3 changes: 2 additions & 1 deletion esmvalcore/_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from multiprocessing import Pool
from pathlib import Path, PosixPath
from shutil import which
from typing import Optional

import psutil
import yaml
Expand Down Expand Up @@ -709,7 +710,7 @@ def get_independent(self) -> 'TaskSet':
independent_tasks.add(task)
return independent_tasks

def run(self, max_parallel_tasks: int = None) -> None:
def run(self, max_parallel_tasks: Optional[int] = None) -> None:
"""Run tasks.

Parameters
Expand Down
2 changes: 2 additions & 0 deletions esmvalcore/cmor/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Read variable information from CMOR 2 and CMOR 3 tables and make it
easily available for the other components of ESMValTool
"""
from __future__ import annotations

import copy
import errno
import glob
Expand Down
4 changes: 3 additions & 1 deletion esmvalcore/config/_config_validators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""List of config validators."""
from __future__ import annotations

import logging
import os.path
import warnings
Expand Down Expand Up @@ -243,7 +245,7 @@ def validate_diagnostics(
}


def deprecate(func, variable, version: str = None):
def deprecate(func, variable, version: Optional[str] = None):
"""Wrap function to mark variables to be deprecated.

This will give a warning if the function will be/has been deprecated.
Expand Down
16 changes: 10 additions & 6 deletions esmvalcore/config/_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import time
from pathlib import Path
from typing import Union
from typing import Optional, Union

import yaml

Expand All @@ -27,8 +27,10 @@ def _purge_file_handlers(cfg: dict) -> None:
]


def _get_log_files(cfg: dict,
output_dir: Union[os.PathLike, str] = None) -> list:
def _get_log_files(
cfg: dict,
output_dir: Optional[Union[os.PathLike, str]] = None,
) -> list:
"""Initialize log files for the file handlers."""
log_files = []

Expand Down Expand Up @@ -59,9 +61,11 @@ def _update_stream_level(cfg: dict, level=None):
handler['level'] = level.upper()


def configure_logging(cfg_file: Union[os.PathLike, str] = None,
output_dir: Union[os.PathLike, str] = None,
console_log_level: str = None) -> list:
def configure_logging(
cfg_file: Optional[Union[os.PathLike, str]] = None,
output_dir: Optional[Union[os.PathLike, str]] = None,
console_log_level: Optional[str] = None,
) -> list:
"""Configure logging.

Parameters
Expand Down
6 changes: 5 additions & 1 deletion esmvalcore/experimental/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ def _load(self, session: Session) -> RecipeEngine:
config_user=config_user,
recipe_file=self.path)

def run(self, task: str = None, session: Session = None):
def run(
self,
task: Optional[str] = None,
session: Optional[Session] = None,
):
"""Run the recipe.

This function loads the recipe into the ESMValCore recipe format
Expand Down
4 changes: 3 additions & 1 deletion esmvalcore/experimental/recipe_metadata.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""API for recipe metadata."""

from typing import Optional

import pybtex
from pybtex.database.input import bibtex

Expand All @@ -23,7 +25,7 @@ class Contributor:
ORCID url
"""

def __init__(self, name: str, institute: str, orcid: str = None):
def __init__(self, name: str, institute: str, orcid: Optional[str] = None):
self.name = name
self.institute = institute
self.orcid = orcid
Expand Down
11 changes: 8 additions & 3 deletions esmvalcore/experimental/recipe_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class OutputFile():

kind: Optional[str] = None

def __init__(self, path: str, attributes: dict = None):
def __init__(self, path: str, attributes: Optional[dict] = None):
if not attributes:
attributes = {}

Expand Down Expand Up @@ -291,7 +291,7 @@ def references(self) -> tuple:
self._references = tuple(Reference.from_tag(tag) for tag in tags)
return self._references

def _get_derived_path(self, append: str, suffix: str = None):
def _get_derived_path(self, append: str, suffix: Optional[str] = None):
"""Return path of related files.

Parameters
Expand Down Expand Up @@ -325,7 +325,12 @@ def provenance_xml_file(self):
return self._get_derived_path('_provenance', '.xml')

@classmethod
def create(cls, path: str, attributes: dict = None) -> 'OutputFile':
def create(
cls,
path: str,
attributes:
Optional[dict] = None,
) -> 'OutputFile':
"""Construct new instances of OutputFile.

Chooses a derived class if suitable.
Expand Down
4 changes: 2 additions & 2 deletions esmvalcore/experimental/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import re
from pathlib import Path
from typing import Pattern, Tuple, Union
from typing import Optional, Pattern, Tuple, Union

from esmvalcore.config._diagnostics import DIAGNOSTICS

Expand Down Expand Up @@ -41,7 +41,7 @@ def find(self, query: Pattern[str]):
return matches


def get_all_recipes(subdir: str = None) -> list:
def get_all_recipes(subdir: Optional[str] = None) -> list:
"""Return a list of all available recipes.

Parameters
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ include_trailing_comma = true

[mypy]
# see mypy.readthedocs.io/en/stable/command_line.html
implicit_optional = True
ignore_missing_imports = True
files = esmvalcore, tests

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
'pytest-xdist',
'ESMValTool_sample_data==0.0.3',
# MyPy library stubs
'mypy>=0.990',
'types-requests',
'types-pkg_resources',
'types-PyYAML',
Expand Down
6 changes: 4 additions & 2 deletions tests/sample_data/multimodel_statistics/test_multimodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import platform
from itertools import groupby
from pathlib import Path
from typing import Optional

import iris
import numpy as np
Expand Down Expand Up @@ -69,7 +70,7 @@ def fix_metadata(cubes):
cube.coord('air_pressure').bounds = None


def preprocess_data(cubes, time_slice: dict = None):
def preprocess_data(cubes, time_slice: Optional[dict] = None):
"""Regrid the data to the first cube and optional time-slicing."""
# Increase TEST_REVISION anytime you make changes to this function.
if time_slice:
Expand All @@ -92,7 +93,8 @@ def get_cache_key(value):
"""Get a cache key that is hopefully unique enough for unpickling.

If this doesn't avoid problems with unpickling the cached data,
manually clean the pytest cache with the command `pytest --cache-clear`.
manually clean the pytest cache with the command `pytest --cache-
clear`.
"""
py_version = platform.python_version()
return (f'{value}_iris-{iris.__version__}_'
Expand Down