
What types should be accepted as bytes path? For now os.path is strict and accepts only bytes and bytes subclasses (even bytearray is not accepted) as bytes path. This is enough for working with low-level Posix paths and supporting backward compatibility. On other hand, most os functions is too permissive since 3.3 and accept any type that supports the buffer protocol as bytes path. Accepted even such meaningless objects as array('h'). Some functions (zipimport.zipimporter() in 3.x, _imp.load_dynamic() in 3.3+, builtin compile() etc in 3.4) accept even arbitrary iterables, e.g. [116, 101, 115, 116] (see http://bugs.python.org/issue26754). I think we should accept only bytes (and subclasses). Even bytearray is less acceptable since it is mutable and can't be used as a key in caches.

IMHO it's more a side effect of the implementation than a deliberate choice. For new code which really want to support bytes paths, I suggest to only accept bytes and bytes subclasses. Victor

Yes, in the 3.2 time frame there was a consensus that only bytes and their subclasses should be accepted. buffer support crept back into the posix module with the major changes in 3.3, likely by mistake. A couple new issues are proposed to remove these inconsistencies/regressions: http://bugs.python.org/issue26754 <http://bugs.python.org/issue26754> http://bugs.python.org/issue26800 <http://bugs.python.org/issue26800> -- Philip Jenvey
On Apr 14, 2016, at 3:29 AM, Victor Stinner <victor.stinner@gmail.com> wrote:
IMHO it's more a side effect of the implementation than a deliberate choice. For new code which really want to support bytes paths, I suggest to only accept bytes and bytes subclasses.
participants (3)
-
Philip Jenvey
-
Serhiy Storchaka
-
Victor Stinner