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.

Title: pathlib.Path will be broken with os.chdir command.
Type: behavior Stage: resolved
Components: C API, Library (Lib) Versions: Python 3.8, Python 3.7
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Y Ono, eric.smith, pitrou, zach.ware
Priority: normal Keywords:

Created on 2020-05-20 00:50 by Y Ono, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg369410 - (view) Author: Y Ono (Y Ono) Date: 2020-05-20 00:50
import os
from pathlib import Path

I put the code into a file in `/tmp/`, and execute it from `/tmp/` directory like below. Then the output showed `/tmp/scripts/scripts/`.

$ python scripts/

After executing `os.chdir`, pathlib's path handling is completely broken.
msg369411 - (view) Author: Y Ono (Y Ono) Date: 2020-05-20 00:58
It's the same as when executing `os.path.abspath`.
msg369418 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2020-05-20 06:09
I don't see anything broken here: `__file__` is "scripts/", `Path(__file__).parent` is "scripts", and `__file__` doesn't change just because the working directory changed (it's a static string set at import time, which is only a relative path because you ran the file using a relative path).
msg369419 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-05-20 06:17 and might help explain behavior. I agree it's working as designed.
Date User Action Args
2022-04-11 14:59:31adminsetgithub: 84870
2020-05-20 06:17:56eric.smithsetnosy: + eric.smith
messages: + msg369419
2020-05-20 06:09:13zach.waresetstatus: open -> closed

nosy: + zach.ware
messages: + msg369418

resolution: not a bug
stage: needs patch -> resolved
2020-05-20 05:10:36SilentGhostsetversions: + Python 3.7
nosy: + pitrou

components: + Library (Lib)
type: behavior
stage: needs patch
2020-05-20 00:58:34Y Onosetmessages: + msg369411
2020-05-20 00:50:18Y Onocreate