New submission from Marco Squarcina <[email protected]>:

Dear PyPy community,

today I found an inconsistency between CPython and PyPy while using the 
argparse 
module. The argparse method add_mutually_exclusive_group is used to create a 
mutually 
exclusive group of arguments, i.e. (from the doc) "[...] will make sure that 
only one 
of the arguments in the mutually exclusive group was present on the command 
line".

The attached source file behaves differently when executed with python and 
pypy. It 
has been tested with python-2.7.3, python-2.7.5, pypy-2.0 and pypy-2.1. An 
example 
follows:

  $ python parse.py -a 2 -b 7.3
  usage: parse.py [-h] [-a A | -b B]
  parse.py: error: argument -b: not allowed with argument -a
  $ python parse.py -a 2 -b 3.14
  usage: parse.py [-h] [-a A | -b B]
  parse.py: error: argument -b: not allowed with argument -a
  $ pypy-c2.0 parse.py -a 2 -b 7.3
  usage: parse.py [-h] [-a A | -b B]
  parse.py: error: argument -b: not allowed with argument -a
  $ pypy-c2.0 parse.py -a 2 -b 3.14
  $ 

The last command does not produce any error. While the pypy behaviour may look 
odd, 
here is what happens when replacing line 7 with: group.add_argument('-b', 
type=int, 
default=3)

  $ python parse_int.py -a 2 -b 7
  usage: parse_int.py [-h] [-a A | -b B]
  parse_int.py: error: argument -b: not allowed with argument -a
  $ python parse_int.py -a 2 -b 3
  $ pypy-c2.0 parse_int.py -a 2 -b 7
  usage: parse_int.py [-h] [-a A | -b B]
  parse_int.py: error: argument -b: not allowed with argument -a
  $ pypy-c2.0 parse_int.py -a 2 -b 3
  $ 

In this case pypy behaves exactly like python.

Thanks for all your great work!

Kind regards,
Marco

----------
files: parse.py
messages: 6124
nosy: lavish, pypy-issue
priority: bug
release: 2.1
status: unread
title: Inconsistency between CPython an PyPy while using argparse with mutual 
exclusion

________________________________________
PyPy bug tracker <[email protected]>
<https://bugs.pypy.org/issue1595>
________________________________________
_______________________________________________
pypy-issue mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-issue

Reply via email to