GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-131178: Fix mimetypes CLI docs to mention that errors go to stdout by htjworld · Pull Request #149683 · python/cpython

Conversation

@htjworld

@htjworld htjworld commented May 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

The mimetypes documentation states that errors go to the standard error stream, but the CLI has always written all output — including errors — to stdout.

Fix the documentation to match the actual behavior, and add subprocess-based tests for the command-line interface.

Changes:

  • Doc/library/mimetypes.rst: Correct "standard error stream" → "standard output stream"; update stale examples (filename.pict is now a recognized type, error message strings did not match actual output).
  • Lib/test/test_mimetypes.py: Add subprocess-based tests verifying CLI output format and exit codes.
  • Issue: Add tests for command-line interface #131178

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@htjworld
pythongh-149682: Fix mimetypes CLI to write error messages to stderr
c87667b
@htjworld
htjworld requested a review from a team as a code owner May 11, 2026 14:39
@bedevere-app bedevere-app Bot mentioned this pull request May 11, 2026
mimetypes CLI writes error messages to stdout instead of stderr #149682
Closed
@bedevere-app bedevere-app Bot added the awaiting review label May 11, 2026
@htjworld htjworld mentioned this pull request May 11, 2026
gh-131178: Add tests for mimetypes command-line interface #149681
Closed
@htjworld
Remove inline comments from docs examples
77e5b2a
@read-the-docs-community

read-the-docs-community Bot commented May 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #32921239 | 📁 Comparing 4b28aed against main (2d3dec0)

  🔍 Preview build  

63 files changed · + 1 added · ± 62 modified

+ Added

  • deprecations/pending-removal-in-3.21.html

± Modified

  • glossary.html
  • index.html
  • c-api/import.html
  • c-api/sentinel.html
  • c-api/stable.html
  • c-api/threads.html
  • deprecations/index.html
  • deprecations/pending-removal-in-3.16.html
  • howto/free-threading-python.html
  • library/audit_events.html
  • and 52 more...
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@htjworld htjworld changed the title gh-149682: Fix mimetypes CLI to write error messages to stderr Fix mimetypes CLI to write error messages to stderr May 11, 2026
@htjworld htjworld changed the title Fix mimetypes CLI to write error messages to stderr gh-149682: Fix mimetypes CLI to write error messages to stderr May 11, 2026
@htjworld htjworld changed the title gh-149682: Fix mimetypes CLI to write error messages to stderr gh-131178: Fix mimetypes CLI to write error messages to stderr May 11, 2026
@bedevere-app bedevere-app Bot mentioned this pull request May 11, 2026
Add tests for command-line interface #131178
Open
7 of 9 tasks
sobolevn
sobolevn reviewed May 11, 2026
View reviewed changes

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This is a rather hard problem: when docs do not represent the reality, we can either fix docs or fix the code.

I guess a lot of places already rely on the fact that errors and results are in the stdout, not in stderr.

So, I think that it would be better to change the docs.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/test/test_mimetypes.py Outdated

def test_type_lookup(self):
rc, stdout, stderr = assert_python_ok('-m', 'mimetypes', 'foo.pdf')
self.assertIn(b'application/pdf', stdout)

@sobolevn sobolevn May 11, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Why not asserting the full stdout contents?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

htjworld reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Lib/test/test_mimetypes.py Outdated
def test_type_lookup_unknown(self):
rc, stdout, stderr = assert_python_failure('-m', 'mimetypes', 'foo.unknownext12345')
self.assertEqual(stdout, b'')
self.assertIn(b'error:', stderr)

@sobolevn sobolevn May 11, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

And the same here: we can assert the full error response.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

htjworld reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Lib/mimetypes.py Outdated
has_error = False
for result in results:
if result.startswith("error: "):
print(result, file=sys.stderr, flush=True)

@sobolevn sobolevn May 11, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This is a behavior change, please revert it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

htjworld reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Misc/NEWS.d/next/Library/2026-05-11-23-38-47.gh-issue-149682.UE08R4.rst Outdated
@@ -0,0 +1,2 @@
Fix :mod:`mimetypes` CLI to write error messages to stderr instead of stdout,

@sobolevn sobolevn May 11, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

And since we revert the behavior change, we need to remove this file as well :)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

