Closed as not planned
Closed as not planned
Description
Bug Report
When using PEP 695 type parameters to annotate a function returning an Image from pillow, mypy produces an error where normally it would pass without issue.
Link to pillow: https://github.com/python-pillow/Pillow
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.13&gist=bde516a7d23bba4bd1bbf29d0490c882
https://gist.github.com/mypy-play/bde516a7d23bba4bd1bbf29d0490c882
Full example code
from PIL import Image
from typing import reveal_type
def no_error1(image: Image.Image) -> Image.Image:
reveal_type(image)
return image
def no_error2[T: Image.Image](image: T) -> T:
reveal_type(image)
return image
def no_error3(image: Image.Image) -> Image.Image:
reveal_type(image)
return Image.new('RGBA', image.size, (0, 0, 0, 0))
type T = Image.Image
def no_error4(image: T) -> T:
reveal_type(image)
return Image.new('RGBA', image.size, (0, 0, 0, 0))
def error[T: Image.Image](image: T) -> T:
reveal_type(image)
return Image.new('RGBA', image.size, (0, 0, 0, 0))
Expected Behavior
No errors
Actual Behavior
scratch_4.py:5: note: Revealed type is "PIL.Image.Image"
scratch_4.py:9: note: Revealed type is "T`-1"
scratch_4.py:13: note: Revealed type is "PIL.Image.Image"
scratch_4.py:19: note: Revealed type is "PIL.Image.Image"
scratch_4.py:23: note: Revealed type is "T`-1"
scratch_4.py:24: error: Incompatible return value type (got "Image", expected "T") [return-value]
Your Environment
- Mypy version used:
mypy 1.16.0 (compiled: yes)
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini
(and other config files): None - Python version used:
3.13.5
- pillow version used:
11.2.1
- potentially-related issue: Typing difficulty because
Image
is a module and also a class python-pillow/Pillow#6676
- potentially-related issue: Typing difficulty because