Nick Coghlan <ncogh...@gmail.com> added the comment:

Regarding PEP 302 compliance: until Python 3.3, the builtin import system 
wasn't present on sys.metapath - it was its own implicit legacy thing. The 
change in Python 3.3 was to fix that, and make it work based on a handful of 
default sys.metapath entries. Not coincidentally, 3.3 was also the first 
release where the import system was finally added to the language reference 
rather than being wholly implementation dependent: 
https://docs.python.org/3/reference/import.html

I think that also points the way forward for providing a useful import spec 
compliant fallback for sourceless files in linecache in a way that could be 
backported to earlier Python 3 versions: it's possible to create a FileFinder 
[1] instance that only looks for source files, and ignores files that don't 
provide source code.

Given that, the changes needed to make SageMath tracebacks "just work" the way 
they currently do in Python 2 would be:

1. Enhance PathFinder [2] to allow specification of which path importer cache 
and path_hooks entries to use
2. Set up a source-only metapath in linecache with a single default entry: a 
PathFinder configured with a source-only FileFinder instance as a path hook
3. Fall back to the source-only metapath if the main import system indicates 
the module is being loaded from a sourceless format.

[1] 
https://docs.python.org/3/library/importlib.html#importlib.machinery.FileFinder
[2] 
https://docs.python.org/3/library/importlib.html#importlib.machinery.PathFinder

----------
versions:  -Python 3.5, Python 3.6, Python 3.7

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

Reply via email to