Skip to content

imghdr is deprecated and slated for removal in Python 3.13 #10440

Closed
@domdfcoding

Description

@domdfcoding

Describe the bug

The imghdr module is deprecated in Python 3.11 by PEP 594 and is slated for removal in Python 3.13.

imghdr is used here to guess image mimetypes:

def guess_mimetype_for_stream(stream: IO, default: Optional[str] = None) -> Optional[str]:
imgtype = imghdr.what(stream)
if imgtype:
return 'image/' + imgtype
else:
return default

The imghdr code is not very large (see here). It could either be vendored by Sphinx or pulled out to a package on PyPI if there's no alternative.

Python version

Python 3.11.0.beta1

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions