You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Rewrite parse_intermixed_args() in argparse #125355
parse_intermixed_args() and parse_known_intermixed_args() are implemented by parsing command lines twice -- first only optional arguments, then the remaining is parsed as positional arguments. This approach has some issues.
The parser is temporary modified to suppress positional or required optional arguments in these two stages. This is not good, because the parser can no longer be used concurrently. This also smells bad in general, this can hide some bugs.
Default values are handled twice.
Unknown options in parse_known_intermixed_args() cannot be intermixed with positional arguments. Well, "parsing only known arguments" is a dubious feature, but still...
I tried to rewrite the implementation by moving the code deeper. No longer parser patching, defaults are handled only once, unknown options are excluded from positionals parsing. @hpaulj, @bitdancer, as the authors of the original implementation, could you please review this code?
Wish the internal API for _parse_known_args had a default of intermixed=False so usage of it wasn't broken. This broke scriptconfig. I'm able to work around it on my end though.
Activity
pythongh-125355: Rewrite parse_intermixed_args() in argparse
serhiy-storchaka commentedon Oct 12, 2024
For reference, the original feature was implemented in bpo-14191(gh-58399), PR #3319, 0f6b9d2.
serhiy-storchaka commentedon Oct 12, 2024
This also fixes support for required mutually exclusive groups containing positionals.
gh-125355: Rewrite parse_intermixed_args() in argparse (GH-125356)
pythongh-125355: Rewrite parse_intermixed_args() in argparse (pythonG…
[3.13] gh-125355: Rewrite parse_intermixed_args() in argparse (GH-125356
[3.12] pythongh-125355: Rewrite parse_intermixed_args() in argparse (p…
[3.12] gh-125355: Rewrite parse_intermixed_args() in argparse (GH-125356
pythongh-125355: Rewrite parse_intermixed_args() in argparse (pythonG…
Erotemic commentedon Jan 16, 2025
Wish the internal API for
_parse_known_argshad a default ofintermixed=Falseso usage of it wasn't broken. This broke scriptconfig. I'm able to work around it on my end though.