This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients martin.panter, pitrou, serhiy.storchaka, vstinner
Date 2016-04-14.18:13:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1460657623.47.0.29764231335.issue26759@psf.upfronthosting.co.za>
In-reply-to
Content
PyBytes_FromObject creates a bytes object from an object that implements the buffer or the iterable protocol. But only using the buffer protocol is documented.

We should either document the current behavior (the documentation of int.from_bytes() can be used as a sample), or change the behavior to match the documentation.

For now PyBytes_FromObject() is used in the stdlib only for converting FS paths to str (besides using internally in bytes). When called from PyUnicode_FSDecoder(), this leads to accepting arbitrary iterables as filenames, that looks at leas strange (issue26754). In the posix module it is called only for objects that support the buffer protocol.

Thus the support of the iterable protocol is not used or misused in the stdlib. I don't know if it is used correctly in third party code, I suspect that this is rather misused. Note that there is alternative API function PyObject_Bytes(), that accepts same arguments as the bytes() constructor, except an integer, and supports the buffer protocol, the iterable protocol, and in additional supports the __bytes__() special method.
History
Date User Action Args
2016-04-14 18:13:43serhiy.storchakasetrecipients: + serhiy.storchaka, pitrou, vstinner, martin.panter
2016-04-14 18:13:43serhiy.storchakasetmessageid: <1460657623.47.0.29764231335.issue26759@psf.upfronthosting.co.za>
2016-04-14 18:13:43serhiy.storchakalinkissue26759 messages
2016-04-14 18:13:43serhiy.storchakacreate