Skip to content

Commit fc19617

Browse files
committed
Remove from __future__ import annotations
Python does not appear to be heading in this direction and is considering other approaches to annotations. This future import is dropped so that we stop relying on a feature that may not come to pass. See also #109, https://peps.python.org/pep-0649/
1 parent faa5933 commit fc19617

File tree

21 files changed

+27
-66
lines changed

21 files changed

+27
-66
lines changed

src/emsarray/accessors.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
import logging
42

53
import xarray

src/emsarray/conventions/_base.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
import abc
42
import dataclasses
53
import enum
@@ -869,7 +867,7 @@ def make_linear(self, data_array: xarray.DataArray) -> xarray.DataArray:
869867

870868
@cached_property # type: ignore
871869
@_requires_plot
872-
def data_crs(self) -> CRS:
870+
def data_crs(self) -> 'CRS':
873871
"""
874872
The coordinate reference system that coordinates in this dataset are
875873
defined in.
@@ -883,7 +881,7 @@ def data_crs(self) -> CRS:
883881
@_requires_plot
884882
def plot_on_figure(
885883
self,
886-
figure: Figure,
884+
figure: 'Figure',
887885
scalar: Optional[DataArrayOrName] = None,
888886
vector: Optional[tuple[DataArrayOrName, DataArrayOrName]] = None,
889887
title: Optional[str] = None,
@@ -963,13 +961,13 @@ def plot(self, *args: Any, **kwargs: Any) -> None:
963961
@_requires_plot
964962
def animate_on_figure(
965963
self,
966-
figure: Figure,
964+
figure: 'Figure',
967965
scalar: Optional[DataArrayOrName] = None,
968966
vector: Optional[tuple[DataArrayOrName, DataArrayOrName]] = None,
969967
coordinate: Optional[DataArrayOrName] = None,
970968
title: Optional[Union[str, Callable[[Any], str]]] = None,
971969
**kwargs: Any,
972-
) -> FuncAnimation:
970+
) -> 'FuncAnimation':
973971
"""
974972
Make an animated plot of a data array.
975973
@@ -1066,7 +1064,7 @@ def make_poly_collection(
10661064
self,
10671065
data_array: Optional[DataArrayOrName] = None,
10681066
**kwargs: Any,
1069-
) -> PolyCollection:
1067+
) -> 'PolyCollection':
10701068
"""
10711069
Make a :class:`~matplotlib.collections.PolyCollection`
10721070
from the geometry of this :class:`~xarray.Dataset`.
@@ -1143,7 +1141,7 @@ def make_patch_collection(
11431141
self,
11441142
data_array: Optional[DataArrayOrName] = None,
11451143
**kwargs: Any,
1146-
) -> PolyCollection:
1144+
) -> 'PolyCollection':
11471145
warnings.warn(
11481146
"Convention.make_patch_collection has been renamed to "
11491147
"Convention.make_poly_collection, and now returns a PolyCollection",
@@ -1154,11 +1152,11 @@ def make_patch_collection(
11541152
@_requires_plot
11551153
def make_quiver(
11561154
self,
1157-
axes: Axes,
1155+
axes: 'Axes',
11581156
u: Optional[DataArrayOrName] = None,
11591157
v: Optional[DataArrayOrName] = None,
11601158
**kwargs: Any,
1161-
) -> Quiver:
1159+
) -> 'Quiver':
11621160
"""
11631161
Make a :class:`matplotlib.quiver.Quiver` instance to plot vector data.
11641162

src/emsarray/conventions/_registry.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
import logging
42
import sys
53
import warnings

src/emsarray/conventions/arakawa_c.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
`Arakawa grids <https://en.wikipedia.org/wiki/Arakawa_grids>`_ on Wikipedia
77
88
"""
9-
from __future__ import annotations
10-
119
import enum
1210
import logging
1311
from collections.abc import Hashable, Sequence
@@ -119,7 +117,7 @@ class ArakawaCGridKind(str, enum.Enum):
119117
#: :meta hide-value:
120118
node = 'node'
121119

122-
def __call__(self, j: int, i: int) -> ArakawaCIndex:
120+
def __call__(self, j: int, i: int) -> 'ArakawaCIndex':
123121
return (self, j, i)
124122

125123

src/emsarray/conventions/grid.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
Datasets following the CF conventions with gridded datasets.
33
Both 1D coordinates and 2D coordinates are supported.
44
"""
5-
from __future__ import annotations
6-
75
import abc
86
import enum
97
import itertools

src/emsarray/conventions/shoc.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
--------
1515
`SHOC documentation <https://research.csiro.au/cem/software/ems/hydro/strucutured-shoc/>`_
1616
"""
17-
from __future__ import annotations
18-
1917
import logging
2018
from collections.abc import Hashable
2119
from functools import cached_property

src/emsarray/conventions/ugrid.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
--------
66
`UGRID conventions <https://ugrid-conventions.github.io/ugrid-conventions/>`_
77
"""
8-
from __future__ import annotations
9-
108
import enum
119
import logging
1210
import pathlib
@@ -39,7 +37,10 @@ def _split_coord(attr: str) -> tuple[str, str]:
3937
return (x, y)
4038

