[pypy-issue] [issue1595] Inconsistency between CPython an PyPy while using argparse with mutual exclusion

Amaury Forgeot d'Arc tracker at bugs.pypy.org
Fri Sep 6 00:04:54 CEST 2013


Amaury Forgeot d'Arc <amauryfa at gmail.com> added the comment:

Yes, CPython behavior is odd when default=3.
This is because of a misuse of the "is" operator in argparse.py, line 1783:
    if argument_values is not action.default:

Now, when you pass -b 3, will the value be identical to action.default? This depends how the object int("3") is 
constructed. Here CPython caches small integers, and int("3") is 3. But int("1000") is not 1000.
And CPython does not cache floats (even 0.0)

PyPy is a bit different, and int(x) is x, always:
http://pypy.readthedocs.org/en/latest/cpython_differences.html#object-identity-of-primitive-values-is-and-id

If it's important, argparse should be rewritten to not rely on the identity of ints or floats.

----------
nosy: +amaury
status: unread -> chatting

________________________________________
PyPy bug tracker <tracker at bugs.pypy.org>
<https://bugs.pypy.org/issue1595>
________________________________________


More information about the pypy-issue mailing list