Skip to content

gh-136507: Fix mimetypes CLI to handle multiple file parameters #136508

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Wulian233
Copy link
Contributor

@Wulian233 Wulian233 commented Jul 10, 2025

@Wulian233
Copy link
Contributor Author

Wulian233 commented Jul 14, 2025

Supplement: #136507 (comment) , so this only in 3.14 and 3.15.

CC: @hugovk could you review this?

@mpkocher
Copy link
Contributor

It's probably a good idea to add both success and failure test case for the multiple provided values (e.g., -e image/jpeg text/html, and -e image/jpeg text/xyz).

@encukou
Copy link
Member

encukou commented Jul 22, 2025

Could you also test the failure case?

@hugovk hugovk changed the title gh-136507: Fix mimetypes CLI cannot handle multiple file parameters gh-136507: Fix mimetypes CLI to handle multiple file parameters Jul 22, 2025
@Wulian233
Copy link
Contributor Author

Could you also test the failure case?

Sorry, I might not have understood it well. 9500cb3 Run this test was failing before the fix, now it runs pass after the fix

…nEuGS.rst

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Lib/mimetypes.py Outdated
results.append(f"type: {guess} encoding: {encoding}")
else:
sys.exit(f"error: media type unknown for {gtype}")
return '\n'.join(results)
return help_text
Copy link
Contributor

Choose a reason for hiding this comment

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

Is return help_text line used?

Either:

  • delete return help_text (that branch of the code is never used)
  • change return help_text to return "\n".join(results) and delete the other return calls at the end of each for type in args.type block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not used, IDE already given a hint

In addition, test failure case have been added

@mpkocher
Copy link
Contributor

Could you also test the failure case?

Sorry, I might not have understood it well. 9500cb3 Run this test was failing before the fix, now it runs pass after the fix

I believe there needs to be a test for the sys.exit calls. For example the case of error: media type unknown for dragons to stderr with a non-zero exit code.

Note that this appears to be slightly changing the interface from a streaming model to a fail fast on the first error case.

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

Successfully merging this pull request may close these issues.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy