[issue18283] shutil.which() should support bytes

STINNER Victor report at bugs.python.org
Sun Jun 23 13:42:32 CEST 2013


STINNER Victor added the comment:

"What about bytearrays and other byte-like objects?

However I'm not sure this enhancement is worth to be accepted. Many other high-level functions in os and shutil modules do not support bytes paths. For shutil.which() there is no backward compatibility with Python 2 which we should support."

Bytes is the native type for path on all platforms... except Windows. So I fixed many functions of the os module to support bytes parameters. For example, functions of os.path support str and bytes types, but not bytearray. I also prefer to reject byte-like objects, to keep it simple.

The bytes type should be accepted for any kind of os function parameter: path, environment variable, command line argument, etc. It's not a question of being compatible with Python 2, an application can make the choice of only used bytes because bytes is the native type for OS data on UNIX.

Python 3 supports also "bytes stored in Unicode" thanks to the PEP 393, but it's not exactly the same: a path stored as str depends on the filesystem locale, whereas a bytes string is well defined (it's just an array of 8-bit unsigned numbers) and doesn't depend on any configuration variable.

----------

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


More information about the Python-bugs-list mailing list