ThomasWaldmann / argparse

python argparse, pypi version (moved from google code)
Other
59 stars 18 forks source link

Issue with argument_group and required add_mutually_exclusive_group #95

Closed pneff closed 3 years ago

pneff commented 8 years ago

The snippet below does behave differently with the PyPI version than it does with any of the built-in versions from Python 2.7+.

from __future__ import print_function

import argparse

parser = argparse.ArgumentParser()

group = parser.add_argument_group('Source arguments')
# Add mutually exclusive group to the argument group.
# The problem only appears in that combination. When using
# a mutually exclusive group without an argument group, then
# the code works consistently across all argparse versions.
oneof = group.add_mutually_exclusive_group(required=True)
oneof.add_argument('--option1')
oneof.add_argument('--option2')

print(parser.parse_args())

Test output from the various Python versions (all on Windows)

Python 2.7 with Pypi package

python parse_test.py
Namespace(option1=None, option2=None)

Python 2.7

c:\python27\python .\parse_test.py
usage: parse_test.py [-h] (--option1 OPTION1 | --option2 OPTION2)
parse_test.py: error: one of the arguments --option1 --option2 is required

Python 3.4

C:\Python34\python .\parse_test.py
usage: parse_test.py [-h] (--option1 OPTION1 | --option2 OPTION2)
parse_test.py: error: one of the arguments --option1 --option2 is required

Python 2.5

C:\Python35\python .\parse_test.py
usage: parse_test.py [-h] (--option1 OPTION1 | --option2 OPTION2)
parse_test.py: error: one of the arguments --option1 --option2 is required
garthy commented 7 years ago

http://bugs.python.org/issue10680

ThomasWaldmann commented 3 years ago

Considering all python versions addressed by this code (see README) are out of support, I will archive this repo now.