Skip to content

Fix list[Literal] fields rejecting valid values - #380

Open
anishpentyala wants to merge 2 commits into
lebrice:masterfrom
anishpentyala:fix/list-literal-parser
Open

anishpentyala wants to merge 2 commits into
lebrice:masterfrom
anishpentyala:fix/list-literal-parser

Conversation

@anishpentyala

Copy link
Copy Markdown

Fixes #374.

get_argparse_type_for_container() currently returns the raw Literal[...] annotation as the argparse item converter. Literal is not callable, so list fields reject valid input such as --colors red green.

Use the existing parse_literal() converter for Literal item types, just as this function already delegates Enum items to parse_enum(). This keeps validation and the actual literal value types, including integer literals. No new parser or dependency is added.

Add regressions for string literals, integer literals, and optional list containers. They cover defaults, valid multiple values, and rejection of values outside the Literal choices. The scope is list containers with Literal items; this does not add support for nested Optional item types or sets.

Validation

Python 3.12.15, pytest 9.2.0, same local environment:

  • All 3 new tests fail against the original runtime with argparse exit code 2 on valid input.
  • Fixed literal suite: 13 passed, 1 skipped, 21 xfailed.
  • Full baseline: 1 failed, 1257 passed, 13 skipped, 96 xfailed, 9 xpassed, 2 warnings.
  • Full fresh clone of this exact public tree: 1 failed, 1260 passed, with the same skips, expected failures, unexpected passes, and warnings.

The shared failure is test_bool_args_in_help, the pre-existing master help-text mismatch addressed separately by #379. Full-suite commands use -o addopts=''; these are not claims about the complete hosted matrix or doctest coverage.

The changed files pass Ruff 0.1.14 lint/format checks and the project's pinned docformatter revision. Hosted CI is pending.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

list[Literal[...]] fields reject valid values

1 participant