Skip to content

Commit

Permalink
Use version guards instead of “except ImportError” (scverse#3145)
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep authored Jul 8, 2024
1 parent db2118e commit 0583594
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
15 changes: 4 additions & 11 deletions src/scanpy/_compat.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
from __future__ import annotations

import sys
from dataclasses import dataclass, field
from functools import partial
from functools import cache, partial
from pathlib import Path

from legacy_api_wrap import legacy_api
from packaging.version import Version

try:
from functools import cache
except ImportError: # Python < 3.9
from functools import lru_cache

cache = lru_cache(maxsize=None)

try:
from dask.array import Array as DaskArray
except ImportError:
Expand All @@ -31,7 +25,6 @@ class ZappyArray:


__all__ = [
"cache",
"DaskArray",
"ZappyArray",
"fullname",
Expand All @@ -48,9 +41,9 @@ def fullname(typ: type) -> str:
return f"{module}.{name}"


try:
if sys.version_info >= (3, 11):
from contextlib import chdir
except ImportError: # Python < 3.11
else:
import os
from contextlib import AbstractContextManager

Expand Down
11 changes: 1 addition & 10 deletions src/testing/scanpy/_helpers/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@
from __future__ import annotations

import warnings

try:
from functools import cache
except ImportError: # Python < 3.9
from functools import lru_cache

def cache(func):
return lru_cache(maxsize=None)(func)


from functools import cache
from typing import TYPE_CHECKING

import scanpy as sc
Expand Down

0 comments on commit 0583594

Please sign in to comment.