Skip to content

Add to_argv utility function that constructs an argv list. - #187

Open
carlosgmartin wants to merge 1 commit into
swansonk14:mainfrom
carlosgmartin:to_argv
Open

carlosgmartin wants to merge 1 commit into
swansonk14:mainfrom
carlosgmartin:to_argv

Conversation

@carlosgmartin

@carlosgmartin carlosgmartin commented Aug 15, 2026 •

Copy link
Copy Markdown

Fixes #186.

@martinjm97

Copy link
Copy Markdown
Collaborator

Hi @carlosgmartin,

Thank you for this PR!

Our key concern is that it is often challenging to automatically reconstruct the argument list from an object instance. For example,

from tap import Tap


class Args(Tap):
    number: int

    def configure(self) -> None:
        self.add_argument("--number", type=lambda value: int(value) + 1)

The original argument is parsed as follows:

args = Args().parse_args(["--number", "1"])
assert args.number == 2

to_argv(args) would stringify the resulting value:

argv = to_argv(args)
assert argv == ["--number", "2"]

Reparsing those arguments changes the value again:

reparsed = Args().parse_args(argv)
assert reparsed.number == 3

Therefore:

assert args.as_dict() != reparsed.as_dict()

Tap and argparse do not require an argument’s type converter to satisfy type_converter(str(value)) == value, so to_argv() cannot generally guarantee a lossless round trip.

More generally, it is challenging to support custom actions, subparsers, complex nargs, duplicate destinations, and other configurations whose final values do not uniquely determine a valid list[str] input.

We will leave this issue open for a few weeks for potential further discussion.

Thanks again and we wish you happy Tapping,
JK

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.

Feature request: Add to_argv utility function

2 participants