Skip to content

Commit 4e5f09f

Browse files
authored
Move typing imports under TYPE_CHECKING block (#9827)
2 parents 0fcd9e3 + 5c2205a commit 4e5f09f

125 files changed

Lines changed: 522 additions & 215 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Tests/test_color_lut.py

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

33
from array import array
4-
from types import ModuleType
54

65
import pytest
76

87
from PIL import Image, ImageFilter
98

109
from .helper import assert_image_equal
1110

11+
TYPE_CHECKING = False
12+
if TYPE_CHECKING:
13+
from types import ModuleType
14+
1215
numpy: ModuleType | None
1316
try:
1417
import numpy

Tests/test_file_apng.py

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

33
from io import BytesIO
4-
from pathlib import Path
54

65
import pytest
76

87
from PIL import Image, ImageSequence, PngImagePlugin
98

9+
TYPE_CHECKING = False
10+
if TYPE_CHECKING:
11+
from pathlib import Path
12+
1013

1114
# APNG browser support tests and fixtures via:
1215
# https://philip.html5.org/tests/apng/tests.html

Tests/test_file_avif.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
import os
55
import re
66
import warnings
7-
from collections.abc import Generator, Sequence
87
from contextlib import contextmanager
98
from io import BytesIO
10-
from pathlib import Path
119
from typing import Any
1210

1311
import pytest
@@ -32,6 +30,11 @@
3230
skip_unless_feature_version,
3331
)
3432

33+
TYPE_CHECKING = False
34+
if TYPE_CHECKING:
35+
from collections.abc import Generator, Sequence
36+
from pathlib import Path
37+
3538
try:
3639
from PIL import _avif
3740

Tests/test_file_blp.py

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

3-
from pathlib import Path
4-
53
import pytest
64

75
from PIL import BlpImagePlugin, Image
@@ -12,6 +10,10 @@
1210
hopper,
1311
)
1412

13+
TYPE_CHECKING = False
14+
if TYPE_CHECKING:
15+
from pathlib import Path
16+
1517

1618
def test_load_blp1() -> None:
1719
with Image.open("Tests/images/blp/blp1_jpeg.blp") as im:

Tests/test_file_bmp.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import io
4-
from pathlib import Path
54

65
import pytest
76

@@ -16,6 +15,10 @@
1615
hopper,
1716
)
1817

18+
TYPE_CHECKING = False
19+
if TYPE_CHECKING:
20+
from pathlib import Path
21+
1922

2023
@pytest.mark.parametrize("mode", ("1", "L", "P", "RGB"))
2124
def test_sanity(mode: str, tmp_path: Path) -> None:

Tests/test_file_bufrstub.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
from pathlib import Path
43
from typing import IO
54

65
import pytest
@@ -9,6 +8,10 @@
98

109
from .helper import hopper
1110

11+
TYPE_CHECKING = False
12+
if TYPE_CHECKING:
13+
from pathlib import Path
14+
1215
TEST_FILE = "Tests/images/gfs.t06z.rassda.tm00.bufr_d"
1316

1417

Tests/test_file_dds.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from __future__ import annotations
44

55
from io import BytesIO
6-
from pathlib import Path
76

87
import pytest
98

@@ -17,6 +16,10 @@
1716
hopper,
1817
)
1918

19+
TYPE_CHECKING = False
20+
if TYPE_CHECKING:
21+
from pathlib import Path
22+
2023
TEST_FILE_DXT1 = "Tests/images/dxt1-rgb-4bbp-noalpha_MipMaps-1.dds"
2124
TEST_FILE_DXT3 = "Tests/images/dxt3-argb-8bbp-explicitalpha_MipMaps-1.dds"
2225
TEST_FILE_DXT5 = "Tests/images/dxt5-argb-8bbp-interpolatedalpha_MipMaps-1.dds"

Tests/test_file_eps.py

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

33
import io
44
import subprocess
5-
from pathlib import Path
65

76
import pytest
87

@@ -19,6 +18,10 @@
1918
timeout_unless_slower_valgrind,
2019
)
2120

21+
TYPE_CHECKING = False
22+
if TYPE_CHECKING:
23+
from pathlib import Path
24+
2225
HAS_GHOSTSCRIPT = EpsImagePlugin.has_ghostscript()
2326

2427
# Our two EPS test files (they are identical except for their bounding boxes)

Tests/test_file_gif.py

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

33
import warnings
4-
from collections.abc import Generator
54
from io import BytesIO
6-
from pathlib import Path
75
from typing import Any
86

97
import pytest
@@ -19,6 +17,11 @@
1917
netpbm_available,
2018
)
2119

20+
TYPE_CHECKING = False
21+
if TYPE_CHECKING:
22+
from collections.abc import Generator
23+
from pathlib import Path
24+
2225
# sample gif stream
2326
TEST_GIF = "Tests/images/hopper.gif"
2427

Tests/test_file_gribstub.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
from pathlib import Path
43
from typing import IO
54

65
import pytest
@@ -9,6 +8,10 @@
98

109
from .helper import hopper
1110

11+
TYPE_CHECKING = False
12+
if TYPE_CHECKING:
13+
from pathlib import Path
14+
1215
TEST_FILE = "Tests/images/WAlaska.wind.7days.grb"
1316

1417

0 commit comments

Comments
 (0)