[issue37130] pathlib.Path.with_name() handles '.' and '..' inconsistently

Steinmann report at bugs.python.org
Mon Jul 8 09:47:26 EDT 2019


Steinmann <lucas at steinm.net> added the comment:

@Brett: I also think making Path('.').name evaluate to '.' would be the most logical thing. More even so since the documentation says PurePath.name() is equivalent to os.path.basename()[1], but:

>>> Path('.').name
''
>>> os.path.basename('.')
'.'

Though I'm not sure if that is ok to change this behaviour or if people already rely on it.

No matter which decision is made, I would say the documentation should be improved.
If it will be the same as basename, document this also here [2].
Otherwise add a note to [1], maybe in the same format and position as was done for os.path.relpath().

[1] https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module
[2] https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.name

----------
nosy: +lucas.steinmann

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37130>
_______________________________________


More information about the Python-bugs-list mailing list