classification
Title: Allow Path instances in sys.path ?
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.8
process
Status: closed Resolution: duplicate
Dependencies: Superseder: add support for path-like objects in sys.path
View: 32642
Assigned To: Nosy List: ammar2, thierry.parmentelat
Priority: normal Keywords:

Created on 2018-11-13 20:55 by thierry.parmentelat, last changed 2018-11-13 20:59 by ammar2. This issue is now closed.

Messages (2)
msg329864 - (view) Author: Thierry Parmentelat (thierry.parmentelat) Date: 2018-11-13 20:55
Hi; this is my first entry in this repo

I ran today into a rather frustrating experience, that I'd to avoid it for others as far as possible

In a nutshell I had a sphinx stub that read:

import sys
sys.path.append("..")
<snip>
import mymodule


and because I was switching from os.path to pathlib.Path, I rather stupidly changed it into this

import sys
sys.path.append(Path("..").resolve())
<snip>
import mymodule


---
When trying to run this new code, the message I got was ModuleNotFoundError
So I tried to troubleshoot the situation, and inserted something like

for x in sys.path:
    print(x)

and so the proper path showed up, and that's the point where I started banging my head against the screen
Granted, I was doing too many changes at the same time, and it's entirely my fault if it took me ages really to figure it out eventually.

---
Still, my proposal would be to

*) either accept Path instances in sys.path, or
*) somehow send a warning message stating that the Path instance is totally ignored; at least, I haven't found the corresponding piece of code yet, but as far as I am concerned it's truly as if this Path instance had been completely ignored when executing the import statement
*) or at the very least add a mention about this possible issue in the import documentation


I understand it was a stupid mistake, but with Path becoming THE right way to deal with paths, I think it is safe to predict that I won't be the only one making it.

As I said I am a complete newbie with cpython's codebase and devel practices, so I'll warmly welcome all inputs on this one.

thanks
msg329865 - (view) Author: Ammar Askar (ammar2) * (Python triager) Date: 2018-11-13 20:59
Looks like there's an issue already open for this.
History
Date User Action Args
2018-11-13 20:59:37ammar2setstatus: open -> closed

superseder: add support for path-like objects in sys.path

nosy: + ammar2
messages: + msg329865
resolution: duplicate
stage: resolved
2018-11-13 20:55:02thierry.parmentelatcreate