"Mark Dickinson" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| On Tue, Mar 25, 2008 at 11:29 AM, Nick Coghlan <[EMAIL PROTECTED]> 
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...

The purpose of type constructors is to construct instances from reasonable 
inputs.  I think all number constructors should accept bytes and so the 
latter three should be changed.

tjr



_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to