Move imports into TYPE_CHECKING (#9123)

This commit is contained in:
Hugo van Kemenade 2025-08-02 13:56:00 +03:00 committed by GitHub
commit eb59176b09
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 31 additions and 11 deletions

View File

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

View File

@ -17,6 +17,9 @@ from __future__ import annotations
import re
from io import BytesIO
TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import IO

View File

@ -38,10 +38,9 @@ import struct
import sys
import tempfile
import warnings
from collections.abc import Callable, Iterator, MutableMapping, Sequence
from collections.abc import MutableMapping
from enum import IntEnum
from types import ModuleType
from typing import IO, Any, Literal, Protocol, cast
from typing import IO, Protocol, cast
# VERSION was removed in Pillow 6.0.0.
# PILLOW_VERSION was removed in Pillow 9.0.0.
@ -64,6 +63,12 @@ try:
except ImportError:
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__)

View File

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

View File

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

View File

@ -38,9 +38,8 @@ import re
import struct
import warnings
import zlib
from collections.abc import Callable
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 ._binary import i16be as i16
@ -53,6 +52,9 @@ from ._util import DeferredError
TYPE_CHECKING = False
if TYPE_CHECKING:
from collections.abc import Callable
from typing import Any, NoReturn
from . import _imaging
logger = logging.getLogger(__name__)

View File

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