Skip to content

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

Closed

Description

@vstinner

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.

Activity

  1. vstinner commented on Oct 18, 2022

    @vstinner
    MemberAuthor

    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.

  2. vstinner commented on Oct 18, 2022

    @vstinner
    MemberAuthor

    I created PR #98394 to implement this change.

  3. vstinner commented on Oct 18, 2022

    @vstinner
    MemberAuthor

    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)

  4. added a commit that references this issue on Oct 18, 2022
  5. added a commit that references this issue on Nov 2, 2022
  6. vstinner commented on Nov 3, 2022

    @vstinner
    MemberAuthor

    Fixed by db03c80 (with f3007ac cleanup).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions