Fix tkinter ImageSpec #11721 (#13049)

This commit is contained in:
Konstantin Baikov
2024-11-25 19:45:58 +01:00
committed by GitHub
parent 69e3eb8be6
commit b815bfaf3c

View File

@@ -5,7 +5,7 @@ from collections.abc import Callable, Iterable, Mapping, Sequence
from tkinter.constants import *
from tkinter.font import _FontDescription
from types import TracebackType
from typing import Any, Generic, Literal, NamedTuple, TypedDict, TypeVar, overload, type_check_only
from typing import Any, Generic, Literal, NamedTuple, Protocol, TypedDict, TypeVar, overload, type_check_only
from typing_extensions import TypeAlias, TypeVarTuple, Unpack, deprecated
if sys.version_info >= (3, 11):
@@ -3454,11 +3454,14 @@ class OptionMenu(Menubutton):
# configure, config, cget are inherited from Menubutton
# destroy and __getitem__ are overridden, signature does not change
# Marker to indicate that it is a valid bitmap/photo image. PIL implements compatible versions
# which don't share a class hierarchy. The actual API is a __str__() which returns a valid name,
# not something that type checkers can detect.
# This matches tkinter's image classes (PhotoImage and BitmapImage)
# and PIL's tkinter-compatible class (PIL.ImageTk.PhotoImage),
# but not a plain PIL image that isn't tkinter compatible.
# The reason is that PIL has width and height attributes, not methods.
@type_check_only
class _Image: ...
class _Image(Protocol):
def width(self) -> int: ...
def height(self) -> int: ...
@type_check_only
class _BitmapImageLike(_Image): ...
@@ -3477,9 +3480,7 @@ class Image(_Image):
def __getitem__(self, key): ...
configure: Incomplete
config: Incomplete
def height(self) -> int: ...
def type(self): ...
def width(self) -> int: ...
class PhotoImage(Image, _PhotoImageLike):
# This should be kept in sync with PIL.ImageTK.PhotoImage.__init__()