Skip to content

Commit

Permalink
Remove from __future__ import annotations
Browse files Browse the repository at this point in the history
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/
  • Loading branch information
mx-moth committed Jan 11, 2024
1 parent faa5933 commit fc19617
Show file tree
Hide file tree
Showing 21 changed files with 27 additions and 66 deletions.
2 changes: 0 additions & 2 deletions src/emsarray/accessors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import logging

import xarray
Expand Down
18 changes: 8 additions & 10 deletions src/emsarray/conventions/_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import abc
import dataclasses
import enum
Expand Down Expand Up @@ -869,7 +867,7 @@ def make_linear(self, data_array: xarray.DataArray) -> xarray.DataArray:

@cached_property # type: ignore
@_requires_plot
def data_crs(self) -> CRS:
def data_crs(self) -> 'CRS':
"""
The coordinate reference system that coordinates in this dataset are
defined in.
Expand All @@ -883,7 +881,7 @@ def data_crs(self) -> CRS:
@_requires_plot
def plot_on_figure(
self,
figure: Figure,
figure: 'Figure',
scalar: Optional[DataArrayOrName] = None,
vector: Optional[tuple[DataArrayOrName, DataArrayOrName]] = None,
title: Optional[str] = None,
Expand Down Expand Up @@ -963,13 +961,13 @@ def plot(self, *args: Any, **kwargs: Any) -> None:
@_requires_plot
def animate_on_figure(
self,
figure: Figure,
figure: 'Figure',
scalar: Optional[DataArrayOrName] = None,
vector: Optional[tuple[DataArrayOrName, DataArrayOrName]] = None,
coordinate: Optional[DataArrayOrName] = None,
title: Optional[Union[str, Callable[[Any], str]]] = None,
**kwargs: Any,
) -> FuncAnimation:
) -> 'FuncAnimation':
"""
Make an animated plot of a data array.
Expand Down Expand Up @@ -1066,7 +1064,7 @@ def make_poly_collection(
self,
data_array: Optional[DataArrayOrName] = None,
**kwargs: Any,
) -> PolyCollection:
) -> 'PolyCollection':
"""
Make a :class:`~matplotlib.collections.PolyCollection`
from the geometry of this :class:`~xarray.Dataset`.
Expand Down Expand Up @@ -1143,7 +1141,7 @@ def make_patch_collection(
self,
data_array: Optional[DataArrayOrName] = None,
**kwargs: Any,
) -> PolyCollection:
) -> 'PolyCollection':
warnings.warn(
"Convention.make_patch_collection has been renamed to "
"Convention.make_poly_collection, and now returns a PolyCollection",
Expand All @@ -1154,11 +1152,11 @@ def make_patch_collection(
@_requires_plot
def make_quiver(
self,
axes: Axes,
axes: 'Axes',
u: Optional[DataArrayOrName] = None,
v: Optional[DataArrayOrName] = None,
**kwargs: Any,
) -> Quiver:
) -> 'Quiver':
"""
Make a :class:`matplotlib.quiver.Quiver` instance to plot vector data.
Expand Down
2 changes: 0 additions & 2 deletions src/emsarray/conventions/_registry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import logging
import sys
import warnings
Expand Down
4 changes: 1 addition & 3 deletions src/emsarray/conventions/arakawa_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
`Arakawa grids <https://en.wikipedia.org/wiki/Arakawa_grids>`_ on Wikipedia
"""
from __future__ import annotations

import enum
import logging
from collections.abc import Hashable, Sequence
Expand Down Expand Up @@ -119,7 +117,7 @@ class ArakawaCGridKind(str, enum.Enum):
#: :meta hide-value:
node = 'node'

def __call__(self, j: int, i: int) -> ArakawaCIndex:
def __call__(self, j: int, i: int) -> 'ArakawaCIndex':
return (self, j, i)


Expand Down
2 changes: 0 additions & 2 deletions src/emsarray/conventions/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
Datasets following the CF conventions with gridded datasets.
Both 1D coordinates and 2D coordinates are supported.
"""
from __future__ import annotations

import abc
import enum
import itertools
Expand Down
2 changes: 0 additions & 2 deletions src/emsarray/conventions/shoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
--------
`SHOC documentation <https://research.csiro.au/cem/software/ems/hydro/strucutured-shoc/>`_
"""
from __future__ import annotations

import logging
from collections.abc import Hashable
from functools import cached_property
Expand Down
14 changes: 9 additions & 5 deletions src/emsarray/conventions/ugrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
--------
`UGRID conventions <https://ugrid-conventions.github.io/ugrid-conventions/>`_
"""
from __future__ import annotations

