[Python-Dev] Bytes path support

Antoine Pitrou antoine at python.org
Wed Aug 20 15:01:40 CEST 2014

Le 20/08/2014 07:08, Nick Coghlan a écrit :
> It's not just the JVM that says text and binary APIs should be separate
> - it's every widely used operating system services layer except POSIX.
> The POSIX way works well *if* everyone reliably encodes things as UTF-8
> or always uses encoding detection, but its failure mode is unfortunately
> silent data corruption.
> That said, there's a lot of Python software that is POSIX specific,
> where bytes paths would be the least of the barriers to porting to
> Windows or Jython. I'm personally +1 on consistently allowing binary
> paths in lower level APIs, but disallowing them in higher level
> explicitly cross platform abstractions like pathlib.

I fully agree with Nick's position here.

To elaborate specifically about pathlib, it doesn't handle bytes paths 
but allows you to generate them if desired:

Adding full bytes support to pathlib would have added a lot of 
complication and fragility in the implementation *and* in the API (is it 
allowed to combine str and bytes paths? should they have separate 
classes?), for arguably little benefit.

I think if you want low-level features (such as unconverted bytes paths 
under POSIX), it is reasonable to point you to low-level APIs.



More information about the Python-Dev mailing list