Skip to content

Commit

Permalink
Merge pull request #144 from radarhere/use-ptr
Browse files Browse the repository at this point in the history
Use CapsuleType hint in Python >= 3.13
  • Loading branch information
homm authored Sep 8, 2024
2 parents d29fa73 + 4318834 commit bd14915
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
7 changes: 1 addition & 6 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,7 @@ class Quantize(IntEnum):
from IPython.lib.pretty import PrettyPrinter

from . import ImageFile, ImageFilter, ImagePalette, ImageQt, TiffImagePlugin
from ._typing import NumpyArray, StrOrBytesPath, TypeGuard

if sys.version_info >= (3, 13):
from types import CapsuleType
else:
CapsuleType = object
from ._typing import CapsuleType, NumpyArray, StrOrBytesPath, TypeGuard
ID: list[str] = []
OPEN: dict[
str,
Expand Down
5 changes: 4 additions & 1 deletion src/PIL/ImageTk.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@

from . import Image, ImageFile

if TYPE_CHECKING:
from ._typing import CapsuleType

# --------------------------------------------------------------------
# Check for Tkinter interface hooks

Expand All @@ -48,7 +51,7 @@ def _get_image_from_kw(kw: dict[str, Any]) -> ImageFile.ImageFile | None:


def _pyimagingtkcall(
command: str, photo: PhotoImage | tkinter.PhotoImage, ptr: object
command: str, photo: PhotoImage | tkinter.PhotoImage, ptr: CapsuleType
) -> None:
tk = photo.tk
try:
Expand Down
5 changes: 5 additions & 0 deletions src/PIL/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
except (ImportError, AttributeError):
pass

if sys.version_info >= (3, 13):
from types import CapsuleType
else:
CapsuleType = object

if sys.version_info >= (3, 12):
from collections.abc import Buffer
else:
Expand Down

0 comments on commit bd14915

Please sign in to comment.