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
{{ message }}
Repository navigation
os module: reject bytes-like strings for paths, only accept the exact bytes type #98393
In Python 3.6, the support for "bytes-like" paths was deprecated (commit d73c318): see issue #70987 for the rationale.
I propose to remove the support for bytes-like paths in Python 3.12. The feature was deprecated in 6 Python releases (PEP 387 is respected). In practice, the two most common "bytes-like" types are: bytearray and memoryview.
In Python 3.2, I removed support for bytearray in PyUnicode_FSConverter(): issue #52731, commit dcb2403.
commit dcb2403022520028a633143602359a30080ed257
Author: Victor Stinner <victor.stinner@haypocalc.com>
Date: Thu Apr 22 12:08:36 2010 +0000
Issue #8485: PyUnicode_FSConverter() doesn't accept bytearray object anymore,
you have to convert your bytearray filenames to bytes
It seems like support for bytes-like object was added again in Python 3.4 with commit a2ad5c3 (issue #60176):
+ if (PyObject_CheckBuffer(o))
+ bytes = PyBytes_FromObject(o);
Or maybe this change is unrelated, and Python 3.2 and 3.3 already accepted bytes-like types indirectly.
Activity
vstinner commentedon Oct 18, 2022
In Python 3.2, I removed support for bytearray in PyUnicode_FSConverter(): issue #52731, commit dcb2403.
It seems like support for bytes-like object was added again in Python 3.4 with commit a2ad5c3 (issue #60176):
Or maybe this change is unrelated, and Python 3.2 and 3.3 already accepted bytes-like types indirectly.
vstinner commentedon Oct 18, 2022
I created PR #98394 to implement this change.
vstinner commentedon Oct 18, 2022
Ah no, it was reintroduced in Python 3.3 with "the big path_converter changes": #70987 (comment)
gh-98393: os module reject bytes-like, only accept bytes (#98394)
gh-98393: Update test_os for bytes-like types (#98487)
vstinner commentedon Nov 3, 2022
Fixed by db03c80 (with f3007ac cleanup).