4139

42-
def buffer_faces(face_indices: numpy.ndarray, topology: Mesh2DTopology) -> numpy.ndarray:
40+
def buffer_faces(
41+
face_indices: numpy.ndarray,
42+
topology: 'Mesh2DTopology',
43+
) -> numpy.ndarray:
4344
"""
4445
When clipping a dataset to a region, including a buffer of extra faces
4546
around the included faces is desired. Given an array of face indices,
@@ -68,7 +69,10 @@ def buffer_faces(face_indices: numpy.ndarray, topology: Mesh2DTopology) -> numpy
6869
return cast(numpy.ndarray, numpy.fromiter(included_faces, dtype=topology.sensible_dtype))
6970

7071

71-
def mask_from_face_indices(face_indices: numpy.ndarray, topology: Mesh2DTopology) -> xarray.Dataset:
72+
def mask_from_face_indices(
73+
face_indices: numpy.ndarray,
74+
topology: 'Mesh2DTopology',
75+
) -> xarray.Dataset:
7276
"""
7377
Make a mask dataset from a list of face indices.
7478
This mask can later be applied using :meth:`~.Convention.apply_clip_mask`.
@@ -868,7 +872,7 @@ def _face_and_node_pair_iter(self) -> Iterable[tuple[int, list[tuple[int, int]]]
868872
yield face_index, list(utils.pairwise(node_indices))
869873

870874
@cached_property
871-
def dimension_for_grid_kind(self) -> dict[UGridKind, Hashable]:
875+
def dimension_for_grid_kind(self) -> dict['UGridKind', Hashable]:
872876
"""
873877
Get the dimension names for each of the grid types in this dataset.
874878
"""

src/emsarray/masking.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
Masks are used when clipping datasets to a smaller geographic subset,
44
such as :meth:`.Convention.clip`.
55
"""
6-
from __future__ import annotations
7-
86
import functools
97
import itertools
108
import logging

src/emsarray/plot.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
from __future__ import annotations
2-
31
from collections.abc import Iterable
4-
from typing import TYPE_CHECKING, Any, Callable, Literal, Optional, Union
2+
from typing import Any, Callable, Literal, Optional, Union
53

64
import numpy
75
import xarray
86

7+
from emsarray import conventions
98
from emsarray.exceptions import NoSuchCoordinateError
109
from emsarray.types import Landmark
1110
from emsarray.utils import requires_extra
1211

13-
if TYPE_CHECKING:
14-
from .conventions import Convention
15-
1612
try:
1713
import cartopy.crs
1814
from cartopy.feature import GSHHSFeature
@@ -263,7 +259,7 @@ def make_plot_title(
263259
@_requires_plot
264260
def plot_on_figure(
265261
figure: Figure,
266-
convention: Convention,
262+
convention: 'conventions.Convention',
267263
*,
268264
scalar: Optional[xarray.DataArray] = None,
269265
vector: Optional[tuple[xarray.DataArray, xarray.DataArray]] = None,
@@ -354,7 +350,7 @@ def plot_on_figure(
354350
@_requires_plot
355351
def animate_on_figure(
356352
figure: Figure,
357-
convention: Convention,
353+
convention: 'conventions.Convention',
358354
*,
359355
coordinate: xarray.DataArray,
360356
scalar: Optional[xarray.DataArray] = None,

src/emsarray/state.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
"""
22
Dataclass for containing state required for emsarray
33
"""
4-
from __future__ import annotations
5-
64
import dataclasses
7-
from typing import TYPE_CHECKING, Final, Optional, cast
5+
from typing import Final, Optional, cast
86

97
import xarray
108

11-
if TYPE_CHECKING:
12-
from emsarray.conventions._base import Convention
9+
from emsarray import conventions
1310

1411

1512
@dataclasses.dataclass
@@ -20,7 +17,7 @@ class State:
2017
to avoid convention autodetection.
2118
"""
2219
dataset: xarray.Dataset
23-
convention: Optional[Convention] = None
20+
convention: Optional['conventions.Convention'] = None
2421

2522
accessor_name: Final[str] = "_emsarray_state"
2623

@@ -32,7 +29,7 @@ def get(cls, dataset: xarray.Dataset) -> "State":
3229
"""
3330
return cast(State, getattr(dataset, State.accessor_name))
3431

35-
def bind_convention(self, convention: Convention) -> None:
32+
def bind_convention(self, convention: 'conventions.Convention') -> None:
3633
"""
3734
Bind a Convention instance to this Dataset.
3835
If the Dataset is already bound, an error is raised.

0 commit comments

Comments
 (0)