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('.').parent is itself rather than parent
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: adrien.pierre.horgnies@gmail.com, brett.cannon, pitrou
Priority: normal Keywords:

Created on 2019-07-02 14:35 by adrien.pierre.horgnies@gmail.com, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg347143 - (view) Author: adrien.pierre.horgnies@gmail.com (adrien.pierre.horgnies@gmail.com) Date: 2019-07-02 14:35
Tested with CPython 3.7.3

```
from pathlib import Path

p = Path('.')

assert p == p.parent # should fail but it does not
```

I expect Path('.').parent to be Path('..')

I searched issues and did not find any similar issue but maybe I didn't search well enough because I would be surprised that I'd be the first one to be bugged by this issue.

I didn't test newer version of Python as I couldn't find a package or wasn't comfortable enough to build it myself.
msg347145 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2019-07-02 15:01
This is by design.  The "parent" attribute is a *lexical operation*.  If you want to walk the actual filesystem, first call resolve().

It's even documented:
https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.parent
msg347147 - (view) Author: adrien.pierre.horgnies@gmail.com (adrien.pierre.horgnies@gmail.com) Date: 2019-07-02 15:34
T-T Sorry. It didn't feel intuitive but I should have read the doc...
msg347170 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2019-07-02 23:10
Would it be worth to set 'parent' to None in this instance? Might break code but would also be potentially less surprising.
History
Date User Action Args
2022-04-11 14:59:17adminsetgithub: 81667
2019-07-02 23:10:31brett.cannonsetnosy: + brett.cannon
messages: + msg347170
2019-07-02 15:34:24adrien.pierre.horgnies@gmail.comsetmessages: + msg347147
2019-07-02 15:01:57pitrousetstatus: open -> closed
resolution: not a bug
messages: + msg347145

stage: resolved
2019-07-02 14:51:05christian.heimessetnosy: + pitrou

versions: + Python 3.8, Python 3.9
2019-07-02 14:35:48adrien.pierre.horgnies@gmail.comcreate