python / python/cpython

argparse with option/value like --gpg-options "--homedir=/home/user" errors out but adding binding op works.

Open
#118,551 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type-bug
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

--gpg-options is defined as follows:

    gpg_options=dict(
        metavar=_("options"),
        action=SplitOptionsAction,
        help="Verbatim gpg options.  May be supplied multiple times.",
        default=dflt(config.gpg_options),
    ),

This does not work (using space):

prog --gpg-options "--homedir=/home/user"

and gets argument --gpg-options: expected one argument

But this one does (using the binding op):

prog --gpg-options="--homedir=/home/user"

with gpg_options being set correctly.

The deprecated optparse handled this correctly.

See Also:
https://gitlab.com/duplicity/duplicity/-/issues/795
https://gitlab.com/duplicity/duplicity/-/issues/816

CPython versions tested on:

3.8, 3.9, 3.10, 3.11, 3.12

Operating systems tested on:

Linux, macOS

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the argparse handling for options whose values begin with --, using the reported --gpg-options "--homedir=/home/user" command as the reproducer. Add coverage for the space-separated form alongside the binding-operator form, and confirm the option value is accepted correctly across the relevant tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.