You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# 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.
@type_check_only
class_Image: ...
Classes implementing this interface are expected to derive from this stub-only class (or one of its sub-classes). Our Pillow stubs did so. Unfortunately, now that Pillow has its own type annotations, I think it's unreasonable for them to do so at runtime. I think our best bet is to change change _Image to Any here, as this interface can't be represented in our type system.
_ImageSpec: TypeAlias=_Image|str# str can be from e.g. tkinter.image_names()
The most common use cases for tkinter images are setting a window icon with wm_iconphoto() and displaying images in the UI with various image=... keyword arguments. These would become basically Any-typed. IMO that's not a huge problem, because if you do these things wrong, you typically get an error when the program starts, so at least it fails loudly and early.
Another option, if it works, is to just import Pillow's type in tkinter stubs with a # type: ignore. Mypy will treat it as Any when pillow is not installed, but I'm not sure what other type checkers would do.
Currently, tkinter uses a hack to mark classes compatible with the
image
parameter:typeshed/stdlib/tkinter/__init__.pyi
Lines 3276 to 3280 in 130a049
Classes implementing this interface are expected to derive from this stub-only class (or one of its sub-classes). Our Pillow stubs did so. Unfortunately, now that Pillow has its own type annotations, I think it's unreasonable for them to do so at runtime. I think our best bet is to change change
_Image
toAny
here, as this interface can't be represented in our type system.Cc @Akuli
The text was updated successfully, but these errors were encountered: