Skip to content

Commit 1c1cf28

Browse files
authored
Merge pull request numpy#27292 from DimitriPapadopoulos/TCH
MAINT: Start applying ruff/flake8-type-checking rules (TCH)
2 parents 221ea71 + d370773 commit 1c1cf28

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

numpy/_typing/_nested_sequence.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

33
from __future__ import annotations
44

5-
from collections.abc import Iterator
65
from typing import (
76
Any,
87
TypeVar,
98
Protocol,
109
runtime_checkable,
10+
TYPE_CHECKING,
1111
)
1212

13+
if TYPE_CHECKING:
14+
from collections.abc import Iterator
15+
1316
__all__ = ["_NestedSequence"]
1417

1518
_T_co = TypeVar("_T_co", covariant=True)

numpy/typing/mypy_plugin.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@
3333

3434
from __future__ import annotations
3535

36-
from collections.abc import Iterable
3736
from typing import Final, TYPE_CHECKING, Callable
3837

3938
import numpy as np
4039

40+
if TYPE_CHECKING:
41+
from collections.abc import Iterable
42+
4143
try:
4244
import mypy.types
4345
from mypy.types import Type

numpy/typing/tests/data/pass/array_like.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from __future__ import annotations
22

3-
from typing import Any
3+
from typing import Any, TYPE_CHECKING
44

55
import numpy as np
6-
from numpy._typing import NDArray, ArrayLike, _SupportsArray
6+
7+
if TYPE_CHECKING:
8+
from numpy._typing import NDArray, ArrayLike, _SupportsArray
79

810
x1: ArrayLike = True
911
x2: ArrayLike = 5

numpy/typing/tests/data/pass/literal.py

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

3-
from typing import Any
3+
from typing import Any, TYPE_CHECKING
44
from functools import partial
5-
from collections.abc import Callable
65

76
import pytest
87
import numpy as np
98

9+
if TYPE_CHECKING:
10+
from collections.abc import Callable
11+
1012
AR = np.array(0)
1113
AR.setflags(write=False)
1214

numpy/typing/tests/test_typing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import re
66
import shutil
77
from collections import defaultdict
8-
from collections.abc import Iterator
98
from typing import TYPE_CHECKING
109

1110
import pytest
@@ -34,6 +33,7 @@
3433
NO_MYPY = False
3534

3635
if TYPE_CHECKING:
36+
from collections.abc import Iterator
3737
# We need this as annotation, but it's located in a private namespace.
3838
# As a compromise, do *not* import it during runtime
3939
from _pytest.mark.structures import ParameterSet

0 commit comments

Comments
 (0)