import enum
import logging
import pathlib
Expand Down Expand Up @@ -39,7 +37,10 @@ def _split_coord(attr: str) -> tuple[str, str]:
return (x, y)


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


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

@cached_property
def dimension_for_grid_kind(self) -> dict[UGridKind, Hashable]:
def dimension_for_grid_kind(self) -> dict['UGridKind', Hashable]:
"""
Get the dimension names for each of the grid types in this dataset.
"""
Expand Down
2 changes: 0 additions & 2 deletions src/emsarray/masking.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
Masks are used when clipping datasets to a smaller geographic subset,
such as :meth:`.Convention.clip`.
"""
from __future__ import annotations

import functools
import itertools
import logging
Expand Down
12 changes: 4 additions & 8 deletions src/emsarray/plot.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
from __future__ import annotations

from collections.abc import Iterable
from typing import TYPE_CHECKING, Any, Callable, Literal, Optional, Union
from typing import Any, Callable, Literal, Optional, Union

import numpy
import xarray

from emsarray import conventions
from emsarray.exceptions import NoSuchCoordinateError
from emsarray.types import Landmark
from emsarray.utils import requires_extra

if TYPE_CHECKING:
from .conventions import Convention

try:
import cartopy.crs
from cartopy.feature import GSHHSFeature
Expand Down Expand Up @@ -263,7 +259,7 @@ def make_plot_title(
@_requires_plot
def plot_on_figure(
figure: Figure,
convention: Convention,
convention: 'conventions.Convention',
*,
scalar: Optional[xarray.DataArray] = None,
vector: Optional[tuple[xarray.DataArray, xarray.DataArray]] = None,
Expand Down Expand Up @@ -354,7 +350,7 @@ def plot_on_figure(
@_requires_plot
def animate_on_figure(
figure: Figure,
convention: Convention,
convention: 'conventions.Convention',
*,
coordinate: xarray.DataArray,
scalar: Optional[xarray.DataArray] = None,
Expand Down
11 changes: 4 additions & 7 deletions src/emsarray/state.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
"""
Dataclass for containing state required for emsarray
"""
from __future__ import annotations

import dataclasses
from typing import TYPE_CHECKING, Final, Optional, cast
from typing import Final, Optional, cast

import xarray

if TYPE_CHECKING:
from emsarray.conventions._base import Convention
from emsarray import conventions


@dataclasses.dataclass
Expand All @@ -20,7 +17,7 @@ class State:
to avoid convention autodetection.
"""
dataset: xarray.Dataset
convention: Optional[Convention] = None
convention: Optional['conventions.Convention'] = None

accessor_name: Final[str] = "_emsarray_state"

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

def bind_convention(self, convention: Convention) -> None:
def bind_convention(self, convention: 'conventions.Convention') -> None:
"""
Bind a Convention instance to this Dataset.
If the Dataset is already bound, an error is raised.
Expand Down
2 changes: 0 additions & 2 deletions src/emsarray/transect.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import dataclasses
from collections.abc import Hashable, Iterable
from functools import cached_property
Expand Down
4 changes: 1 addition & 3 deletions src/emsarray/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
--------
:mod:`emsarray.operations`
"""
from __future__ import annotations

import datetime
import functools
import itertools
Expand Down Expand Up @@ -51,7 +49,7 @@ class PerfTimer:
def __init__(self) -> None:
self.running = False

def __enter__(self) -> PerfTimer:
def __enter__(self) -> 'PerfTimer':
if self.running:
raise RuntimeError("Timer is already running")
self.running = True
Expand Down
2 changes: 0 additions & 2 deletions tests/cli/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import argparse
import json
from pathlib import Path
Expand Down
2 changes: 0 additions & 2 deletions tests/conventions/test_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import dataclasses
import enum
import pathlib
Expand Down
2 changes: 0 additions & 2 deletions tests/conventions/test_cfgrid1d.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import json
import pathlib

Expand Down
2 changes: 0 additions & 2 deletions tests/conventions/test_cfgrid2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
Instead of writing two identical test suites,
the SHOC simple convention is used to test both.
"""
from __future__ import annotations

import itertools
import json
import pathlib
Expand Down
2 changes: 0 additions & 2 deletions tests/conventions/test_shoc_standard.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import itertools
import json
import pathlib
Expand Down
2 changes: 0 additions & 2 deletions tests/conventions/test_ugrid.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import json
import pathlib
import warnings
Expand Down
2 changes: 0 additions & 2 deletions tests/masking/test_mask_dataset.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import pathlib

import netCDF4
Expand Down
2 changes: 0 additions & 2 deletions tests/masking/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import pathlib

import netCDF4
Expand Down
2 changes: 0 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import abc
import contextlib
import itertools
Expand Down

0 comments on commit fc19617

Please sign in to comment.