Skip to content

Commit

Permalink
remove obsolete version checks
Browse files Browse the repository at this point in the history
  • Loading branch information
keewis committed Aug 7, 2024
1 parent 60dd298 commit 7872c7e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 76 deletions.
15 changes: 2 additions & 13 deletions xarray/backends/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import functools
import inspect
import itertools
import sys
import warnings
from collections.abc import Callable
from importlib.metadata import entry_points
Expand All @@ -14,12 +13,7 @@

if TYPE_CHECKING:
import os
from importlib.metadata import EntryPoint

if sys.version_info >= (3, 10):
from importlib.metadata import EntryPoints
else:
EntryPoints = list[EntryPoint]
from importlib.metadata import EntryPoint, EntryPoints
from io import BufferedIOBase

from xarray.backends.common import AbstractDataStore
Expand Down Expand Up @@ -130,13 +124,8 @@ def list_engines() -> dict[str, BackendEntrypoint]:
-----
This function lives in the backends namespace (``engs=xr.backends.list_engines()``).
If available, more information is available about each backend via ``engs["eng_name"]``.
# New selection mechanism introduced with Python 3.10. See GH6514.
"""
if sys.version_info >= (3, 10):
entrypoints = entry_points(group="xarray.backends")
else:
entrypoints = entry_points().get("xarray.backends", [])
entrypoints = entry_points(group="xarray.backends")
return build_engines(entrypoints)


Expand Down
34 changes: 6 additions & 28 deletions xarray/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
)
from enum import Enum
from pathlib import Path
from typing import TYPE_CHECKING, Any, Generic, Literal, TypeVar, overload
from typing import TYPE_CHECKING, Any, Generic, Literal, TypeGuard, TypeVar, overload

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -275,34 +275,12 @@ def _is_scalar(value, include_0d):
)


# See GH5624, this is a convoluted way to allow type-checking to use `TypeGuard` without
# requiring typing_extensions as a required dependency to _run_ the code (it is required
# to type-check).
try:
if sys.version_info >= (3, 10):
from typing import TypeGuard
else:
from typing import TypeGuard
except ImportError:
if TYPE_CHECKING:
raise
else:

def is_scalar(value: Any, include_0d: bool = True) -> bool:
"""Whether to treat a value as a scalar.
Any non-iterable, string, or 0-D array
"""
return _is_scalar(value, include_0d)
def is_scalar(value: Any, include_0d: bool = True) -> TypeGuard[Hashable]:
"""Whether to treat a value as a scalar.
else:

def is_scalar(value: Any, include_0d: bool = True) -> TypeGuard[Hashable]:
"""Whether to treat a value as a scalar.
Any non-iterable, string, or 0-D array
"""
return _is_scalar(value, include_0d)
Any non-iterable, string, or 0-D array
"""
return _is_scalar(value, include_0d)


def is_valid_numpy_dtype(dtype: Any) -> bool:
Expand Down
8 changes: 1 addition & 7 deletions xarray/namedarray/dtypes.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
from __future__ import annotations

import functools
import sys
from typing import Any, Literal

if sys.version_info >= (3, 10):
from typing import TypeGuard
else:
from typing import TypeGuard
from typing import Any, Literal, TypeGuard

import numpy as np

Expand Down
10 changes: 1 addition & 9 deletions xarray/namedarray/parallelcompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from __future__ import annotations

import functools
import sys
from abc import ABC, abstractmethod
from collections.abc import Callable, Iterable, Sequence
from importlib.metadata import EntryPoint, entry_points
Expand Down Expand Up @@ -56,15 +55,8 @@ def list_chunkmanagers() -> dict[str, ChunkManagerEntrypoint[Any]]:
chunkmanagers : dict
Dictionary whose values are registered ChunkManagerEntrypoint subclass instances, and whose values
are the strings under which they are registered.
Notes
-----
# New selection mechanism introduced with Python 3.10. See GH6514.
"""
if sys.version_info >= (3, 10):
entrypoints = entry_points(group="xarray.chunkmanagers")
else:
entrypoints = entry_points().get("xarray.chunkmanagers", ())
entrypoints = entry_points(group="xarray.chunkmanagers")

return load_chunkmanagers(entrypoints)

Expand Down
6 changes: 1 addition & 5 deletions xarray/namedarray/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import importlib
import sys
import warnings
from collections.abc import Hashable, Iterable, Iterator, Mapping
from functools import lru_cache
Expand All @@ -13,10 +12,7 @@
from xarray.namedarray._typing import ErrorOptionsWithWarn, _DimsLike

if TYPE_CHECKING:
if sys.version_info >= (3, 10):
from typing import TypeGuard
else:
from typing import TypeGuard
from typing import TypeGuard

from numpy.typing import NDArray

Expand Down
17 changes: 3 additions & 14 deletions xarray/tests/test_plugins.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
from __future__ import annotations

import sys
from importlib.metadata import EntryPoint

if sys.version_info >= (3, 10):
from importlib.metadata import EntryPoints
else:
EntryPoints = list[EntryPoint]
from importlib.metadata import EntryPoint, EntryPoints
from unittest import mock

import pytest
Expand Down Expand Up @@ -288,10 +283,7 @@ def test_refresh_engines() -> None:
EntryPointMock1.name = "test1"
EntryPointMock1.load.return_value = DummyBackendEntrypoint1

if sys.version_info >= (3, 10):
return_value = EntryPoints([EntryPointMock1])
else:
return_value = {"xarray.backends": [EntryPointMock1]}
return_value = EntryPoints([EntryPointMock1])

with mock.patch("xarray.backends.plugins.entry_points", return_value=return_value):
list_engines.cache_clear()
Expand All @@ -303,10 +295,7 @@ def test_refresh_engines() -> None:
EntryPointMock2.name = "test2"
EntryPointMock2.load.return_value = DummyBackendEntrypoint2

if sys.version_info >= (3, 10):
return_value2 = EntryPoints([EntryPointMock2])
else:
return_value2 = {"xarray.backends": [EntryPointMock2]}
return_value2 = EntryPoints([EntryPointMock2])

with mock.patch("xarray.backends.plugins.entry_points", return_value=return_value2):
refresh_engines()
Expand Down

0 comments on commit 7872c7e

Please sign in to comment.