[pypy-dev] CPython compatibility in the fractions module

Naftali Harris naftaliharris at gmail.com
Thu Apr 10 21:05:33 CEST 2014


Hi everyone,

I'd like to report a compatibility issue between CPython and PyPy in the
fractions module.  In short, CPython coerces Fraction objects into int's in
strings formatted with "%d", but PyPy throws a TypeError.  Here's an
example reproducing this:

~/Downloads/pypy-2.2.1-linux64/bin$ ./pypy
Python 2.7.3 (87aa9de10f9c, Nov 24 2013, 18:48:13)
[PyPy 2.2.1 with GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``<arigato> fijal: I'm sure
there
is tons of unspecified context information that I should ideally also be
aware
of''
>>>> from fractions import Fraction
>>>> print "%d" % Fraction(1, 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type for int(): 'Fraction'
>>>>
~/Downloads/pypy-2.2.1-linux64/bin$ python
Python 2.7.3 (default, Feb 27 2014, 19:37:34)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from fractions import Fraction
>>> print "%d" % Fraction(1, 1)
1
>>>

Thanks for the great work you all do!

Naftali
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20140410/14ce4679/attachment.html>


More information about the pypy-dev mailing list