Skip to content

Commit

Permalink
Fix some typing errors in DuckArrayModule (#7296)
Browse files Browse the repository at this point in the history
* Fix some typing errors in DuckArrayModule

* Update pycompat.py

* Update pycompat.py
  • Loading branch information
Illviljan authored Nov 20, 2022
1 parent 9dd3c1b commit d6671dd
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions xarray/core/pycompat.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

from importlib import import_module
from typing import Any, Literal
from types import ModuleType
from typing import TYPE_CHECKING, Any, Literal, Type

import numpy as np
from packaging.version import Version
Expand All @@ -10,7 +11,9 @@

integer_types = (int, np.integer)

ModType = Literal["dask", "pint", "cupy", "sparse"]
if TYPE_CHECKING:
ModType = Literal["dask", "pint", "cupy", "sparse"]
DuckArrayTypes = tuple[Type[Any], ...] # TODO: improve this? maybe Generic


class DuckArrayModule:
Expand All @@ -21,12 +24,15 @@ class DuckArrayModule:
https://github.com/pydata/xarray/pull/5561#discussion_r664815718
"""

module: ModType | None
module: ModuleType | None
version: Version
type: tuple[type[Any]] # TODO: improve this? maybe Generic
type: DuckArrayTypes
available: bool

def __init__(self, mod: ModType) -> None:
duck_array_module: ModuleType | None = None
duck_array_version: Version
duck_array_type: DuckArrayTypes
try:
duck_array_module = import_module(mod)
duck_array_version = Version(duck_array_module.__version__)
Expand All @@ -53,7 +59,7 @@ def __init__(self, mod: ModType) -> None:
self.available = duck_array_module is not None


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

Expand Down

0 comments on commit d6671dd

Please sign in to comment.