Skip to content

Fix some typing errors in DuckArrayModule #7296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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