[Python-Dev] Re: [Python-checkins] python/nondist/peps pep-0318.txt, 1.25, 1.26

Brett C. bac at OCF.Berkeley.EDU
Tue Aug 24 21:57:03 CEST 2004


Neil Schemenauer wrote:

> On Tue, Aug 24, 2004 at 11:56:13AM -0700, montanaro at users.sourceforge.net wrote:
> 
>>Modified Files:
>>	pep-0318.txt 
>>Log Message:
>>List some possible reasons why arriving at consensus about
>>decorators has been so hard (or impossible) to acheive.  There are
>>certainly more.
> 
> 
> Perhaps you could add my reservation (objection is too strong a
> word).  I think decorators are not powerful enough given their high
> syntactic profile.  This could be rephrased as "if we are going the
> use the @ sign then it should be able to do really cool things".
> 
> One idea is to have the compiler pass the AST for the function body
> to the decorator function.  The decorator could create new nodes in
> the AST or modify existing ones.  That would allow decorators to do
> things like adding a try/except without introducing another function
> call.  The output of the decorator would be passed to the code
> generator.
> 

That kind of stuff is my dream use of the AST; modifying it before final 
compilation to a .pyc file.  Although that could also just be set up in 
a list that gets called on *all* compilations.

We could also just keep the AST around in the code object, although that 
would be space-consuming.

-Brett


More information about the Python-Dev mailing list