Brett Cannon <br...@python.org> added the comment:

importlib is probably not os.PathLike-clean due to its bootstrapping 
restrictions of not getting to use anything implemented in Python from 'os' 
(i.e. if it isn't being managed in posixmodule.c then it probably won't work).

If you follow the traceback it's trying to marshal a code object for the 
eventual .pyc file and failing 
(https://github.com/python/cpython/blob/faf49573963921033c608b4d2f398309d9f0d2b5/Lib/importlib/_bootstrap_external.py#L604).
 The real question is why is any unmarshallable object getting passed in the 
first place since that object is the code object that compile() returned.

Best guess? The compile() function is being given the path-like object (via 
https://github.com/python/cpython/blob/faf49573963921033c608b4d2f398309d9f0d2b5/Lib/importlib/_bootstrap_external.py#L848)
 and it's blindly setting it on the code object itself, and then marhsal fails 
since it can't handle pathlib.Path. If my hunch is right, then the possible 
solutions are:

- Don't do that 😉
- Make compile() aware of path-like objects
- Have importlib explicitly work around compile()'s shortcoming by doing the 
right thing for path-like objects before passing in the the 'path' argument.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue42839>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to