Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Doc/library/mimetypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,6 @@ than one MIME-type database; it provides an interface similar to the one of the
When *strict* is ``True`` (the default), the mapping will be added to the
official MIME types, otherwise to the non-standard ones.

.. deprecated-removed:: 3.14 3.16
Invalid, undotted extensions will raise a
:exc:`ValueError` in Python 3.16.


.. _mimetypes-cli:

Expand Down
7 changes: 7 additions & 0 deletions Doc/whatsnew/3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ functools
* Calling the Python implementation of :func:`functools.reduce` with *function*
or *sequence* as keyword arguments has been deprecated since Python 3.14.

mimetypes
---------

* Passing an invalid *ext* (that is, an extension that is not empty and does not
start with a '.') to :meth:`mimetypes.MimeTypes.add_type` now raises a :exc:`ValueError`.
(Contributed by Daniel Watkins, Hugo van Kemenade, and Stan Ulbrych in :gh:`75223`.)

symtable
--------

Expand Down
9 changes: 1 addition & 8 deletions Lib/mimetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,7 @@ def add_type(self, type, ext, strict=True):
Valid extensions are empty or start with a '.'.
"""
if ext and not ext.startswith('.'):
from warnings import _deprecated

_deprecated(
"Undotted extensions",
"Using undotted extensions is deprecated and "
"will raise a ValueError in Python {remove}",
remove=(3, 16),
)
raise ValueError("Extensions should start with a '.' or be empty")

if not type:
return
Expand Down
8 changes: 5 additions & 3 deletions Lib/test/test_mimetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,11 @@ def test_added_types_are_used(self):
mime_type, _ = mimetypes.guess_type('test.myext')
self.assertEqual(mime_type, 'testing/type')

def test_add_type_with_undotted_extension_deprecated(self):
with self.assertWarns(DeprecationWarning):
mimetypes.add_type("testing/type", "undotted")
def test_add_type_with_undotted_extension_raises_exception(self):
Comment thread
hugovk marked this conversation as resolved.
with self.assertRaisesRegex(
ValueError, "Extensions should start with a '.' or be empty"
):
mimetypes.add_type('testing/type', 'undotted')


@unittest.skipUnless(sys.platform.startswith("win"), "Windows only")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Reject undotted extensions in :meth:`mimetypes.MimeTypes.add_type`.
Loading