classification
Title: Add exec_module() as part of the import loader API
Type: enhancement Stage:
Components: Interpreter Core Versions: Python 3.4
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: eric.snow Nosy List: amaury.forgeotdarc, brett.cannon, eric.snow, pitrou
Priority: normal Keywords:

Created on 2012-07-28 19:33 by eric.snow, last changed 2012-07-31 06:25 by eric.snow. This issue is now closed.

Messages (2)
msg166677 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2012-07-28 19:33
issue15110 introduced a new private function, _exec_module(), to the default loaders in Lib/importlib/_bootstrap.py.  Doing so helped hide importlib frames from the traceback.  A related fix is likely required for issue15425.

Should some general form of exec_module() be an official part of the loader API (in importlib.abc.Loader).  If a loader subclasses one of the default ones, it already gets the behavior for free.  Otherwise it does not benefit from the cleaner traceback (unless the author is savvy to the _exec_module() implementation detail).

Though the use of Loader._exec_module() to strip tracebacks is an implementation detail of CPython, having a public Loader.exec_module() would allow other implementations to perform a similar action.  And if we found a way to move remove_importlib_frames to importlib then all the better.  (Looking into traceback API improvements is on my to-do list.)

As a bonus, Loader.exec_module() would also allow loaders that wrap other loaders (yes, esoteric) to manage the execution portion of loading.  I haven't given this part a lot of thought, so it may not be much of a bonus (or could even be a negative).

From the perspective of caution, the import machinery is already pretty complicated.  It may not be advisable to add to that even in this little way.
msg166963 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2012-07-31 06:25
This isn't going to be worth it.
History
Date User Action Args
2012-07-31 06:25:20eric.snowsetstatus: open -> closed
resolution: rejected
messages: + msg166963
2012-07-28 19:33:09eric.snowcreate