Allow pyright to "see" core properly

Without this change, the following file raises errors (in strict mode)
and reveals the type as "Unknown". After this change, the type is
correctly revealed as "ImagingCore".

  # pyright: strict

  from PIL import Image

  img = Image.new('RGB', (10, 10))
  data = img.getdata()
  reveal_type(data)
This commit is contained in:
Joey Marianer 2025-08-19 22:01:07 -07:00
parent 34c651deb8
commit 9240ec96c0

View File

@ -86,6 +86,9 @@ WARN_POSSIBLE_FORMATS: bool = False
MAX_IMAGE_PIXELS: int | None = int(1024 * 1024 * 1024 // 4 // 3)
if TYPE_CHECKING:
from . import _imaging as core
else:
try:
# If the _imaging C module is not present, Pillow will not load.
# Note that other modules should not refer to _imaging directly;