Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WIP: What happens behind execution of an `impor...

Shivashis Padhi
May 02, 2020
390

WIP: What happens behind execution of an `import` statement?

Shivashis Padhi

May 02, 2020
Tweet

Transcript

  1. Finders - examples • locate built-in modules • locate frozen

    modules • import path - imagine $PATH and $PYTHONPATH
  2. Finders - function • If a finder is capable of

    handling import, it returns a module spec. • module spec contains module’s metadata i.e path, name, etc. The import machinery uses this spec to load modules later
  3. Loaders After spec object is returned from a finder, loaders

    are used to execute the module and store its reference in sys.modules
  4. What else can you do with import hooks? • full

    control after what happens after ‘import x’ • importing from ftp, https, authorization checks. • importing from a variety of storage, not just .py/.pyc