Skip to content

Commit 7872c7e

Browse files
committed
remove obsolete version checks
1 parent 60dd298 commit 7872c7e

File tree

6 files changed

+14
-76
lines changed

6 files changed

+14
-76
lines changed

xarray/backends/plugins.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import functools
44
import inspect
55
import itertools
6-
import sys
76
import warnings
87
from collections.abc import Callable
98
from importlib.metadata import entry_points
@@ -14,12 +13,7 @@
1413

1514
if TYPE_CHECKING:
1615
import os
17-
from importlib.metadata import EntryPoint
18-
19-
if sys.version_info >= (3, 10):
20-
from importlib.metadata import EntryPoints
21-
else:
22-
EntryPoints = list[EntryPoint]
16+
from importlib.metadata import EntryPoint, EntryPoints
2317
from io import BufferedIOBase
2418

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

142131

xarray/core/utils.py

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
)
6464
from enum import Enum
6565
from pathlib import Path
66-
from typing import TYPE_CHECKING, Any, Generic, Literal, TypeVar, overload
66+
from typing import TYPE_CHECKING, Any, Generic, Literal, TypeGuard, TypeVar, overload
6767

6868
import numpy as np
6969
import pandas as pd
@@ -275,34 +275,12 @@ def _is_scalar(value, include_0d):
275275
)
276276

277277

278-
# See GH5624, this is a convoluted way to allow type-checking to use `TypeGuard` without
279-
# requiring typing_extensions as a required dependency to _run_ the code (it is required
280-
# to type-check).
281-
try:
282-
if sys.version_info >= (3, 10):
283-
from typing import TypeGuard
284-
else:
285-
from typing import TypeGuard
286-
except ImportError:
287-
if TYPE_CHECKING:
288-
raise
289-
else:
290-
291-
def is_scalar(value: Any, include_0d: bool = True) -> bool:
292-
"""Whether to treat a value as a scalar.
293-
294-
Any non-iterable, string, or 0-D array
295-
"""
296-
return _is_scalar(value, include_0d)
278+
def is_scalar(value: Any, include_0d: bool = True) -> TypeGuard[Hashable]:
279+
"""Whether to treat a value as a scalar.
297280
298-
else:
299-
300-
def is_scalar(value: Any, include_0d: bool = True) -> TypeGuard[Hashable]:
301-
"""Whether to treat a value as a scalar.
302-
303-
Any non-iterable, string, or 0-D array
304-
"""
305-
return _is_scalar(value, include_0d)
281+
Any non-iterable, string, or 0-D array
282+
"""
283+
return _is_scalar(value, include_0d)
306284

307285

308286
def is_valid_numpy_dtype(dtype: Any) -> bool:

xarray/namedarray/dtypes.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
from __future__ import annotations
22

33
import functools
4-
import sys
5-
from typing import Any, Literal
6-
7-
if sys.version_info >= (3, 10):
8-
from typing import TypeGuard
9-
else:
10-
from typing import TypeGuard
4+
from typing import Any, Literal, TypeGuard
115

126
import numpy as np
137

xarray/namedarray/parallelcompat.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from __future__ import annotations
88

99
import functools
10-
import sys
1110
from abc import ABC, abstractmethod
1211
from collections.abc import Callable, Iterable, Sequence
1312
from importlib.metadata import EntryPoint, entry_points
@@ -56,15 +55,8 @@ def list_chunkmanagers() -> dict[str, ChunkManagerEntrypoint[Any]]:
5655
chunkmanagers : dict
5756
Dictionary whose values are registered ChunkManagerEntrypoint subclass instances, and whose values
5857
are the strings under which they are registered.
59-
60-
Notes
61-
-----
62-
# New selection mechanism introduced with Python 3.10. See GH6514.
6358
"""
64-
if sys.version_info >= (3, 10):
65-
entrypoints = entry_points(group="xarray.chunkmanagers")
66-
else:
67-
entrypoints = entry_points().get("xarray.chunkmanagers", ())
59+
entrypoints = entry_points(group="xarray.chunkmanagers")
6860

6961
return load_chunkmanagers(entrypoints)
7062

xarray/namedarray/utils.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import importlib
4-
import sys
54
import warnings
65
from collections.abc import Hashable, Iterable, Iterator, Mapping
76
from functools import lru_cache
@@ -13,10 +12,7 @@
1312
from xarray.namedarray._typing import ErrorOptionsWithWarn, _DimsLike
1413

1514
if TYPE_CHECKING:
16-
if sys.version_info >= (3, 10):
17-
from typing import TypeGuard
18-
else:
19-
from typing import TypeGuard
15+
from typing import TypeGuard
2016

2117
from numpy.typing import NDArray
2218

xarray/tests/test_plugins.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
from __future__ import annotations
22

33
import sys
4-
from importlib.metadata import EntryPoint
5-
6-
if sys.version_info >= (3, 10):
7-
from importlib.metadata import EntryPoints
8-
else:
9-
EntryPoints = list[EntryPoint]
4+
from importlib.metadata import EntryPoint, EntryPoints
105
from unittest import mock
116

127
import pytest
@@ -288,10 +283,7 @@ def test_refresh_engines() -> None:
288283
EntryPointMock1.name = "test1"
289284
EntryPointMock1.load.return_value = DummyBackendEntrypoint1
290285

291-
if sys.version_info >= (3, 10):
292-
return_value = EntryPoints([EntryPointMock1])
293-
else:
294-
return_value = {"xarray.backends": [EntryPointMock1]}
286+
return_value = EntryPoints([EntryPointMock1])
295287

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

306-
if sys.version_info >= (3, 10):
307-
return_value2 = EntryPoints([EntryPointMock2])
308-
else:
309-
return_value2 = {"xarray.backends": [EntryPointMock2]}
298+
return_value2 = EntryPoints([EntryPointMock2])
310299

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

0 commit comments

Comments
 (0)