Skip to content
Snippets Groups Projects
Select Git revision
  • 60f1063797716cfec14c84afafec69bf06127777
  • master default protected
2 results

runtime.c

  • Paul m. p. P's avatar
    60f10637
    py/runtime: Allow to override builtins.__import__ with Python func. · 60f10637
    Paul m. p. P authored
    This patch adds a simple but powerful hook into the import system, in a
    CPython compatible way, by allowing to override builtins.__import__.
    
    This does introduce some overhead to all imports but it's minor:
    - the dict lookup of __import__ is bypassed if there are no modifications
      to the builtins module (which is the case at start up);
    - imports are not performance critical, usually done just at the start of a
      script;
    - compared to how much work is done in an import, looking up a value in a
      dict is a relatively small additional piece of work.
    60f10637
    History
    py/runtime: Allow to override builtins.__import__ with Python func.
    Paul m. p. P authored
    This patch adds a simple but powerful hook into the import system, in a
    CPython compatible way, by allowing to override builtins.__import__.
    
    This does introduce some overhead to all imports but it's minor:
    - the dict lookup of __import__ is bypassed if there are no modifications
      to the builtins module (which is the case at start up);
    - imports are not performance critical, usually done just at the start of a
      script;
    - compared to how much work is done in an import, looking up a value in a
      dict is a relatively small additional piece of work.