From 4254b4af33843f711459e5242018cd1d678ad3a0 Mon Sep 17 00:00:00 2001 From: crusaderky Date: Fri, 4 Oct 2019 23:17:56 +0100 Subject: [PATCH] Lint (#3373) * raise exception instance, not class * isort * isort * Bump mypy version --- .pre-commit-config.yaml | 2 +- asv_bench/benchmarks/__init__.py | 2 +- asv_bench/benchmarks/dataset_io.py | 2 +- ci/requirements/py36-min-all-deps.yml | 2 +- ci/requirements/py36.yml | 2 +- ci/requirements/py37-windows.yml | 2 +- ci/requirements/py37.yml | 2 +- properties/test_encode_decode.py | 2 +- xarray/backends/common.py | 12 ++++++------ xarray/backends/file_manager.py | 6 +++--- xarray/coding/cftime_offsets.py | 2 +- xarray/coding/variables.py | 4 ++-- xarray/core/common.py | 2 +- xarray/core/concat.py | 2 +- xarray/core/coordinates.py | 8 ++++---- xarray/core/dataset.py | 4 ++-- xarray/tests/test_backends.py | 2 +- xarray/tests/test_concat.py | 1 + 18 files changed, 30 insertions(+), 29 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a9fb3d699ff..502120cd5dc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,7 @@ repos: hooks: - id: flake8 - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.720 # Must match ci/requirements/*.yml + rev: v0.730 # Must match ci/requirements/*.yml hooks: - id: mypy # run these occasionally, ref discussion https://github.com/pydata/xarray/pull/3194 diff --git a/asv_bench/benchmarks/__init__.py b/asv_bench/benchmarks/__init__.py index 1ffd3afa4ae..b0adb2feafd 100644 --- a/asv_bench/benchmarks/__init__.py +++ b/asv_bench/benchmarks/__init__.py @@ -18,7 +18,7 @@ def requires_dask(): try: import dask # noqa: F401 except ImportError: - raise NotImplementedError + raise NotImplementedError() def randn(shape, frac_nan=None, chunks=None, seed=0): diff --git a/asv_bench/benchmarks/dataset_io.py b/asv_bench/benchmarks/dataset_io.py index c1567d0b513..d1ffbc34706 100644 --- a/asv_bench/benchmarks/dataset_io.py +++ b/asv_bench/benchmarks/dataset_io.py @@ -458,7 +458,7 @@ def setup(self): try: import distributed except ImportError: - raise NotImplementedError + raise NotImplementedError() self.client = distributed.Client() self.write = create_delayed_write() diff --git a/ci/requirements/py36-min-all-deps.yml b/ci/requirements/py36-min-all-deps.yml index 1829f2a11e3..affbf8637fd 100644 --- a/ci/requirements/py36-min-all-deps.yml +++ b/ci/requirements/py36-min-all-deps.yml @@ -20,7 +20,7 @@ dependencies: - iris=2.2.0 - lxml=4.4.1 # optional dep of pydap - matplotlib=3.1.1 - - mypy==0.720 # Must match .pre-commit-config.yaml + - mypy==0.730 # Must match .pre-commit-config.yaml - nc-time-axis=1.2.0 - netcdf4=1.5.1.2 - numba=0.45.1 diff --git a/ci/requirements/py36.yml b/ci/requirements/py36.yml index 187a9c79fbf..bdb649f6f1b 100644 --- a/ci/requirements/py36.yml +++ b/ci/requirements/py36.yml @@ -20,7 +20,7 @@ dependencies: - iris>=1.10 - lxml # optional dep of pydap - matplotlib - - mypy==0.720 # Must match .pre-commit-config.yaml + - mypy==0.730 # Must match .pre-commit-config.yaml - nc-time-axis - netcdf4 - numba diff --git a/ci/requirements/py37-windows.yml b/ci/requirements/py37-windows.yml index 24297327393..79b54030bc6 100644 --- a/ci/requirements/py37-windows.yml +++ b/ci/requirements/py37-windows.yml @@ -20,7 +20,7 @@ dependencies: - iris>=1.10 - lxml # optional dep of pydap - matplotlib - - mypy==0.720 # Must match .pre-commit-config.yaml + - mypy==0.730 # Must match .pre-commit-config.yaml - nc-time-axis - netcdf4 - numba diff --git a/ci/requirements/py37.yml b/ci/requirements/py37.yml index 5a328c64cf9..a4fe2d82a6f 100644 --- a/ci/requirements/py37.yml +++ b/ci/requirements/py37.yml @@ -20,7 +20,7 @@ dependencies: - iris>=1.10 - lxml # optional dep of pydap - matplotlib - - mypy==0.720 # Must match .pre-commit-config.yaml + - mypy==0.730 # Must match .pre-commit-config.yaml - nc-time-axis - netcdf4 - numba diff --git a/properties/test_encode_decode.py b/properties/test_encode_decode.py index c7839608981..011e7a922d1 100644 --- a/properties/test_encode_decode.py +++ b/properties/test_encode_decode.py @@ -4,7 +4,7 @@ These ones pass, just as you'd hope! """ -import pytest +import pytest # isort:skip pytest.importorskip("hypothesis") diff --git a/xarray/backends/common.py b/xarray/backends/common.py index 455b77907f9..72c7c5a517f 100644 --- a/xarray/backends/common.py +++ b/xarray/backends/common.py @@ -88,13 +88,13 @@ def __len__(self): return len(self.variables) def get_dimensions(self): # pragma: no cover - raise NotImplementedError + raise NotImplementedError() def get_attrs(self): # pragma: no cover - raise NotImplementedError + raise NotImplementedError() def get_variables(self): # pragma: no cover - raise NotImplementedError + raise NotImplementedError() def get_encoding(self): return {} @@ -247,13 +247,13 @@ def encode_attribute(self, a): return a def set_dimension(self, d, l): # pragma: no cover - raise NotImplementedError + raise NotImplementedError() def set_attribute(self, k, v): # pragma: no cover - raise NotImplementedError + raise NotImplementedError() def set_variable(self, k, v): # pragma: no cover - raise NotImplementedError + raise NotImplementedError() def store_dataset(self, dataset): """ diff --git a/xarray/backends/file_manager.py b/xarray/backends/file_manager.py index dfd38ff9f48..eac28852281 100644 --- a/xarray/backends/file_manager.py +++ b/xarray/backends/file_manager.py @@ -28,7 +28,7 @@ class FileManager: def acquire(self, needs_lock=True): """Acquire the file object from this manager.""" - raise NotImplementedError + raise NotImplementedError() def acquire_context(self, needs_lock=True): """Context manager for acquiring a file. Yields a file object. @@ -37,11 +37,11 @@ def acquire_context(self, needs_lock=True): (i.e., removes it from any cache) if an exception is raised from the context. It *does not* automatically close the file. """ - raise NotImplementedError + raise NotImplementedError() def close(self, needs_lock=True): """Close the file object associated with this manager, if needed.""" - raise NotImplementedError + raise NotImplementedError() class CachingFileManager(FileManager): diff --git a/xarray/coding/cftime_offsets.py b/xarray/coding/cftime_offsets.py index 223eff571ae..d7841fd43f8 100644 --- a/xarray/coding/cftime_offsets.py +++ b/xarray/coding/cftime_offsets.py @@ -181,7 +181,7 @@ def _get_day_of_month(other, day_option): elif day_option is None: # Note: unlike `_shift_month`, _get_day_of_month does not # allow day_option = None - raise NotImplementedError + raise NotImplementedError() else: raise ValueError(day_option) diff --git a/xarray/coding/variables.py b/xarray/coding/variables.py index f54ae7867d8..7adaca4e9bc 100644 --- a/xarray/coding/variables.py +++ b/xarray/coding/variables.py @@ -36,12 +36,12 @@ class VariableCoder: def encode(self, variable, name=None): # pragma: no cover # type: (Variable, Any) -> Variable """Convert an encoded variable to a decoded variable.""" - raise NotImplementedError + raise NotImplementedError() def decode(self, variable, name=None): # pragma: no cover # type: (Variable, Any) -> Variable """Convert an decoded variable to a encoded variable.""" - raise NotImplementedError + raise NotImplementedError() class _ElementwiseFunctionArray(indexing.ExplicitlyIndexedNDArrayMixin): diff --git a/xarray/core/common.py b/xarray/core/common.py index a8fac245c02..bf15e9907c4 100644 --- a/xarray/core/common.py +++ b/xarray/core/common.py @@ -1216,7 +1216,7 @@ def __exit__(self, exc_type, exc_value, traceback) -> None: def __getitem__(self, value): # implementations of this class should implement this method - raise NotImplementedError + raise NotImplementedError() def full_like(other, fill_value, dtype: DTypeLike = None): diff --git a/xarray/core/concat.py b/xarray/core/concat.py index e68c247d880..5c9beda3f74 100644 --- a/xarray/core/concat.py +++ b/xarray/core/concat.py @@ -4,7 +4,7 @@ from . import dtypes, utils from .alignment import align -from .merge import unique_variable, _VALID_COMPAT +from .merge import _VALID_COMPAT, unique_variable from .variable import IndexVariable, Variable, as_variable from .variable import concat as concat_vars diff --git a/xarray/core/coordinates.py b/xarray/core/coordinates.py index 430e507396b..ce17973866e 100644 --- a/xarray/core/coordinates.py +++ b/xarray/core/coordinates.py @@ -6,8 +6,8 @@ Hashable, Iterator, Mapping, - Set, Sequence, + Set, Tuple, Union, cast, @@ -17,7 +17,7 @@ from . import formatting, indexing from .indexes import Indexes -from .merge import merge_coords, merge_coordinates_without_align +from .merge import merge_coordinates_without_align, merge_coords from .utils import Frozen, ReprObject, either_dict_or_kwargs from .variable import Variable @@ -53,10 +53,10 @@ def indexes(self) -> Indexes: @property def variables(self): - raise NotImplementedError + raise NotImplementedError() def _update_coords(self, coords, indexes): - raise NotImplementedError + raise NotImplementedError() def __iter__(self) -> Iterator["Hashable"]: # needs to be in the same order as the dataset variables diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 71025cb3040..d394e05b07a 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -64,8 +64,8 @@ from .merge import ( dataset_merge_method, dataset_update_method, - merge_data_and_coords, merge_coordinates_without_align, + merge_data_and_coords, ) from .options import OPTIONS, _get_keep_attrs from .pycompat import dask_array_type @@ -76,9 +76,9 @@ decode_numpy_dict_values, either_dict_or_kwargs, hashable, - maybe_wrap_array, is_dict_like, is_list_like, + maybe_wrap_array, ) from .variable import IndexVariable, Variable, as_variable, broadcast_variables diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index 87958824c7b..4645b4db796 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -237,7 +237,7 @@ class DatasetIOBase: file_format = None # type: Optional[str] def create_store(self): - raise NotImplementedError + raise NotImplementedError() @contextlib.contextmanager def roundtrip( diff --git a/xarray/tests/test_concat.py b/xarray/tests/test_concat.py index 00428f70966..d2635e4451a 100644 --- a/xarray/tests/test_concat.py +++ b/xarray/tests/test_concat.py @@ -6,6 +6,7 @@ from xarray import DataArray, Dataset, Variable, concat from xarray.core import dtypes, merge + from . import ( InaccessibleArray, assert_array_equal,