Open
Description
I think something is broken in mimetype.guess_type
or documentation did not cover the change ...
A small working example and its outputs for different Python versions are listed below.
In this example the value from a concrete mimetypes.types_map
entry should
match to the returnvalue of mimetypes.guess_type
in all tested Python versions:
But it did not; the return value of mimetypes.guess_type
is wrong from my point of view.
Operating system and architecture:
Windows 10/WSL
$ uname -s -v -i -m -p -o
Linux #1237-Microsoft Sat Sep 11 14:32:00 PST 2021 x86_64 x86_64 x86_64 GNU/Linux
Ubuntu
$ uname -s -v -i -m -p -o
Linux #220-Ubuntu SMP Thu May 9 12:40:49 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
Small working example : mimetest.py
import mimetypes
mimetypes.init()
MIMETYPE_ADDITIONAL_EXTENSIONS = [("text/x-r-script", ".R"), ]
for (mimetype, extension) in MIMETYPE_ADDITIONAL_EXTENSIONS:
mimetypes.add_type(mimetype, extension, strict=True)
print("mimetypes.types_map['.R'] = %s , mimetypes.guess_type('example.R')[0] = %s" % (mimetypes.types_map['.R'],mimetypes.guess_type('example.R')[0]))
Running this via multiple Python versions is showing the problem:
Python 2.7.17
mimetypes.types_map['.R'] = text/x-r-script , mimetypes.guess_type('example.R')[0] = text/x-r-script
Python 3.5.6
mimetypes.types_map['.R'] = text/x-r-script , mimetypes.guess_type('example.R')[0] = text/x-r-script
Python 3.6.13
mimetypes.types_map['.R'] = text/x-r-script , mimetypes.guess_type('example.R')[0] = text/x-r-script
Python 3.9.7
mimetypes.types_map['.R'] = text/x-r-script , mimetypes.guess_type('example.R')[0] = text/x-r-script
Python 3.9.11
mimetypes.types_map['.R'] = text/x-r-script , mimetypes.guess_type('example.R')[0] = None
Python 3.9.12
mimetypes.types_map['.R'] = text/x-r-script , mimetypes.guess_type('example.R')[0] = None
Python 3.10.4
mimetypes.types_map['.R'] = text/x-r-script , mimetypes.guess_type('example.R')[0] = None
perhaps this different behavior is a result of issue #64591
and its related merged pull requests
- [python:main] bpo-20392: Fix inconsistency with uppercase file extensions in mimetypes.guess_type #30229
- [python:3.9] [3.9] bpo-20392: Fix inconsistency with uppercase file extensions in mimetypes.guess_type (GH-30229) #31903
- [python:3.10] [3.10] bpo-20392: Fix inconsistency with uppercase file extensions in mimetypes.guess_type (GH-30229) #31904