Skip to content

Commit d6671dd

Browse files
authored
Fix some typing errors in DuckArrayModule (#7296)
* Fix some typing errors in DuckArrayModule * Update pycompat.py * Update pycompat.py
1 parent 9dd3c1b commit d6671dd

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

xarray/core/pycompat.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from __future__ import annotations
22

33
from importlib import import_module
4-
from typing import Any, Literal
4+
from types import ModuleType
5+
from typing import TYPE_CHECKING, Any, Literal, Type
56

67
import numpy as np
78
from packaging.version import Version
@@ -10,7 +11,9 @@
1011

1112
integer_types = (int, np.integer)
1213

13-
ModType = Literal["dask", "pint", "cupy", "sparse"]
14+
if TYPE_CHECKING:
15+
ModType = Literal["dask", "pint", "cupy", "sparse"]
16+
DuckArrayTypes = tuple[Type[Any], ...] # TODO: improve this? maybe Generic
1417

1518

1619
class DuckArrayModule:
@@ -21,12 +24,15 @@ class DuckArrayModule:
2124
https://github.com/pydata/xarray/pull/5561#discussion_r664815718
2225
"""
2326

24-
module: ModType | None
27+
module: ModuleType | None
2528
version: Version
26-
type: tuple[type[Any]] # TODO: improve this? maybe Generic
29+
type: DuckArrayTypes
2730
available: bool
2831

2932
def __init__(self, mod: ModType) -> None:
33+
duck_array_module: ModuleType | None = None
34+
duck_array_version: Version
35+
duck_array_type: DuckArrayTypes
3036
try:
3137
duck_array_module = import_module(mod)
3238
duck_array_version = Version(duck_array_module.__version__)
@@ -53,7 +59,7 @@ def __init__(self, mod: ModType) -> None:
5359
self.available = duck_array_module is not None
5460

5561

56-
def array_type(mod: ModType) -> tuple[type[Any]]:
62+
def array_type(mod: ModType) -> DuckArrayTypes:
5763
"""Quick wrapper to get the array class of the module."""
5864
return DuckArrayModule(mod).type
5965

0 commit comments

Comments
 (0)