Skip to content

Commit e127f34

Browse files
committed
Fix some new mypy errors
1 parent 01295f2 commit e127f34

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/emsarray/cli/commands/plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(
3333
):
3434
if default is None:
3535
default = {}
36-
type = functools.partial(key_value, value_type=value_type)
36+
type: Callable = functools.partial(key_value, value_type=value_type)
3737
super().__init__(
3838
option_strings, dest, default=default, type=type, **kwargs)
3939

src/emsarray/plot.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import cartopy.crs
1616
from cartopy.feature import GSHHSFeature
1717
from cartopy.mpl import gridliner
18+
from cartopy.mpl.geoaxes import GeoAxes
1819
from matplotlib import animation, patheffects
1920
from matplotlib.artist import Artist
2021
from matplotlib.axes import Axes
@@ -37,7 +38,7 @@
3738
CARTOPY_0_23 = CARTOPY_VERSION >= packaging.version.Version('0.23')
3839

3940

40-
def add_coast(axes: Axes, **kwargs: Any) -> None:
41+
def add_coast(axes: GeoAxes, **kwargs: Any) -> None:
4142
"""
4243
Add coastlines to an :class:`~matplotlib.axes.Axes`.
4344
Some default styles are applied:
@@ -61,7 +62,7 @@ def add_coast(axes: Axes, **kwargs: Any) -> None:
6162
axes.add_feature(coast, **kwargs)
6263

6364

64-
def add_gridlines(axes: Axes, **kwargs: Any) -> gridliner.Gridliner:
65+
def add_gridlines(axes: GeoAxes, **kwargs: Any) -> gridliner.Gridliner:
6566
"""
6667
Add some gridlines to the axes.
6768
@@ -310,7 +311,7 @@ def plot_on_figure(
310311
if projection is None:
311312
projection = cartopy.crs.PlateCarree()
312313

313-
axes = figure.add_subplot(projection=projection)
314+
axes: GeoAxes = figure.add_subplot(projection=projection)
314315
axes.set_aspect(aspect='equal', adjustable='datalim')
315316

316317
if scalar is None and vector is None:

src/emsarray/transect.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import dataclasses
22
from collections.abc import Hashable, Iterable
33
from functools import cached_property
4-
from typing import Any, Callable, Generic, Optional, Union
4+
from typing import Any, Callable, Generic, Optional, Union, cast
55

66
import cfunits
77
import numpy
@@ -228,8 +228,8 @@ def _set_up_axis(self, variable: xarray.DataArray) -> tuple[str, Formatter]:
228228
# Use cfunits to normalize the units to their short symbol form.
229229
# EngFormatter will write 'k{unit}', 'G{unit}', etc
230230
# so unit symbols are required.
231-
units = cfunits.Units(units).formatted()
232-
formatter = EngFormatter(unit=units)
231+
formatted_units = cfunits.Units(units).formatted()
232+
formatter = EngFormatter(unit=formatted_units)
233233

234234
return title, formatter
235235

@@ -746,7 +746,7 @@ def _plot_on_figure(
746746
depth_limit_shallow = up(transect_dataset['depth_bounds'][depth_start])
747747
depth_limit_deep = down(transect_dataset['depth_bounds'][depth_stop])
748748

749-
axes = figure.subplots()
749+
axes = cast(Axes, figure.subplots())
750750
x_title, x_formatter = self._set_up_axis(distance_bounds)
751751
y_title, y_formatter = self._set_up_axis(depth)
752752
axes.set_xlabel(x_title)
@@ -764,7 +764,8 @@ def _plot_on_figure(
764764
if title is not None:
765765
axes.set_title(title)
766766

767-
cmap = colormaps[cmap].copy()
767+
if isinstance(cmap, str):
768+
cmap = colormaps[cmap].copy()
768769
cmap.set_bad(ocean_floor_colour)
769770

770771
if data_array.size != 0:

0 commit comments

Comments
 (0)