Skip to content

Commit

Permalink
Implement suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
bouweandela committed Jun 26, 2024
1 parent 7f84689 commit 5a286e8
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
3 changes: 2 additions & 1 deletion benchmarks/asv_delegated_conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def name(self):
def _update_info(self) -> None:
"""Make sure class properties reflect the actual environment being used."""
# Follow symlink if it has been created.
actual_path = Path(self._path).resolve() # type: ignore[has-type]
self._path: str
actual_path = Path(self._path).resolve()
self._path = str(actual_path)

# Get custom environment's Python version if it exists yet.
Expand Down
4 changes: 2 additions & 2 deletions lib/iris/analysis/maths.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,12 +558,12 @@ def exponentiate(cube, exponent, in_place=False):
)
if cube.has_lazy_data():

def power(data):
def power(data, out=None):
return operator.pow(data, exponent)

else:

def power(data, out=None): # type: ignore[misc]
def power(data, out=None):
return np.power(data, exponent, out)

return _math_op_common(
Expand Down
5 changes: 3 additions & 2 deletions lib/iris/experimental/ugrid/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import dask.array as da
import numpy as np

from iris.common.metadata import CoordMetadata
from iris.cube import Cube


Expand Down Expand Up @@ -93,7 +94,7 @@ def recombine_submeshes(

result_metadata = None
result_dtype = None
indexcoord_metadata = None
indexcoord_metadata: CoordMetadata | None = None
for i_sub, cube in enumerate(submesh_cubes):
sub_str = f'Submesh cube #{i_sub + 1}/{len(submesh_cubes)}, "{cube.name()}"'

Expand Down Expand Up @@ -197,7 +198,7 @@ def recombine_submeshes(
if indexcoord_metadata is None:
# Store first occurrence (from first region-cube)
indexcoord_metadata = sub_metadata
elif sub_metadata != indexcoord_metadata: # type: ignore[unreachable]
elif sub_metadata != indexcoord_metadata:
# This code is unreachable, is this a bug?
# Compare subsequent occurrences (from other region-cubes)
err = (
Expand Down
8 changes: 2 additions & 6 deletions lib/iris/fileformats/netcdf/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
"""

from collections.abc import Iterable, Mapping
from collections.abc import Iterable, Iterator, Mapping
from contextlib import contextmanager
from copy import deepcopy
from enum import Enum, auto
import threading
from typing import Iterator
import warnings

import numpy as np
Expand Down Expand Up @@ -765,10 +764,7 @@ def set(
raise ValueError(msg)
dim_chunks = self.var_dim_chunksizes.setdefault(var_name, {})
for dim_name, chunksize in dimension_chunksizes.items():
if not (
isinstance(dim_name, str) # type: ignore[redundant-expr]
and isinstance(chunksize, int)
):
if not (isinstance(dim_name, str) and isinstance(chunksize, int)):
msg = (
"'dimension_chunksizes' kwargs should be a dict "
f"of `str: int` pairs, not {dimension_chunksizes!r}."
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/fileformats/netcdf/saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2291,7 +2291,7 @@ def _increment_name(self, varname):

def _lazy_stream_data(
self,
data: np.ndarray | da.Array,
data: np.typing.ArrayLike,
cf_var: CFVariable,
) -> None:
if hasattr(data, "shape") and data.shape == (1,) + cf_var.shape:
Expand Down
10 changes: 6 additions & 4 deletions lib/iris/fileformats/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,12 @@ def _ensure_aligned(regrid_cache, src_cube, target_cube):
return result_cube


_loader_attrs = ("field_generator", "field_generator_kwargs", "converter")


class Loader(collections.namedtuple("Loader", _loader_attrs)): # type: ignore[misc]
class Loader(
collections.namedtuple(
"Loader",
("field_generator", "field_generator_kwargs", "converter"),
)
):
def __new__(cls, field_generator, field_generator_kwargs, converter):
"""Create a definition of a field-based Cube loader.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ ignore = [
ignore_missing_imports = true
warn_unused_configs = true
warn_unreachable = true
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
enable_error_code = ["ignore-without-code", "truthy-bool"]
exclude = [
'noxfile\.py',
'docs/src/conf\.py'
Expand Down

0 comments on commit 5a286e8

Please sign in to comment.