htjworld reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
htjworld added 2 commits May 12, 2026 00:33
@htjworld
Address review feedback: revert stderr routing, update docs and tests
5b75aaa
Per sobolevn's review: revert the behavior change that routed error
messages to stderr, as existing code may rely on stdout behavior.
Instead update docs to accurately reflect that errors go to stdout.

Also update tests to assert full output contents as suggested.
@htjworld
Add NEWS entry for mimetypes CLI tests
ad605cd
@htjworld

htjworld commented May 11, 2026

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting change review and removed awaiting review labels May 11, 2026
@bedevere-app

bedevere-app Bot commented May 11, 2026

Copy link
Copy Markdown

Thanks for making the requested changes!

: please review the changes made to this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

sobolevn
sobolevn reviewed May 11, 2026
View reviewed changes
Comment thread Lib/test/test_mimetypes.py Outdated

def test_unknown_flag(self):
rc, stdout, stderr = assert_python_failure('-m', 'mimetypes', '--unknown-flag')
self.assertNotEqual(rc, 0)

@sobolevn sobolevn May 11, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

assert the output please :)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

htjworld reacted with laugh emoji
All reactions
  • 😄 1 reaction
Comment thread Misc/NEWS.d/next/Tests/2026-05-12-00-35-20.gh-issue-131178.mX9pQa.rst Outdated
@@ -0,0 +1,2 @@
Add subprocess-based tests for the :mod:`mimetypes` command-line interface,

@sobolevn sobolevn May 11, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

we don't add news for docs / tests only changes.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

htjworld reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Lib/test/test_mimetypes.py Outdated

def test_extension_flag(self):
rc, stdout, stderr = assert_python_ok('-m', 'mimetypes', '-e', 'image/jpeg')
self.assertIn(b'.jpg', stdout)

@sobolevn sobolevn May 11, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Let's use assertEqual here as well.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

htjworld reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@htjworld
Address review feedback: strengthen test assertions, remove NEWS entry
f6db7b1
@htjworld

htjworld commented May 11, 2026

Copy link
Copy Markdown
Contributor Author

thanks for the review appreciate it
I have made the requested changes; please review again

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app

bedevere-app Bot commented May 11, 2026

Copy link
Copy Markdown

Thanks for making the requested changes!

: please review the changes made to this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

sobolevn
sobolevn reviewed May 12, 2026
View reviewed changes
Comment thread Lib/test/test_mimetypes.py Outdated
def test_unknown_flag(self):
rc, stdout, stderr = assert_python_failure('-m', 'mimetypes', '--unknown-flag')
self.assertEqual(stdout, b'')
self.assertIn(b'error', stderr)

@sobolevn sobolevn May 12, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Suggested change
self.assertIn(b'error', stderr)
self.assertIn(b'error: unrecognized arguments: --unknown-flag', stderr)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

clin1234 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@sobolevn sobolevn added the skip news label May 12, 2026
@htjworld
pythongh-131178: fix test_unknown_flag to supply positional arg
edf95da
@python-cla-bot

python-cla-bot Bot commented May 12, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@htjworld
pythongh-131178: add @force_not_colorized to test_unknown_flag
b00896c
sobolevn
sobolevn approved these changes May 12, 2026
View reviewed changes

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting change review labels May 12, 2026
clin1234
clin1234 reviewed May 12, 2026
View reviewed changes

@clin1234 clin1234 left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

If CI passes, it LGTM ;-)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@htjworld

htjworld commented May 31, 2026

Copy link
Copy Markdown
Contributor Author

Hi @sobolevn, gentle ping 🙂 — is there anything else needed on my end for this to move forward? Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sobolevn sobolevn changed the title gh-131178: Fix mimetypes CLI to write error messages to stderr gh-131178: Fix mimetypes CLI docs to mention that errors go to stdout May 31, 2026
@sobolevn sobolevn added needs backport to 3.15 bugs and security fixes needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes labels May 31, 2026
@sobolevn
Merge branch 'main' into pythongh-149682-mimetypes-fix-stderr
e0409b3
sobolevn
sobolevn reviewed May 31, 2026
View reviewed changes
Comment thread Doc/library/mimetypes.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/mimetypes.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@htjworld
pythongh-131178: revert unnecessary CLI example changes in mimetypes …
277b007
…docs

