[Python-ideas] PEP 511: Add a check function to decide if a "language extension" code transformer should be used or not
Andrew Barnert
abarnert at yahoo.com
Wed Jan 27 16:34:46 EST 2016
On Jan 27, 2016, at 12:20, Brett Cannon <brett at python.org> wrote:
>
>> On Wed, 27 Jan 2016 at 08:49 Andrew Barnert via Python-ideas <python-ideas at python.org> wrote:
>>
>> If someone builds a transformer that only runs on files with a different extension, he already needs an import hook, so he might as well just call his transformer from the input hook, same as he does today.
>
> And the import hook is not that difficult.
Unless it has to work in 2.7 and 3.3 (or, worse, 2.6 and 3.2). :)
> You can reuse everything from importlib without modification except for needing to override a single method in some loader to do your transformation
Yes, as of 3.4, the design is amazing. In fact, hooking any level--lookup, source, AST, bytecode, or pyc--is about as easy as it could be.
My only complaint is that it's not easy enough to find out how easy import hooks are. When I tell people "you could write a simple import hook to play with that idea", they get a look of fear and panic that's completely unwarranted and just drop their cool idea. (I wonder if having complete examples of a simple global-transformer hook and a simple special-extension hook at the start of the docs would be enough to solve that problem?)
And I'm a bit worried that if Victor tries to make things like MacroPy and Hy easier, it still won't be enough for real-life cases, so all it'll do is discourage people from going right to writing import hooks and seeing how easy that already is.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160127/f55f82e2/attachment.html>
More information about the Python-ideas
mailing list