[issue6687] Move the special-case for integer objects out of PyBytes_FromObject.

Alexandre Vassalotti report at bugs.python.org
Fri Dec 11 14:54:21 CET 2009


Alexandre Vassalotti <alexandre at peadrop.com> added the comment:

Mark Dickinson wrote:
> Is there still a need for a separate C function for creating a zero-
> initialized bytes object from a Py_ssize_t or a Python integer?

What C function are you referring to?

> And this check doesn't cover other, similar, cases: for example, list('')
> will still be converted by PyBytes_FromObject, while list('123') won't.

Well, one is a just empty list and the other a list of strings. I don't see
why converting a empty list to bytes should raise an error. Although I agree
the type check is a bit out of place, I think it will help prevents bugs. 

In addition, PyBytes_FromObject() is documented as equivalent to the
built-in
bytes(). Since calling bytes() with any unicode string raises a TypeError
exception, unless an encoding is specified, I believe PyBytes_FromObject()
should also follow this convention.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6687>
_______________________________________


More information about the Python-bugs-list mailing list