-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
In [1]: import argparse
...: parser = argparse.ArgumentParser()
...: parser.add_argument('--foobar', action=argparse.BooleanOptionalAction)
...: parser.add_argument('--foo', action="store_true")
...: parser.parse_args(['--no-foo'])
Out[1]: Namespace(foobar=False, foo=False)
In [2]: parser = argparse.ArgumentParser()
...: parser.add_argument('--foo-bar', action=argparse.BooleanOptionalAction)
...: parser.add_argument('--foo', action="store_true")
...: parser.parse_args(['--no-foo'])
Out[2]: Namespace(foo_bar=False, foo=False)
Is this expected? There is no '--no-foo' option, but using it sets '--foobar', '--foo-bar' and '--foo' to False. I have tested this on Python 3.12.10 and Python 3.13.3.
CPython versions tested on:
3.13
Operating systems tested on:
Windows
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
Status
Doc issues