Repository navigation
mimetypes CLI cannot handle multiple file parameters #136507
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Jul 10, 2025 - addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on Jul 10, 2025 The change that introduced the issue is here: #131408
There's a few friction points in that commit:
- There's a bit of duplication. We're essentially iterating over a list of strings and calling a function. Try to simplify the model if possible.
- There's no test coverage for the case where multiple values are provided to the command line. These tests would have caught the bug.
- There's already good test coverage on
guess_extensionandguess_type, we can lean more on testing_mainand validating stdout/stderr/exit code (this is similar to the model before the 131408 commit). - There's a bunch of test coverage that is testing argparse and not providing a ton of value. This could be deleted.
Ideally, we should try to fix these issues and simplify the code. Even if this increase the diff quite a bit.
@Wulian233 Here's a few ideas that are in that direction. main...mpkocher:cpython:fix-mimetypes
Perhaps @StanFromIreland can weigh on the direction to take.
Thank you for your supplement. I will add a test case for the multiple provided values in my PR. I think the other changes are a bit too much for a bug fix. main...mpkocher:cpython:fix-mimetypes#diff-aed43839a49bace08b60186baa4b27ad69ecd6b61f928bd696b4fb670750774f
I plan to add one test in my PR. Your improvements are also looks great, perhaps they can be implemented in a new PR?
- added a commit that references this issue
on Oct 7, 2025 (Oops, sorry!)
Bug report
Bug description:
According to
cpython/Lib/mimetypes.py
Line 714 in f519918
, the use of
nargs='+'indicates that the original intention was to support passing multiple files and identifying their MIME types one by oneHowever, the current behavior only processes the first file. For example, running the following command:
> python mimetypes.py 1.pdf 1.png type: application/pdf encoding: Noneonly outputs the type information for
1.pdf, while1.pngis ignored.CPython versions tested on:
3.14
Operating systems tested on:
Windows
Linked PRs