Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
domdfcoding opened this issue May 9, 2022 · 4 comments
Closed

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

domdfcoding opened this issue May 9, 2022 · 4 comments

Comments

@domdfcoding
Copy link
Contributor

domdfcoding commented May 9, 2022

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

@tk0miya
Copy link
Member

tk0miya commented May 14, 2022

Now we're using the imagesize package to obtain the image file size. It's better to extend it to detect the type of image.
https://pypi.org/project/imagesize/

And it's much better to use the Pillow package as a fallback when the imagesize can't detect the type.

@trevorbaca
Copy link

Hi,

With the public release of Python 3.11, the deprecation warning for imghdr is now showing up.

Any idea when imghdr might be removed?

Thanks!

@hugovk
Copy link
Contributor

hugovk commented May 21, 2023

imghdr was removed in a502e75 (no PR) and released in v6.2.0 🚀

@AA-Turner
Copy link
Member

I had forgotten about this issue -- thanks for the reminder Hugo!

A

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants