[Python-ideas] PEP 511: API for code transformers

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Jan 17 16:54:10 EST 2016


Concerning ways to allow a module to opt in to transformations
that change semantics, my first thought was to use an import
from a magic module:

from __extensions__ import modulename

This would have to appear before any other statements or
non-magic imports, like __future__ does. The named module
would be imported at compile time and some suitable
convention used to extract transformers from it.

The problem is that if your extension is in a package,
you want to be able to write

from __extensions__ import packagename.modulename

which is not valid syntax.

So instead of a magic module, maybe a magic namespace
package:

import __extensions__.packagename.modulename

-- 
Greg



More information about the Python-ideas mailing list