Skip to content

Support options with optional arguments #126374

Closed
@serhiy-storchaka

Description

@serhiy-storchaka

Feature or enhancement

GNU getopt supports options with optional arguments. For example GNU grep can be used with option --color=auto and with just --color. Unix getopt does not need it, because it stops after encountering first nonoption argument, but GNU getopt needs it to support options intermixed with positional arguments. getopt.gnu_getopt() needs it for the same reason.

Neither optparse nor argparse directly support such kind of optional arguments. It can be supported in optparse with custom callback, but support of optional arguments in argparse is non-standard. In future I'm planning to add support of such kind of optional arguments in argparse, and maybe in optparse.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixesstdlibPython modules in the Lib dirtype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions