Mark Dickinson <dicki...@gmail.com> added the comment:

+1 from me too;  I agree the current API of PyBytes_FromObject is ugly.  

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?  It's a 
fairly simple operation (PyBytes_FromStringAndSize + memset), so perhaps 
it doesn't need its own public function.

I'm not sure about the extra PyUnicode_Check:  this seems to go against 
Python's philosophy of duck-typing.  After all, the empty string *is* an 
iterable all of whose elements are integers.  And this check doesn't cover 
other, similar, cases:  for example, list('') will still be converted by 
PyBytes_FromObject, while list('123') won't.  What's the benefit?

If this check is going to stay, there should probably also be a unit test 
for this behaviour.

Apart from the reservation about the PyUnicode_Check, the patch looks good 
to me.  All tests pass on my machine (OS X 10.5) with this patch applied.

----------
nosy: +marketdickinson

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue6687>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to