diff --git a/Doc/library/mimetypes.rst b/Doc/library/mimetypes.rst index 0facacd50fd389..e8dd51dcbfd99e 100644 --- a/Doc/library/mimetypes.rst +++ b/Doc/library/mimetypes.rst @@ -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: diff --git a/Doc/whatsnew/3.16.rst b/Doc/whatsnew/3.16.rst index d9beda92aba6a3..65036b7b16529e 100644 --- a/Doc/whatsnew/3.16.rst +++ b/Doc/whatsnew/3.16.rst @@ -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 -------- diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py index 6d9278bccf927e..7e6351db0249c0 100644 --- a/Lib/mimetypes.py +++ b/Lib/mimetypes.py @@ -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 diff --git a/Lib/test/test_mimetypes.py b/Lib/test/test_mimetypes.py index 2d618081521e10..07bb63b3fd0280 100644 --- a/Lib/test/test_mimetypes.py +++ b/Lib/test/test_mimetypes.py @@ -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): + 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") diff --git a/Misc/NEWS.d/next/Library/2019-09-10-09-28-52.gh-issue-75223.VyAJS9.rst b/Misc/NEWS.d/next/Library/2019-09-10-09-28-52.gh-issue-75223.VyAJS9.rst new file mode 100644 index 00000000000000..bafcbe1b714b72 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-09-10-09-28-52.gh-issue-75223.VyAJS9.rst @@ -0,0 +1 @@ +Reject undotted extensions in :meth:`mimetypes.MimeTypes.add_type`.