You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I agree it is a bit strange. It looks like it is a victim of PyBytes_FromObject() doing more than it says; its documentation only mentions the buffer protocol, not accepting iterables.
This is behavior of PyUnicode_FSDecoder() from the start (bpo-9542). All above functions accepted only str in 3.1, thus accepting bytes object and others was new feature.
None tests are failed if reject non-str and non-bytes argument in PyUnicode_FSDecoder(). But none tests are failed even if disable support of bytes argument (there is a lack of tests for bytes path).
What should we do?
Add a warning when the argument neither str nor supporting the buffer protocol.
Drop support of non-str and not supporting the buffer protocol arguments without a warning.
Drop support of non-str and not supporting the buffer protocol arguments without a warning, and add a warning when the argument neither str nor bytes.
Drop support of non-str and non-bytes arguments without a warning.
Activity
serhiy-storchaka commentedon Apr 14, 2016
PyUnicode_FSDecoder() accepts not only str and bytes or bytes-like object, but arbitrary iterable, e.g. list.
Example:
I think accepting arbitrary iterables is unintentional and weird behavior.
pitrou commentedon Apr 14, 2016
I agree this doens't make sense.
vadmium commentedon Apr 14, 2016
I agree it is a bit strange. It looks like it is a victim of PyBytes_FromObject() doing more than it says; its documentation only mentions the buffer protocol, not accepting iterables.
serhiy-storchaka commentedon Apr 14, 2016
PyUnicode_FSDecoder() is used in following functions in the stdlib:
This is behavior of PyUnicode_FSDecoder() from the start (bpo-9542). All above functions accepted only str in 3.1, thus accepting bytes object and others was new feature.
None tests are failed if reject non-str and non-bytes argument in PyUnicode_FSDecoder(). But none tests are failed even if disable support of bytes argument (there is a lack of tests for bytes path).
What should we do?
Add a warning when the argument neither str nor supporting the buffer protocol.
Drop support of non-str and not supporting the buffer protocol arguments without a warning.
Drop support of non-str and not supporting the buffer protocol arguments without a warning, and add a warning when the argument neither str nor bytes.
Drop support of non-str and non-bytes arguments without a warning.
pjenvey commentedon Apr 18, 2016
See bpo-26800 for reasoning to go with #4
serhiy-storchaka commentedon Jun 11, 2016
Proposed patch makes PyUnicode_FSDecoder() rejecting arbitrary iterables.
python-dev commentedon Jun 18, 2016
New changeset 2e48c2c4c733 by Serhiy Storchaka in branch '3.5':
Issue bpo-26754: PyUnicode_FSDecoder() accepted a filename argument encoded as
https://hg.python.org/cpython/rev/2e48c2c4c733
New changeset e18ac7370113 by Serhiy Storchaka in branch 'default':
Issue bpo-26754: PyUnicode_FSDecoder() accepted a filename argument encoded as
https://hg.python.org/cpython/rev/e18ac7370113
serhiy-storchaka commentedon Jun 18, 2016
Following patch deprecates the support of bytes-like objects (except bytes itself) in PyUnicode_FSDecoder() for consistency with bpo-26800.
python-dev commentedon Aug 6, 2016
New changeset 818f22f9ab02 by Serhiy Storchaka in branch 'default':
Issue bpo-26754: Undocumented support of general bytes-like objects
https://hg.python.org/cpython/rev/818f22f9ab02