Restore the original filename.pict / --lenient example and the
filename.xxx multi-input example. Keep only the genuinely-needed
fix: the error message string ("unknown extension of X" was never
emitted; the CLI prints "media type unknown for X").
sobolevn
sobolevn reviewed May 31, 2026
View reviewed changes
Comment thread Doc/library/mimetypes.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@htjworld @sobolevn
Update Doc/library/mimetypes.rst
4b28aed
Co-authored-by: sobolevn <[email protected]>
sobolevn
sobolevn approved these changes May 31, 2026
View reviewed changes
@sobolevn

sobolevn commented May 31, 2026

Copy link
Copy Markdown
Member

Thanks a lot!

htjworld reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sobolevn
sobolevn enabled auto-merge (squash) May 31, 2026 07:17
@htjworld

htjworld commented May 31, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for the thorough review!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sobolevn
sobolevn merged commit 2b94b92 into python:main May 31, 2026
52 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app

miss-islington-app Bot commented May 31, 2026

Copy link
Copy Markdown

Thanks @htjworld for the PR, and @sobolevn for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label May 31, 2026
@miss-islington-app

miss-islington-app Bot commented May 31, 2026

Copy link
Copy Markdown

Sorry, @htjworld and @sobolevn, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 2b94b923943a1f75cdbd5a5e4e2eb5f93eb43e23 3.13
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app

bedevere-app Bot commented May 31, 2026

Copy link
Copy Markdown

GH-150655 is a backport of this pull request to the 3.15 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label May 31, 2026
@miss-islington-app miss-islington-app Bot assigned sobolevn May 31, 2026
@bedevere-app

bedevere-app Bot commented May 31, 2026

Copy link
Copy Markdown

GH-150656 is a backport of this pull request to the 3.14 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label May 31, 2026
@sobolevn

sobolevn commented May 31, 2026

Copy link
Copy Markdown
Member

@htjworld can you please follow the instructions in #149683 (comment) and create a manual 3.13 backport?

htjworld reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@htjworld

htjworld commented May 31, 2026

Copy link
Copy Markdown
Contributor Author

@sobolevn, I looked into the 3.13 backport — the mimetypes CLI was reworked after 3.13, so the changes don't seem to apply cleanly:

  • The Command-line usage section this PR edits doesn't exist in 3.13 (it appears to have been added in 3.14).
  • The 3.13 CLI still uses the old getopt-based implementation and prints I don't know anything about type X rather than error: media type unknown for X, so the new CommandLineSubprocessTest assertions would fail there.

Would it make sense to drop the needs backport to 3.13 label?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sobolevn

sobolevn commented May 31, 2026

Copy link
Copy Markdown
Member

Then no - thanks for the investigation :)

htjworld reacted with thumbs up emoji htjworld reacted with laugh emoji
All reactions
  • 👍 1 reaction
  • 😄 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

sobolevn added a commit that referenced this pull request May 31, 2026
@miss-islington @htjworld @sobolevn
[3.14] gh-131178: Fix mimetypes CLI docs, mention that errors go to s…
15eb113
…tdout (GH-149683) (#150656)

gh-131178: Fix mimetypes CLI docs, mention that errors go to stdout (GH-149683)
(cherry picked from commit 2b94b92)

Co-authored-by: htjworld <[email protected]>
Co-authored-by: sobolevn <[email protected]>
sobolevn added a commit that referenced this pull request May 31, 2026
@miss-islington @htjworld @sobolevn
[3.15] gh-131178: Fix mimetypes CLI docs, mention that errors go to s…
2ff80c7
…tdout (GH-149683) (#150655)

gh-131178: Fix mimetypes CLI docs, mention that errors go to stdout (GH-149683)
(cherry picked from commit 2b94b92)

Co-authored-by: htjworld <[email protected]>
Co-authored-by: sobolevn <[email protected]>
@StanFromIreland StanFromIreland removed the needs backport to 3.13 only security fixes label Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@sobolevn sobolevn sobolevn approved these changes
+1 more reviewer
@clin1234 clin1234 clin1234 left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@sobolevn sobolevn

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@htjworld @sobolevn @clin1234 @StanFromIreland
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.