Skip to content

Commit 27a7582

Browse files
committed
Moved imports into TYPE_CHECKING
1 parent 98d6c3b commit 27a7582

File tree

7 files changed

+31
-11
lines changed

7 files changed

+31
-11
lines changed

Tests/test_imagecms.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import sys
88
from io import BytesIO
99
from pathlib import Path
10-
from typing import Any, Literal, cast
10+
from typing import Literal, cast
1111

1212
import pytest
1313

@@ -31,6 +31,9 @@
3131
# Skipped via setup_module()
3232
pass
3333

34+
TYPE_CHECKING = False
35+
if TYPE_CHECKING:
36+
from typing import Any
3437

3538
SRGB = "Tests/icc/sRGB_IEC61966-2-1_black_scaled.icc"
3639
HAVE_PROFILE = os.path.exists(SRGB)

src/PIL/GimpPaletteFile.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717

1818
import re
1919
from io import BytesIO
20-
from typing import IO
20+
21+
TYPE_CHECKING = False
22+
if TYPE_CHECKING:
23+
from typing import IO
2124

2225

2326
class GimpPaletteFile:

src/PIL/Image.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@
3838
import sys
3939
import tempfile
4040
import warnings
41-
from collections.abc import Callable, Iterator, MutableMapping, Sequence
41+
from collections.abc import MutableMapping
4242
from enum import IntEnum
43-
from types import ModuleType
44-
from typing import IO, Any, Literal, Protocol, cast
43+
from typing import IO, Protocol, cast
4544

4645
# VERSION was removed in Pillow 6.0.0.
4746
# PILLOW_VERSION was removed in Pillow 9.0.0.
@@ -64,6 +63,12 @@
6463
except ImportError:
6564
ElementTree = None
6665

66+
TYPE_CHECKING = False
67+
if TYPE_CHECKING:
68+
from collections.abc import Callable, Iterator, Sequence
69+
from types import ModuleType
70+
from typing import Any, Literal
71+
6772
logger = logging.getLogger(__name__)
6873

6974

src/PIL/Jpeg2KImagePlugin.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@
1818
import io
1919
import os
2020
import struct
21-
from collections.abc import Callable
22-
from typing import IO, cast
21+
from typing import cast
2322

2423
from . import Image, ImageFile, ImagePalette, _binary
2524

25+
TYPE_CHECKING = False
26+
if TYPE_CHECKING:
27+
from collections.abc import Callable
28+
from typing import IO
29+
2630

2731
class BoxReader:
2832
"""

src/PIL/JpegImagePlugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import sys
4343
import tempfile
4444
import warnings
45-
from typing import IO, Any
4645

4746
from . import Image, ImageFile
4847
from ._binary import i16be as i16
@@ -53,6 +52,8 @@
5352

5453
TYPE_CHECKING = False
5554
if TYPE_CHECKING:
55+
from typing import IO, Any
56+
5657
from .MpoImagePlugin import MpoImageFile
5758

5859
#

src/PIL/PngImagePlugin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@
3838
import struct
3939
import warnings
4040
import zlib
41-
from collections.abc import Callable
4241
from enum import IntEnum
43-
from typing import IO, Any, NamedTuple, NoReturn, cast
42+
from typing import IO, NamedTuple, cast
4443

4544
from . import Image, ImageChops, ImageFile, ImagePalette, ImageSequence
4645
from ._binary import i16be as i16
@@ -53,6 +52,9 @@
5352

5453
TYPE_CHECKING = False
5554
if TYPE_CHECKING:
55+
from collections.abc import Callable
56+
from typing import Any, NoReturn
57+
5658
from . import _imaging
5759

5860
logger = logging.getLogger(__name__)

src/PIL/WebPImagePlugin.py

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

33
from io import BytesIO
4-
from typing import IO, Any
54

65
from . import Image, ImageFile
76

@@ -12,6 +11,9 @@
1211
except ImportError:
1312
SUPPORTED = False
1413

14+
TYPE_CHECKING = False
15+
if TYPE_CHECKING:
16+
from typing import IO, Any
1517

1618
_VP8_MODES_BY_IDENTIFIER = {
1719
b"VP8 ": "RGB",

0 commit comments

Comments
 (0)