Skip to content

gh-132054: Add application/yaml to mimetypes #132056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
Changes from 8 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
3 changes: 3 additions & 0 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,9 @@ mimetypes

(Contributed by Hugo van Kemenade in :gh:`129965`.)

* Add :rfc:`9512` ``application/yaml`` MIME type for YAML files (``.yaml``
and ``.yml``). (Contributed by Kristinita in :gh:`132056`.)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kristinita We can put your full name here if you like.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hugovk, thanks for adding the function test_guess_file_type()!

My contribution here is insignificant, and I think it would be more fair if you will add your name instead of my.

(But if the name of the author of the pull request is required, perhaps, Sasha “Nelie” Chernykh instead of Kristinita would be better).

Thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You contribution is not insignificant. I've put both our names there, thanks again!



multiprocessing
---------------
Expand Down
2 changes: 2 additions & 0 deletions Lib/mimetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
21 changes: 21 additions & 0 deletions Lib/test/test_mimetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The ``application/yaml`` mime type (:rfc:`9512`) is now supported
by :mod:`mimetypes`.
Loading