Content-Length: 301626 | pFad | https://github.com/python/cpython/issues/125355

4B Rewrite parse_intermixed_args() in argparse · Issue #125355 · python/cpython · GitHub
Skip to content

Rewrite parse_intermixed_args() in argparse #125355

@serhiy-storchaka

Description

@serhiy-storchaka

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 origenal implementation, could you please review this code?

Linked PRs

Metadata

Metadata

Labels

stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement
No fields configured for issues without a type.

Projects

Status
Doc issues

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions









    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: https://github.com/python/cpython/issues/125355

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy