|
6 | 6 | import warnings |
7 | 7 | from collections.abc import Callable, Hashable, Iterable, Sequence |
8 | 8 | from functools import cached_property |
9 | | -from typing import TYPE_CHECKING, Any, Generic, Literal, TypeVar, cast |
| 9 | +from typing import TYPE_CHECKING, Any, Literal, cast |
10 | 10 |
|
11 | 11 | import numpy |
12 | 12 | import shapely |
|
38 | 38 | logger = logging.getLogger(__name__) |
39 | 39 |
|
40 | 40 |
|
41 | | -#: Some type that can enumerate the different :ref:`grid types <grids>` |
42 | | -#: present in a dataset. |
43 | | -#: This can be an :class:`enum.Enum` listing each different kind of grid. |
44 | | -#: |
45 | | -#: :data:`Index` values will be included in the feature properties |
46 | | -#: of exported geometry from :mod:`emsarray.operations.geometry`. |
47 | | -#: If the index type includes the grid kind, |
48 | | -#: the grid kind needs to be JSON serializable. |
49 | | -#: The easiest way to achieve this is to make your GridKind type subclass :class:`str`: |
50 | | -#: |
51 | | -#: .. code-block:: python |
52 | | -#: |
53 | | -#: class MyGridKind(str, enum.Enum): |
54 | | -#: face = 'face' |
55 | | -#: edge = 'edge' |
56 | | -#: node = 'node' |
57 | | -#: |
58 | | -#: For cases where the convention only supports a single grid, |
59 | | -#: a singleton enum can be used. |
60 | | -#: |
61 | | -#: More esoteric cases involving datasets with a potentially unbounded numbers of grids |
62 | | -#: can use a type that supports this instead. |
63 | | -GridKind = TypeVar("GridKind") |
64 | | - |
65 | | -#: An :ref:`index <indexing>` to a specific point on a grid in this convention. |
66 | | -#: For conventions with :ref:`multiple grids <grids>` (e.g. cells, edges, and nodes), |
67 | | -#: this should be a tuple whos first element is :data:`.GridKind`. |
68 | | -#: For conventions with a single grid, :data:`.GridKind` is not required. |
69 | | -Index = TypeVar("Index") |
70 | | - |
71 | | - |
72 | 41 | @dataclasses.dataclass |
73 | | -class SpatialIndexItem(Generic[Index]): |
| 42 | +class SpatialIndexItem[Index]: |
74 | 43 | """Information about an item in the :class:`~shapely.strtree.STRtree` |
75 | 44 | spatial index for a dataset. |
76 | 45 |
|
@@ -124,7 +93,7 @@ class Specificity(enum.IntEnum): |
124 | 93 | HIGH = 30 |
125 | 94 |
|
126 | 95 |
|
127 | | -class Convention(abc.ABC, Generic[GridKind, Index]): |
| 96 | +class Convention[GridKind, Index](abc.ABC): |
128 | 97 | """ |
129 | 98 | Each supported geometry convention represents data differently. |
130 | 99 | The :class:`Convention` class abstracts these differences away, |
@@ -1749,7 +1718,7 @@ def hash_geometry(self, hash: "hashlib._Hash") -> None: |
1749 | 1718 | hash_attributes(hash, data_array.attrs) |
1750 | 1719 |
|
1751 | 1720 |
|
1752 | | -class DimensionConvention(Convention[GridKind, Index]): |
| 1721 | +class DimensionConvention[GridKind, Index](Convention[GridKind, Index]): |
1753 | 1722 | """ |
1754 | 1723 | A Convention subclass where different grid kinds |
1755 | 1724 | are always defined on unique sets of dimension. |
|
0 commit comments