Skip to content

GH-130750: Restore quoting of choices in argparse error messages to match documentation and improve clarity#144983

Open
savannahostrowski wants to merge 3 commits intopython:mainfrom
savannahostrowski:fix-suggestion
Open

GH-130750: Restore quoting of choices in argparse error messages to match documentation and improve clarity#144983
savannahostrowski wants to merge 3 commits intopython:mainfrom
savannahostrowski:fix-suggestion

Conversation

@savannahostrowski
Copy link
Member

@savannahostrowski savannahostrowski commented Feb 19, 2026

In 66b3922 (gh-117766), argparse was changed to use str() instead of repr() when displaying choices in error messages. This was done to improve StrEnum display, but had the side effect of removing quotes from string choices, making error messages less clear and inconsistent with the documentation.

This PR restores quoting and adds special handling for Enum members to display just the quoted value (e.g., 'red' instead of <Color.RED: 'red'>). This also improves clarity for mixed-type choices (e.g., 1, '2' clearly shows int vs string).

@savannahostrowski savannahostrowski added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Feb 19, 2026
@savannahostrowski savannahostrowski changed the title GH-130751: Restore quoting of choices in argparse error messages to match documentation and improve clarity GH-130750: Restore quoting of choices in argparse error messages to match documentation and improve clarity Feb 19, 2026
Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

I support explicit quotes, because bar in Python is a variable name, 'bar' is a string. 👍

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

Labels

awaiting merge needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments