Ionuț Ciocîrlan <ionut.ciocir...@gmail.com> added the comment: > Can you please add an example of how normalize() should behave?
``` >>> mypath = PurePosixPath("foo/bar/bzz") >>> mypath /= "../../" >>> mypath PurePosixPath('foo/bar/bzz/../..') >>> mypath = mypath.normalize() >>> mypath PurePosixPath('foo') >>> mypath /= "../../../there" >>> mypath PurePosixPath('foo/../../../there') >>> mypath = mypath.normalize() >>> mypath PurePosixPath('../../there') >>> mypath /= "../../and/back/again" >>> mypath PurePosixPath('../../there/../../and/back/again') >>> mypath = mypath.normalize() >>> mypath PurePosixPath('../../../and/back/again') ``` > I assume you want the same behaviour as os.path.normpath which already > accepts a pathlike object to be added to pathlib. Yes, exactly the same behaviour, but arguing that normpath() can take a pathlib object is just saying that it saves you from doing an intermediate str(), which is, well, nice, but still not pretty. Consider `mypath = mypath.normalize()` vs. `mypath = PurePosixPath(normpath(mypath))`. > Do note that Path inherits from PurePath, so providing a normalize() method > on the latter means it will end up on the former. That could be "circumvented" with a bit of code shuffling, e.g. moving everything from `PurePath` to a `PathBase` or `_Path` or somesuch, and forking the inheritance from there. On the other hand, it might be useful. I personally can't think of a scenario, but the GNU folk certainly think so, see `realpath --logical`: https://www.gnu.org/software/coreutils/manual/html_node/realpath-invocation.html ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue38924> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com