Felipe Rodrigues <fel...@felipevr.com> added the comment:

@_savage, on the commit @xtreak referred, there's a note that "image/jpg" and 
some other non-standard mimetypes are only supported if `strict=False`[1]

So, this:

>>> mimetypes.guess_extension("image/jpg")

Gives no return. But this works:

>>> mimetypes.guess_extension("image/jpg", strict=False)
'.jpg'


---------

I guess we could improve the current documentation [2]. It currently specifies 
correctly the `strict` behavior:


> The optional strict argument is a flag specifying whether the list of known 
> MIME types is limited to
> only the official types registered with IANA. When strict is True (the 
> default), only the IANA types
> are supported; when strict is False, some additional non-standard but 
> commonly used MIME types are 
> also recognized.

But I think it would be nice to have a table specifying what are those 
"non-standard but commonly used MIME types". Personally, I'd have a hard time 
guessing on a regular day of my life which of 'image/jpeg' and 'image/jpg' is 
standard or not. We could even add a nice note pointing out that the 
`common_types` property [3] is a list of those supported non-standard type .

Given the fact that the `strict` flag is used by different methods with the 
same behavior, maybe we could add a note on the top of the doc explaining the 
general meaning of that flag.



[1]: 
https://github.com/python/cpython/commit/2a99fd911ebeecedbb250a05667cd46eca4735b9#diff-fc65388a9cdf41980b2c31de5de67758R547

[2]: https://docs.python.org/3.10/library/mimetypes.html#mimetypes.guess_type

[3]: https://docs.python.org/3.10/library/mimetypes.html#mimetypes.common_types

----------
nosy: +fbidu

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue37943>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to