Skip to content

Packaging Type Information Not Distributed #5325

@byarbrough

Description

@byarbrough

Describe the bug

Diffusers does not appear to adhere to PEP 561 – Distributing and Packaging Type Information. As a result, static type checkers, such as mypy or pyright, report incorrect errors.

According to the docs, this can be remedied by

  1. Creating a blank py.typed in the package; note, that it applies recursively
  2. Add the line package_data = {'diffusers': ['py.typed']} to setup.py

In searching for a related issue I found #5249, which indicates to me that type hints are highly desired in this project.

Reproduction

Anything that imports diffusers will cause the problem with a static type checker. I used this file:

from diffusers import AutoPipelineForText2Image

# https://huggingface.co/runwayml/stable-diffusion-v1-5
diffusion_model: str = "runwayml/stable-diffusion-v1-5"

# The auto pipeline automatically detects and loads the model
pipeline = AutoPipelineForText2Image.from_pretrained(
    diffusion_model, use_safetensors=True
).to("cpu")

# Generate the image based on the prompt
prompt: str = "A python is sitting on a desk, and the snake is wearing glasses."
image = pipeline(prompt, num_inference_steps=25).images[0]
image.show()

mypy

error: Skipping analyzing "diffusers": module is installed, but missing library stubs or py.typed marker [import]
note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

pyright

--verifytypes diffusers

error: No py.typed file found

Logs

No response

System Info

  • diffusers version: 0.21.4
  • Platform: Linux-6.2.0-32-generic-x86_64-with-glibc2.35
  • Python version: 3.10.12
  • PyTorch version (GPU?): 2.1.0+cu121 (False)
  • Huggingface_hub version: 0.17.3
  • Transformers version: 4.34.0
  • Accelerate version: 0.23.0
  • xFormers version: not installed
  • Using GPU in script?: No
  • Using distributed or parallel set-up in script?: No
  • mypy 1.5.1 (compiled: yes)
  • pyright 1.1.329

Who can help?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions