Brett Cannon added the comment:

So it isn't about importlib not handling missing directories on sys.path 
directly, it has to do with the fact that os.getcwd() raises FileNotFoundError 
when CWD is no longer valid and that is in a fundamental part of importlib that 
isn't worrying about non-existent directories.

We could be robust and simply have instances of os.getcwd() failing just move 
on, e.g. when '' is hit in sys.path and os.getcwd() raises an exception just 
give up. The other option is leaving this to raise FileNotFoundError but 
throwing a new copy with a better error message mentioning this is because the 
current working directory no longer exists. That would lead to easier debugging 
since paths on sys.path are typically obvious -- since makes them 
absolute -- but I'm willing to bet people don't bother checking CWD is still 
good. So it's robustness vs. debugging when you make this mistake.

Any opinions on the matter?

status: open -> pending

Python tracker <>
Python-bugs-list mailing list

Reply via email to