Skip to content

mimetypes CLI cannot handle multiple file parameters #136507

Description

@Wulian233

Bug report

Bug description:

According to

parser.add_argument('type', nargs='+', help='a type to search')

, the use of nargs='+' indicates that the original intention was to support passing multiple files and identifying their MIME types one by one

However, 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: None

only outputs the type information for 1.pdf, while 1.png is ignored.

CPython versions tested on:

3.14

Operating systems tested on:

Windows

Linked PRs

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Jul 10, 2025
  2. mpkocher commented on Jul 14, 2025

    @mpkocher
    Contributor

    The change that introduced the issue is here: #131408

    There's a few friction points in that commit:

    1. 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.
    2. There's no test coverage for the case where multiple values are provided to the command line. These tests would have caught the bug.
    3. There's already good test coverage on guess_extension and guess_type, we can lean more on testing _main and validating stdout/stderr/exit code (this is similar to the model before the 131408 commit).
    4. 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.

  3. Wulian233 commented on Jul 17, 2025

    @Wulian233
    ContributorAuthor

    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?

  4. added a commit that references this issue on Aug 25, 2025
  5. added a commit that references this issue on Aug 25, 2025
  6. added a commit that references this issue on Oct 7, 2025
  7. reopened this on Oct 8, 2025
  8. hugovk commented on Oct 8, 2025

    @hugovk
    Member

    (Oops, sorry!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions