* Calling the Python implementation of :func:`functools.reduce` with *function*
or *sequence* as keyword arguments has been deprecated since Python 3.14.
+* :mod:`mimetypes`:
+
+ * Valid extensions start with a '.' or are empty for
+ :meth:`mimetypes.MimeTypes.add_type`.
+ Undotted extensions are deprecated and will
+ raise a :exc:`ValueError` in Python 3.16.
+ (Contributed by Hugo van Kemenade in :gh:`75223`.)
+
* :mod:`shutil`:
* The :class:`!ExecError` exception
.. method:: MimeTypes.add_type(type, ext, strict=True)
- Add a mapping from the MIME type *type* to the extension *ext*. When the
+ Add a mapping from the MIME type *type* to the extension *ext*.
+ Valid extensions start with a '.' or are empty. When the
extension is already known, the new type will replace the old one. When the type
is already known the extension will be added to the list of known extensions.
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:
and scheduled for removal in Python 3.16. Define handlers with the *stream*
argument instead. (Contributed by Mariusz Felisiak in :gh:`115032`.)
+* :mod:`mimetypes`:
+ Valid extensions start with a '.' or are empty for
+ :meth:`mimetypes.MimeTypes.add_type`.
+ Undotted extensions are deprecated and will
+ raise a :exc:`ValueError` in Python 3.16.
+ (Contributed by Hugo van Kemenade in :gh:`75223`.)
+
* :mod:`!nturl2path`: This module is now deprecated. Call
:func:`urllib.request.url2pathname` and :func:`~urllib.request.pathname2url`
instead.
If strict is true, information will be added to
list of standard types, else to the list of non-standard
types.
+
+ 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),
+ )
+
if not type:
return
self.types_map[strict][ext] = type
self.assertEqual(self.db.guess_extension(
type='image/jpg', strict=False), '.jpg')
+ def test_added_types_are_used(self):
+ mimetypes.add_type('testing/default-type', '')
+ mime_type, _ = mimetypes.guess_type('')
+ self.assertEqual(mime_type, 'testing/default-type')
+
+ mime_type, _ = mimetypes.guess_type('test.myext')
+ self.assertEqual(mime_type, None)
+
+ mimetypes.add_type('testing/type', '.myext')
+ 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")
+
@unittest.skipUnless(sys.platform.startswith("win"), "Windows only")
class Win32MimeTypesTestCase(unittest.TestCase):
--- /dev/null
+Deprecate undotted extensions in :meth:`mimetypes.MimeTypes.add_type`.
+Patch by Hugo van Kemenade.