[Python-ideas] tweaking the file system path protocol

Wolfgang Maier wolfgang.maier at biologie.uni-freiburg.de
Mon May 29 04:03:44 EDT 2017


On 05/29/2017 09:55 AM, Serhiy Storchaka wrote:
> 29.05.17 00:33, Wolfgang Maier пише:
>> The path protocol does *not* use __fspath__ as an indicator that an 
>> object's str-representation is intended to be used as a path. If you 
>> had wanted this, the PEP should have defined __fspath__ not as a 
>> method, but as a flag and have the protocol check that flag, then call 
>> __str__ if appropriate.
> 
> __fspath__ is a method because there is a need to support bytes paths. 
> __fspath__() can return a bytes object, str() can't.
> 

That's certainly one reason, but again just shows that calling 
str(path_object) to get a path representation is wrong.



More information about the Python-ideas mailing list