[issue2483] int and float accept bytes, complex does not

Mark Dickinson report at bugs.python.org
Tue Mar 25 17:22:00 CET 2008


New submission from Mark Dickinson <dickinsm at gmail.com>:

In 3.0, the int and float constructors accepts bytes instances as well as 
strings:

>>> int(b'1')
1
>>> float(b'1')
1.0

but the complex constructor doesn't:

>>> complex(b'1')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: complex() argument must be a string or a number

I'd suggest that at least one of these three results is a bug,
but I'm not sure which.

>From a purity point of view, I think int() and float() shouldn't accept 
bytes.  Is this a case of practicality beats purity?  What are the
pratical reasons to have int() and float() accept bytes?

Once this is resolved, the behaviors of Decimal and Fraction should also 
be considered.

----------
components: Interpreter Core
messages: 64494
nosy: marketdickinson
severity: normal
status: open
title: int and float accept bytes, complex does not
type: behavior
versions: Python 3.0

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2483>
__________________________________


More information about the Python-bugs-list mailing list