[Python-Dev] Decimal(unicode)

Mark Dickinson dickinsm at gmail.com
Tue Mar 25 16:53:03 CET 2008


On Tue, Mar 25, 2008 at 11:29 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:

> The isinstance(value, str) check in Py3k is too restrictive - it needs
> to accept bytes instances as well.
>

Hmm. There's not a lot of consistency here:

>>> int(b'1')
1
>>> float(b'1')
1.0
>>> complex(b'1')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: complex() argument must be a string or a number
>>> from fractions import Fraction
>>> Fraction(b'1')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/dickinsm/python_source/py3k/Lib/fractions.py", line 98, in
__new__
    numerator = numerator.__index__()
AttributeError: 'bytes' object has no attribute '__index__'

So int and float accepts bytes, while complex, Decimal and Fraction do
not...

Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-dev/attachments/20080325/41694f3f/attachment.htm 


More information about the Python-Dev mailing list