diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index a561d3b3383fc5..9b56ed3ab9928d 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -829,6 +829,10 @@ mimetypes (Contributed by Hugo van Kemenade in :gh:`129965`.) +* Add :rfc:`9512` ``application/yaml`` MIME type for YAML files (``.yaml`` + and ``.yml``). (Contributed by Sasha "Nelie" Chernykh and Hugo van Kemenade + in :gh:`132056`.) + multiprocessing --------------- diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py index 6b94fe3c4df756..2c56c5469fb1c5 100644 --- a/Lib/mimetypes.py +++ b/Lib/mimetypes.py @@ -544,6 +544,8 @@ def _default_mime_types(): '.rdf' : 'application/xml', '.wsdl' : 'application/xml', '.xpdl' : 'application/xml', + '.yaml' : 'application/yaml', + '.yml' : 'application/yaml', '.zip' : 'application/zip', '.3gp' : 'audio/3gpp', '.3gpp' : 'audio/3gpp', diff --git a/Lib/test/test_mimetypes.py b/Lib/test/test_mimetypes.py index b5d1f50099e16a..26a32c56761074 100644 --- a/Lib/test/test_mimetypes.py +++ b/Lib/test/test_mimetypes.py @@ -244,6 +244,7 @@ def check_extensions(): ("application/x-texinfo", ".texi"), ("application/x-troff", ".roff"), ("application/xml", ".xsl"), + ("application/yaml", ".yaml"), ("audio/flac", ".flac"), ("audio/matroska", ".mka"), ("audio/mp4", ".m4a"), @@ -286,6 +287,26 @@ def check_extensions(): mimetypes.init() check_extensions() + def test_guess_file_type(self): + def check_file_type(): + for mime_type, ext in ( + ("application/yaml", ".yaml"), + ("application/yaml", ".yml"), + ("audio/mpeg", ".mp2"), + ("audio/mpeg", ".mp3"), + ("video/mpeg", ".m1v"), + ("video/mpeg", ".mpe"), + ("video/mpeg", ".mpeg"), + ("video/mpeg", ".mpg"), + ): + with self.subTest(mime_type=mime_type, ext=ext): + result, _ = mimetypes.guess_file_type(f"filename{ext}") + self.assertEqual(result, mime_type) + + check_file_type() + mimetypes.init() + check_file_type() + def test_init_stability(self): mimetypes.init() diff --git a/Misc/NEWS.d/next/Library/2025-04-03-20-28-54.gh-issue-132054.c1nlOx.rst b/Misc/NEWS.d/next/Library/2025-04-03-20-28-54.gh-issue-132054.c1nlOx.rst new file mode 100644 index 00000000000000..b9602c0b2ca1c6 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-04-03-20-28-54.gh-issue-132054.c1nlOx.rst @@ -0,0 +1,2 @@ +The ``application/yaml`` mime type (:rfc:`9512`) is now supported +by :mod:`mimetypes`. Patch by Sasha "Nelie" Chernykh and Hugo van Kemenade.