Repository navigation
Conversation
get_metavar() had no case for Literal, so `Literal[...] | None` and
`tuple[Literal[...], ...]` showed the type name "Literal" in --help.
It now returns the choices in argparse's "{a,b,c}" form (Enum members by
name), and the Optional and tuple cases reuse it through recursion.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #375.
get_metavar()had no case forLiteral, so a Literal nested inOptional,tuple[..., ...]or aUnionshowed up in--helpasLiteral. It now returns the choices in argparse's{a,b,c}form, with Enum members by name asFieldWrapper.choicesdoes. The Optional, tuple and Union branches already callget_metavar()on their arguments, so they pick it up:A plain
Literalfield is unchanged, since that path drops the metavar and lets argparse print the choices.list[Literal[...]]still showslist; the issue says that one is reported separately.The new test in test_literal.py fails on master and passes with the change. On Python 3.11 the full suite gives 1267 passed and one failure,
test_bool_args_in_help, which fails on master for me too.