Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os module: reject bytes-like strings for paths, only accept the exact bytes type #98393

Closed
vstinner opened this issue Oct 18, 2022 · 4 comments
Closed
Labels
type-bug An unexpected behavior, bug, or error

Comments

@vstinner
Copy link
Member

vstinner commented Oct 18, 2022

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.

@vstinner
Copy link
Member Author

In Python 3.2, I removed support for bytearray in PyUnicode_FSConverter(): issue #52731, commit dcb2403.

commit dcb2403022520028a633143602359a30080ed257
Author: Victor Stinner <[email protected]>
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.

@vstinner
Copy link
Member Author

I created PR #98394 to implement this change.

@vstinner
Copy link
Member Author

It seems like support for bytes-like object was added again in Python 3.4 with commit a2ad5c3 (issue #60176):

Ah no, it was reintroduced in Python 3.3 with "the big path_converter changes": #70987 (comment)

vstinner added a commit that referenced this issue Oct 18, 2022
The os module and the PyUnicode_FSDecoder() function no longer accept
bytes-like paths, like bytearray and memoryview types: only the exact
bytes type is accepted for bytes strings.
vstinner added a commit that referenced this issue Nov 2, 2022
@vstinner
Copy link
Member Author

vstinner commented Nov 3, 2022

Fixed by db03c80 (with f3007ac cleanup).

@vstinner vstinner closed this as completed Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant