This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pathlib.Path.resolve(strict=False) strips final path components
Type: behavior Stage:
Components: Windows Versions: Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, lutecki, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2019-11-14 10:16 by lutecki, last changed 2022-04-11 14:59 by admin.

Messages (3)
msg356589 - (view) Author: (lutecki) Date: 2019-11-14 10:16
When a directory doesn't exist, the resolve() method trims everything except the first component (a doesn't exist here):

import pathlib
p = pathlib.Path(".", "a", "b", "c")
p
WindowsPath('a/b/c')
p.resolve(strict=False)
WindowsPath('C:/Python36/Scripts/a')

I would expect C:/Python36/Scripts/a/b/c
Am I missing something?
msg356615 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-11-14 16:44
I'm not sure - I try the same thing (on 3.6, 3.7 and 3.8) and get different results:

>>> import pathlib
>>> p = pathlib.Path(".", "a", "b", "c")
>>> p.resolve(strict=False)
WindowsPath('a/b/c')

Are you sure that it's not successfully resolving a link of some kind?
msg356616 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-11-14 16:47
If "a" exists in the current directory, I get this (correct) result:

>>> import pathlib
>>> p = pathlib.Path(".", "a", "b", "c")
>>> p.resolve(strict=False)
WindowsPath('<my CWD>/a/b/c')

So there's an existence check of some kind that's not being handled properly.
History
Date User Action Args
2022-04-11 14:59:23adminsetgithub: 82974
2019-11-14 17:08:39brett.cannonsetnosy: + brett.cannon
2019-11-14 16:47:57steve.dowersetmessages: + msg356616
2019-11-14 16:44:47steve.dowersetmessages: + msg356615
2019-11-14 10:16:42luteckicreate