[issue46733] pathlib.Path methods can raise NotImplementedError
Eryk Sun
report at bugs.python.org
Mon Feb 21 06:42:45 EST 2022
Eryk Sun <eryksun at gmail.com> added the comment:
> pathlib does not allow to distinguish "path" from "path/".
os.path.normpath() and os.path.abspath() don't retain a trailing slash -- or a leading dot component for that matter. Are you referring to os.path.join()? For example:
>>> os.path.join('./spam', 'eggs/')
'./spam/eggs/'
>>> os.path.normpath('./spam/eggs/')
'spam/eggs'
>>> PurePath('./spam') / PurePath('eggs/')
PurePosixPath('spam/eggs')
A leading dot component is significant in a context that searches a set of paths -- usually PATH. A trailing slash is significant in a context that has to distinguish a device or file path from a directory path, of which there are several cases in Windows.
I think it's a deficiency in pathlib that it lacks a way to require conservative normalization in these cases. Path and PurePath objects could gain a keyword-only parameter, and internal attribute if needed, that enables a more conservative normalization.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46733>
_______________________________________
More information about the Python-bugs-list
mailing list