Moved imports into TYPE_CHECKING

This commit is contained in:
Andrew Murray 2025-08-02 11:40:35 +10:00
parent 98d6c3bf88
commit 27a7582b35
7 changed files with 31 additions and 11 deletions

View File

@ -7,7 +7,7 @@ import shutil
import sys import sys
from io import BytesIO from io import BytesIO
from pathlib import Path from pathlib import Path
from typing import Any, Literal, cast from typing import Literal, cast
import pytest import pytest
@ -31,6 +31,9 @@ except ImportError:
# Skipped via setup_module() # Skipped via setup_module()
pass pass
TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Any
SRGB = "Tests/icc/sRGB_IEC61966-2-1_black_scaled.icc" SRGB = "Tests/icc/sRGB_IEC61966-2-1_black_scaled.icc"
HAVE_PROFILE = os.path.exists(SRGB) HAVE_PROFILE = os.path.exists(SRGB)

View File

@ -17,7 +17,10 @@ from __future__ import annotations
import re import re
from io import BytesIO from io import BytesIO
from typing import IO
TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import IO
class GimpPaletteFile: class GimpPaletteFile:

View File

@ -38,10 +38,9 @@ import struct
import sys import sys
import tempfile import tempfile
import warnings import warnings
from collections.abc import Callable, Iterator, MutableMapping, Sequence from collections.abc import MutableMapping
from enum import IntEnum from enum import IntEnum
from types import ModuleType from typing import IO, Protocol, cast
from typing import IO, Any, Literal, Protocol, cast
# VERSION was removed in Pillow 6.0.0. # VERSION was removed in Pillow 6.0.0.
# PILLOW_VERSION was removed in Pillow 9.0.0. # PILLOW_VERSION was removed in Pillow 9.0.0.
@ -64,6 +63,12 @@ try:
except ImportError: except ImportError:
ElementTree = None ElementTree = None
TYPE_CHECKING = False
if TYPE_CHECKING:
from collections.abc import Callable, Iterator, Sequence
from types import ModuleType
from typing import Any, Literal
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View File

@ -18,11 +18,15 @@ from __future__ import annotations
import io import io
import os import os
import struct import struct
from collections.abc import Callable from typing import cast
from typing import IO, cast
from . import Image, ImageFile, ImagePalette, _binary from . import Image, ImageFile, ImagePalette, _binary
TYPE_CHECKING = False
if TYPE_CHECKING:
from collections.abc import Callable
from typing import IO
class BoxReader: class BoxReader:
""" """

View File

@ -42,7 +42,6 @@ import subprocess
import sys import sys
import tempfile import tempfile
import warnings import warnings
from typing import IO, Any
from . import Image, ImageFile from . import Image, ImageFile
from ._binary import i16be as i16 from ._binary import i16be as i16
@ -53,6 +52,8 @@ from .JpegPresets import presets
TYPE_CHECKING = False TYPE_CHECKING = False
if TYPE_CHECKING: if TYPE_CHECKING:
from typing import IO, Any
from .MpoImagePlugin import MpoImageFile from .MpoImagePlugin import MpoImageFile
# #

View File

@ -38,9 +38,8 @@ import re
import struct import struct
import warnings import warnings
import zlib import zlib
from collections.abc import Callable
from enum import IntEnum from enum import IntEnum
from typing import IO, Any, NamedTuple, NoReturn, cast from typing import IO, NamedTuple, cast
from . import Image, ImageChops, ImageFile, ImagePalette, ImageSequence from . import Image, ImageChops, ImageFile, ImagePalette, ImageSequence
from ._binary import i16be as i16 from ._binary import i16be as i16
@ -53,6 +52,9 @@ from ._util import DeferredError
TYPE_CHECKING = False TYPE_CHECKING = False
if TYPE_CHECKING: if TYPE_CHECKING:
from collections.abc import Callable
from typing import Any, NoReturn
from . import _imaging from . import _imaging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View File

@ -1,7 +1,6 @@
from __future__ import annotations from __future__ import annotations
from io import BytesIO from io import BytesIO
from typing import IO, Any
from . import Image, ImageFile from . import Image, ImageFile
@ -12,6 +11,9 @@ try:
except ImportError: except ImportError:
SUPPORTED = False SUPPORTED = False
TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import IO, Any
_VP8_MODES_BY_IDENTIFIER = { _VP8_MODES_BY_IDENTIFIER = {
b"VP8 ": "RGB", b"VP8 ": "RGB",