May-26-2018, 09:12 PM
Hi,
I have recently found a weird behaviour while trying to resolve a relative path located on the root directory on a macOs.
I tried to resolve a Path('spam') and the interpreter answered PosixPath('//spam') —double slash for root— instead of (my) expected PosixPath('/spam').
I really do not know if this is the intended result or a bug.
I ran the interpreter from root directory (cd /; python). Once running the interpreter, this is what I did:
More examples are:
Python docs (https://docs.python.org/3/library/pathlib.html) talks about "UNC shares" but this is not the case (in using a macOs HFS+ filesystem).
PEP 428 (https://www.python.org/dev/peps/pep-0428/) says:
I do not think that this is related to the aforementioned issue.
However, I also checked the POSIX specification link (http://pubs.opengroup.org/onlinepubs/009...#tag_04_11) and found:
I do not really think that this can cause a double slashes while resolving a relative path on macOs.
Is this the proper behaviour of pathlib.Path.resolve() method? Is this a bug? Am I missing something about filesystems, filenames, etc.?
Thank you in advance.
My software is:
Python 3.6.5 (default, May 15 2018, 08:20:57)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)] on darwin
Running on: macOs High Sierra 10.13.4 (17E202)
I have recently found a weird behaviour while trying to resolve a relative path located on the root directory on a macOs.
I tried to resolve a Path('spam') and the interpreter answered PosixPath('//spam') —double slash for root— instead of (my) expected PosixPath('/spam').
I really do not know if this is the intended result or a bug.
I ran the interpreter from root directory (cd /; python). Once running the interpreter, this is what I did:
>>> import pathlib
>>> pathlib.Path.cwd()
PosixPath('/')
# since the interpreter has been launched from root
>>> p = pathlib.Path('spam')
>>> p
PosixPath('spam')
# just for checking
>>> p.resolve()
PosixPath('//spam')
# beware of double slash instead of single slashI also checked the behaviour of Path.resolve() in a non-root directory (in my case launching the interpreter from /Applications).>>> import pathlib
>>> pathlib.Path.cwd()
PosixPath('/Applications')
>>> p = pathlib.Path('eggs')
>>> p
PosixPath('eggs')
>>> p.resolve()
PosixPath('/Applications/eggs')
# just one slash as root in this case (as should be)So it seems that double slashes just appear while resolving relative paths in the root directory.More examples are:
>>> pathlib.Path('spam/egg').resolve()
PosixPath('//spam/egg')
>>> pathlib.Path('./spam').resolve()
PosixPath('//spam')
>>> pathlib.Path('./spam/egg').resolve()
PosixPath('//spam/egg')but>>> pathlib.Path('').resolve()
PosixPath('/')
>>> pathlib.Path('.').resolve()
PosixPath('/')Intriguingly,>>> pathlib.Path('spam').resolve().resolve()
PosixPath('/spam')
# 'spam'.resolve = '//spam'
# '//spam'.resolve = '/spam'!!!
>>> pathlib.Path('//spam').resolve()
PosixPath('/spam')I searched for some information on this issue but I did not found anything useful.Python docs (https://docs.python.org/3/library/pathlib.html) talks about "UNC shares" but this is not the case (in using a macOs HFS+ filesystem).
PEP 428 (https://www.python.org/dev/peps/pep-0428/) says:
Quote:Multiple leading slashes are treated differently depending on the path flavour. They are always retained on Windows paths (because of the UNC notation):
>>> PureWindowsPath('//some/path')
PureWindowsPath('//some/path/')
On POSIX, they are collapsed except if there are exactly two leading slashes, which is a special case in the POSIX specification on pathname resolution [8] (this is also necessary for Cygwin compatibility):
>>> PurePosixPath('///some/path')
PurePosixPath('/some/path')
>>> PurePosixPath('//some/path')
PurePosixPath('//some/path')
I do not think that this is related to the aforementioned issue.
However, I also checked the POSIX specification link (http://pubs.opengroup.org/onlinepubs/009...#tag_04_11) and found:
Quote:A pathname that begins with two successive slashes may be interpreted in an implementation-defined manner, although more than two leading slashes shall be treated as a single slash.
I do not really think that this can cause a double slashes while resolving a relative path on macOs.
Is this the proper behaviour of pathlib.Path.resolve() method? Is this a bug? Am I missing something about filesystems, filenames, etc.?
Thank you in advance.
My software is:
Python 3.6.5 (default, May 15 2018, 08:20:57)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)] on darwin
Running on: macOs High Sierra 10.13.4 (17E202)
