Skip to content

Commit b815bfa

Browse files
authored
Fix tkinter ImageSpec #11721 (#13049)
1 parent 69e3eb8 commit b815bfa

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

stdlib/tkinter/__init__.pyi

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from collections.abc import Callable, Iterable, Mapping, Sequence
55
from tkinter.constants import *
66
from tkinter.font import _FontDescription
77
from types import TracebackType
8-
from typing import Any, Generic, Literal, NamedTuple, TypedDict, TypeVar, overload, type_check_only
8+
from typing import Any, Generic, Literal, NamedTuple, Protocol, TypedDict, TypeVar, overload, type_check_only
99
from typing_extensions import TypeAlias, TypeVarTuple, Unpack, deprecated
1010

1111
if sys.version_info >= (3, 11):
@@ -3454,11 +3454,14 @@ class OptionMenu(Menubutton):
34543454
# configure, config, cget are inherited from Menubutton
34553455
# destroy and __getitem__ are overridden, signature does not change
34563456

3457-
# Marker to indicate that it is a valid bitmap/photo image. PIL implements compatible versions
3458-
# which don't share a class hierarchy. The actual API is a __str__() which returns a valid name,
3459-
# not something that type checkers can detect.
3457+
# This matches tkinter's image classes (PhotoImage and BitmapImage)
3458+
# and PIL's tkinter-compatible class (PIL.ImageTk.PhotoImage),
3459+
# but not a plain PIL image that isn't tkinter compatible.
3460+
# The reason is that PIL has width and height attributes, not methods.
34603461
@type_check_only
3461-
class _Image: ...
3462+
class _Image(Protocol):
3463+
def width(self) -> int: ...
3464+
def height(self) -> int: ...
34623465

34633466
@type_check_only
34643467
class _BitmapImageLike(_Image): ...
@@ -3477,9 +3480,7 @@ class Image(_Image):
34773480
def __getitem__(self, key): ...
34783481
configure: Incomplete
34793482
config: Incomplete
3480-
def height(self) -> int: ...
34813483
def type(self): ...
3482-
def width(self) -> int: ...
34833484

34843485
class PhotoImage(Image, _PhotoImageLike):
34853486
# This should be kept in sync with PIL.ImageTK.PhotoImage.__init__()

0 commit comments

Comments
 (0)