You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
mimetypes.add_type should complain when you give it an undotted ext #75223
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2017-07-25.19:25:41.891>labels= ['3.7', 'library', 'docs']
title='mimetypes.add_type should complain when you give it an undotted ext'updated_at=<Date2019-09-13.10:59:42.020>user='https://github.com/OddBloke'
I (mistakenly) expected the latter print to give me "('text/plain', None)". It doesn't because I should have prepended a . to the second add_type argument.
I think add_type should error out when given an extension without a dot-prefix, because it's extremely unlikely that code that does so is behaving as intended with the current implementation.
(At the very least, documentation should be updated to make this expectation clearer.)
Activity
OddBloke commentedon Jul 25, 2017
results in:
I (mistakenly) expected the latter print to give me "('text/plain', None)". It doesn't because I should have prepended a . to the second add_type argument.
I think add_type should error out when given an extension without a dot-prefix, because it's extremely unlikely that code that does so is behaving as intended with the current implementation.
(At the very least, documentation should be updated to make this expectation clearer.)
jimjjewett commentedon Nov 19, 2017
Ideally, use .startswith('.') Instead if find, but this is a clear UI fix. First pull request fixes doc, second fixes code. OK to apply both.
JulienPalard commentedon Sep 13, 2019
I think we should deprecate calling
add_typewith an emptyext, as I don't think it's a feature, more a side effect of the current implementation.But as some may use it like a feature, I asked the current PR to emit a warning, to not break the current implementations.
To be able to simplify in the future, why not deprecating empty
extso we can remove it in a few versions?JulienPalard commentedon Sep 13, 2019
I just found a case where the empty mime type is actually usefull, it's in Lib/http/server.py:
It does *not* uses add_type, but demos the fact that the empty type may be usefull from time to time, maybe don't warn and don't deprecate it at all.
hugovk commentedon Nov 21, 2024
Checking the top 8k PyPI projects:
Details
Of the 77 calls (in 26 projects) to
mimetypes.add_type:gh-75223: Deprecate undotted extensions in `mimetypes.MimeTypes.add_t…
hugovk commentedon Apr 28, 2025
mimetypes.MimeTypes.add_type#128638extmust start with.inmimetypes.add_type#149720