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.listdir(bytes) gives a list of bytes, but os.listdir(buffer) gives a list of unicodes #75062

Closed
arigo mannequin opened this issue Jul 8, 2017 · 7 comments
Closed
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@arigo
Copy link
Mannequin

arigo mannequin commented Jul 8, 2017

BPO 30879
Nosy @arigo, @alex, @serhiy-storchaka
PRs
  • bpo-30879: os.listdir() and os.scandir() now emit bytes names when #2634
  • [3.6] bpo-30879: os.listdir() and os.scandir() now emit bytes names when (GH-2634) #2656
  • [3.5] bpo-30879: os.listdir() and os.scandir() now emit bytes names when (GH-2634) #2657
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2017-07-11.04:44:12.866>
    created_at = <Date 2017-07-08.16:27:45.508>
    labels = ['3.7', 'type-bug', 'library']
    title = 'os.listdir(bytes) gives a list of bytes, but os.listdir(buffer) gives a list of unicodes'
    updated_at = <Date 2017-07-11.04:44:12.866>
    user = 'https://github.com/arigo'

    bugs.python.org fields:

    activity = <Date 2017-07-11.04:44:12.866>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-07-11.04:44:12.866>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2017-07-08.16:27:45.508>
    creator = 'arigo'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 30879
    keywords = []
    message_count = 7.0
    messages = ['297960', '297962', '297963', '297984', '298111', '298116', '298118']
    nosy_count = 3.0
    nosy_names = ['arigo', 'alex', 'serhiy.storchaka']
    pr_nums = ['2634', '2656', '2657']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue30879'
    versions = ['Python 3.5', 'Python 3.6', 'Python 3.7']

    @arigo
    Copy link
    Mannequin Author

    arigo mannequin commented Jul 8, 2017

    The os functions generally accept any buffer-supporting object as file names, and interpret it as if bytes() had been called on it. However, os.listdir(x) uses the type of x to know if it should return a list of bytes or a list of unicodes---and the condition seems to be isinstance(x, bytes). So we get this kind of inconsistent behaviour:

    >>> os.listdir(b".")
    [b'python', b'Include', b'python-config.py', ...]
    
    >>> os.listdir(bytearray(b"."))
    ['python', 'Include', 'python-config.py', ...]

    @arigo arigo mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jul 8, 2017
    @serhiy-storchaka
    Copy link
    Member

    Good catch Armin! PR 2634 fixes this inconsistency.

    Maybe it is worth to deprecate support of other bytes-like object except bytes. open(), os.fspath() and os.path functions don't support them.

    @arigo
    Copy link
    Mannequin Author

    arigo mannequin commented Jul 8, 2017

    I've also been pointed to https://bugs.python.org/issue26800 .

    @serhiy-storchaka
    Copy link
    Member

    Oh, I forgot that this feature already is deprecated!

    @serhiy-storchaka
    Copy link
    Member

    New changeset 1180e5a by Serhiy Storchaka in branch 'master':
    bpo-30879: os.listdir() and os.scandir() now emit bytes names when (bpo-2634)
    1180e5a

    @serhiy-storchaka
    Copy link
    Member

    New changeset ecfe4f6 by Serhiy Storchaka in branch '3.6':
    [3.6] bpo-30879: os.listdir() and os.scandir() now emit bytes names when (GH-2634) (bpo-2656)
    ecfe4f6

    @serhiy-storchaka
    Copy link
    Member

    New changeset 7527c32 by Serhiy Storchaka in branch '3.5':
    [3.5] bpo-30879: os.listdir() and os.scandir() now emit bytes names when (GH-2634) (bpo-2657)
    7527c32

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant