From d866f2b1a3abc6170028aaee821a280775de8ac0 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Tue, 3 Jan 2023 20:33:39 -0800 Subject: [PATCH 1/3] gh-87691: provide an absolute pathlib example under operator The behaviour is fully explained a couple paragraphs above, but it may be useful to have a brief example to cover the behaviour. --- Doc/library/pathlib.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index 47687400c14e3a..c1b0b67e019531 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -222,6 +222,8 @@ The slash operator helps create child paths, similarly to :func:`os.path.join`:: >>> q = PurePath('bin') >>> '/usr' / q PurePosixPath('/usr/bin') + >>> p / '/another' / 'absolute' / 'path' + PurePosixPath('/another/absolute/path') A path object can be used anywhere an object implementing :class:`os.PathLike` is accepted:: From abbfa2ab53dfe00f73591f6476a2e95b4ad588a4 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Thu, 5 Jan 2023 14:04:03 -0800 Subject: [PATCH 2/3] simpler example --- Doc/library/pathlib.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index c1b0b67e019531..36bb7f9b9b6a22 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -222,8 +222,8 @@ The slash operator helps create child paths, similarly to :func:`os.path.join`:: >>> q = PurePath('bin') >>> '/usr' / q PurePosixPath('/usr/bin') - >>> p / '/another' / 'absolute' / 'path' - PurePosixPath('/another/absolute/path') + >>> p / '/an_absolute_path' + PurePosixPath('/an_absolute_path') A path object can be used anywhere an object implementing :class:`os.PathLike` is accepted:: From f9ee1b9216d5033355136ded53522298ef9c0684 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Thu, 5 Jan 2023 14:48:13 -0800 Subject: [PATCH 3/3] copy over everything --- Doc/library/pathlib.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index 36bb7f9b9b6a22..c90758c9306c72 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -212,7 +212,10 @@ Paths of a different flavour compare unequal and cannot be ordered:: Operators ^^^^^^^^^ -The slash operator helps create child paths, similarly to :func:`os.path.join`:: +The slash operator helps create child paths, mimicking the behaviour of +:func:`os.path.join`. For instance, when several absolute paths are given, the +last is taken as an anchor; for a Windows path, changing the local root doesn't +discard the previous drive setting:: >>> p = PurePath('/etc') >>> p @@ -224,6 +227,8 @@ The slash operator helps create child paths, similarly to :func:`os.path.join`:: PurePosixPath('/usr/bin') >>> p / '/an_absolute_path' PurePosixPath('/an_absolute_path') + >>> PureWindowsPath('c:/Windows', '/Program Files') + PureWindowsPath('c:/Program Files') A path object can be used anywhere an object implementing :class:`os.PathLike` is accepted::