New submission from Serhiy Storchaka: 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. ---------- messages: 263423 nosy: haypo, martin.panter, pitrou, serhiy.storchaka priority: normal severity: normal status: open title: PyBytes_FromObject accepts arbitrary iterable type: behavior versions: Python 3.5, Python 3.6 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue26759> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com