@@ -5,7 +5,7 @@ from collections.abc import Callable, Iterable, Mapping, Sequence
55from tkinter .constants import *
66from tkinter .font import _FontDescription
77from 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
99from typing_extensions import TypeAlias , TypeVarTuple , Unpack , deprecated
1010
1111if 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
34643467class _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
34843485class PhotoImage (Image , _PhotoImageLike ):
34853486 # This should be kept in sync with PIL.ImageTK.PhotoImage.__init__()
0 commit comments