On Tue, 8 Dec 2020 07:29:15 -0300 "Joao S. O. Bueno" email@example.com wrote:
And how would Python compute the "full basename of the file to be imported"?
The way it does it usually.
How could it guess among all directories on sys.path the one containing the "file", and check if it is a file or a package without going through the existing mechanism?
It would not guess anything, it would iterate thru sys.path, as it usually does, and would give the hook a chance to see if the needed file exists.
This proposal is also about *modules* and treats packages just as "hierarchical structure of modules" (Python does more than that, but this is "dead simple import hooks").
Maybe this proposal is good - but possibly, just cutingt the "full basename" and pass to the "simple hook" whatever string is on the import statement would be better.
That's already possible, just hook into __import__() (or one of the other extension points provided by importlib). It's exactly the "convert full hierarchical module name into the actual file path" what's the boring part of it, and what I want to leave to the existing import system.