https://github.com/python/cpython/commit/0534774a472424f6b9be2dc4ce9784384bc02401
commit: 0534774a472424f6b9be2dc4ce9784384bc02401
branch: main
author: sobolevn <[email protected]>
committer: sobolevn <[email protected]>
date: 2026-05-12T13:40:21Z
summary:

gh-149720: Remove support for undotted `ext` in `mimetypes.MimeType.add_type` 
(#149721)

files:
A Misc/NEWS.d/next/Library/2026-05-12-14-44-39.gh-issue-149720.ccsoW-.rst
M Doc/library/mimetypes.rst
M Doc/whatsnew/3.16.rst
M Lib/mimetypes.py
M Lib/test/test_mimetypes.py

diff --git a/Doc/library/mimetypes.rst b/Doc/library/mimetypes.rst
index 0facacd50fd389..eed9acb92e0c95 100644
--- a/Doc/library/mimetypes.rst
+++ b/Doc/library/mimetypes.rst
@@ -129,10 +129,18 @@ behavior of the module.
    Add a mapping from the MIME type *type* to the extension *ext*. 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.
+   Valid extensions are empty or start with a ``'.'``.
 
    When *strict* is ``True`` (the default), the mapping will be added to the
    official MIME types, otherwise to the non-standard ones.
 
+   .. deprecated:: 3.14
+      *ext* values that do not start with ``'.'`` are deprecated.
+
+   .. versionchanged:: next
+      *ext* now must start with ``'.'``. Otherwise :exc:`ValueError` is raised.
+
+
 
 .. data:: inited
 
diff --git a/Doc/whatsnew/3.16.rst b/Doc/whatsnew/3.16.rst
index 6d91d53f478d8e..f79f976ee55cfa 100644
--- a/Doc/whatsnew/3.16.rst
+++ b/Doc/whatsnew/3.16.rst
@@ -127,6 +127,13 @@ logging
   and scheduled for removal in Python 3.16. Define handlers with the *stream*
   argument instead.
 
+mimetypes
+---------
+
+* Valid extensions start with a '.' or are empty for
+  :meth:`mimetypes.MimeTypes.add_type`.
+  Undotted extensions now raise a :exc:`ValueError`.
+
 symtable
 --------
 
diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py
index 6d9278bccf927e..15e8c0a437bfd9 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(f"Extension {ext!r} must start with '.'")
 
         if not type:
             return
diff --git a/Lib/test/test_mimetypes.py b/Lib/test/test_mimetypes.py
index 2d618081521e10..607aff8418edcf 100644
--- a/Lib/test/test_mimetypes.py
+++ b/Lib/test/test_mimetypes.py
@@ -389,9 +389,12 @@ 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):
+    def test_add_type_with_undotted_extension_not_supported(self):
+        msg = "Extension 'undotted' must start with '.'"
+        with self.assertRaisesRegex(ValueError, msg):
             mimetypes.add_type("testing/type", "undotted")
+        with self.assertRaisesRegex(ValueError, msg):
+            mimetypes.add_type("", "undotted")
 
 
 @unittest.skipUnless(sys.platform.startswith("win"), "Windows only")
diff --git 
a/Misc/NEWS.d/next/Library/2026-05-12-14-44-39.gh-issue-149720.ccsoW-.rst 
b/Misc/NEWS.d/next/Library/2026-05-12-14-44-39.gh-issue-149720.ccsoW-.rst
new file mode 100644
index 00000000000000..f16d8770d740f4
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-05-12-14-44-39.gh-issue-149720.ccsoW-.rst
@@ -0,0 +1 @@
+Remove support for undotted *ext* in :meth:`mimetypes.MimeTypes.add_type`.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to