bpo-32642: Allow for PathLike objects in sys.path by sroet · Pull Request #22000 · python/cpython (original) (raw)

This is similar to what was done in #5691, but that one seems abandoned.

It was mentioned there a test needed to be included.
My current idea of a test involves making files outside of the running directory to be added to sys.path and then imported.
I would like some guidance on what the best/common practices are for that in this code-base.

test that shows the issue (taken from issue32642):
t.py

import pathlib
import sys

sys.path.append(pathlib.Path('foo'))

uncomment next line for this script to pass on master

sys.path.append('foo')

import s

in foo/s.py

on master this gives:

Traceback (most recent call last):
  File "t.py", line 9, in <module>
    import s
ModuleNotFoundError: No module named 's'

With this implementation:

https://bugs.python.org/issue32642