Skip to content

Typing difficulty because Image is a module and also a class #6676

@scarf005

Description

@scarf005

What did you do?

from PIL import Image

def foo(img: Image) -> None:
	...

and got Module "PIL.Image" is not valid as a typemypy(error).

What did you expect to happen?

functions such as Image.open are classmethod of class Image.

What actually happened?

Image was actually an module, so for typing you need to type Image.Image, such as

from PIL import Image

def foo(img: Image.Image) -> None:
	...

What are your OS, Python and Pillow versions?

  • OS: Ubuntu 22.04
  • Python: Python 3.11.0rc2
  • Pillow: Name: Pillow-SIMD 9.0.0.post1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions