Skip to content

Commit

Permalink
STY: Apply ruff/flake8-type-checking rule TCH003
Browse files Browse the repository at this point in the history
TCH003 Move standard library import into a type-checking block
  • Loading branch information
DimitriPapadopoulos committed Sep 22, 2024
1 parent bb22191 commit 0a27464
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion nibabel/_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@

import bz2
import gzip
import io
import typing as ty

from .optpkg import optional_package

if ty.TYPE_CHECKING:
import io

import indexed_gzip # type: ignore[import]
import pyzstd

Expand Down
4 changes: 3 additions & 1 deletion nibabel/fileholders.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

from __future__ import annotations

import io
import typing as ty
from copy import copy

from .openers import ImageOpener

if ty.TYPE_CHECKING:
import io


class FileHolderError(Exception):
pass
Expand Down
4 changes: 3 additions & 1 deletion nibabel/optpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
from __future__ import annotations

import typing as ty
from types import ModuleType

from packaging.version import Version

from .tripwire import TripWire

if ty.TYPE_CHECKING:
from types import ModuleType


def _check_pkg_version(min_version: str | Version) -> ty.Callable[[ModuleType], bool]:
min_ver = Version(min_version) if isinstance(min_version, str) else min_version
Expand Down
5 changes: 3 additions & 2 deletions nibabel/spatialimages.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@

from __future__ import annotations

import io
import typing as ty
from collections.abc import Sequence
from typing import Literal

import numpy as np
Expand All @@ -153,6 +151,9 @@
from functools import lru_cache as cache

if ty.TYPE_CHECKING:
import io
from collections.abc import Sequence

import numpy.typing as npt

from .arrayproxy import ArrayLike
Expand Down
3 changes: 1 addition & 2 deletions nibabel/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@
from .np_features import memmap_after_ufunc

if ty.TYPE_CHECKING:
from importlib_resources.abc import Traversable
from importlib.resources.abc import Traversable

try:
from importlib.resources import as_file, files
from importlib.resources.abc import Traversable
except ImportError: # PY38
from importlib_resources import as_file, files

Expand Down
3 changes: 2 additions & 1 deletion nibabel/volumeutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from __future__ import annotations

import io
import sys
import typing as ty
import warnings
Expand All @@ -25,6 +24,8 @@
from .externals.oset import OrderedSet

if ty.TYPE_CHECKING:
import io

import numpy.typing as npt

Scalar = np.number | float
Expand Down

0 comments on commit 0a27464

Please sign in to comment.