[Python-Dev] file system path protocol PEP

Serhiy Storchaka storchaka at gmail.com
Thu May 12 04:14:38 EDT 2016


On 12.05.16 10:54, Ethan Furman wrote:
> Currently, any of these functions that already take a string have to do
> a couple pointer comparisons to make sure they have a string; any of
> these functions that take both a string and a bytes have to do a couple
> pointer comparisons to make sure they have a string or a bytes;  the
> only difference if this PEP is accepted is the fall-back path when those
> first checks fail.

This is cheap in C, but os.path functions are implemented in Python. 
They have to make at least one function call (os.fspath(), hasattr() or 
isinstance()), not counting a bytecode for retrieving arguments, 
resolving attributes, comparing, jumps. Currently os.path functions use 
tricks to avoid overheads

Yet one problem is that currently many os,path functions work with 
duck-typed strings (e.g. UserString). Using os.fspath() likely limit 
supported types to str, bytes and types that support the path protocol.




More information about the Python-Dev mailing list