[New-bugs-announce] [issue30879] os.listdir(bytes) gives a list of bytes, but os.listdir(buffer) gives a list of unicodes

Armin Rigo report at bugs.python.org
Sat Jul 8 12:27:45 EDT 2017


New submission from Armin Rigo:

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', ...]

----------
components: Library (Lib)
messages: 297960
nosy: arigo
priority: normal
severity: normal
status: open
title: os.listdir(bytes) gives a list of bytes, but os.listdir(buffer) gives a list of unicodes
type: behavior
versions: Python 3.5, Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30879>
_______________________________________


More information about the New-bugs-announce mailing list