Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Dev

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

 

 

Python dev RSS feed   Index | Next | Previous | View Threaded


nas at arctrix

Aug 24, 2004, 12:33 PM

Post #1 of 7 (916 views)
Permalink
Re: [Python-checkins] python/nondist/peps pep-0318.txt, 1.25, 1.26

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.

Neil
_______________________________________________
Python-Dev mailing list
Python-Dev[at]python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


bac at OCF

Aug 24, 2004, 12:57 PM

Post #2 of 7 (876 views)
Permalink
Re: Re: [Python-checkins] python/nondist/peps pep-0318.txt, 1.25, 1.26 [In reply to]

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
_______________________________________________
Python-Dev mailing list
Python-Dev[at]python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


skip at pobox

Aug 24, 2004, 12:59 PM

Post #3 of 7 (884 views)
Permalink
Re: Re: [Python-checkins] python/nondist/peps pep-0318.txt, 1.25, 1.26 [In reply to]

>> List some possible reasons why arriving at consensus about decorators
>> has been so hard (or impossible) to acheive. There are certainly
>> more.

Neil> Perhaps you could add my reservation (objection is too strong a
Neil> word). I think decorators are not powerful enough given their
Neil> high syntactic profile. This could be rephrased as "if we are
Neil> going the use the @ sign then it should be able to do really cool
Neil> things".

I was trying to elaborate general barriers to concluding this process, not
issues related to selecting one proposal over another.

Neil> One idea is to have the compiler pass the AST for the function
Neil> body to the decorator function. The decorator could create new
Neil> nodes in the AST or modify existing ones. That would allow
Neil> decorators to do things like adding a try/except without
Neil> introducing another function call. The output of the decorator
Neil> would be passed to the code generator.

I suppose you could do that, although if you did I suspect metaclasses would
seem tame by comparison. Couldn't you do something like this?

@ast_to_func
@neils_cool_ast_transform
@func_to_ast
def f(a):
pass

After all, there's no restriction on what a decorator can return.

How about we save true AST decorators for "$"? <wink>

Skip
_______________________________________________
Python-Dev mailing list
Python-Dev[at]python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


fumanchu at amor

Aug 24, 2004, 1:08 PM

Post #4 of 7 (887 views)
Permalink
RE: Re: [Python-checkins] python/nondist/peps pep-0318.txt, 1.25, 1.26 [In reply to]

Skip Montanaro (I think) wrote:
> List some possible reasons why arriving at consensus about decorators
> has been so hard (or impossible) to acheive. There are certainly
more.

First reaction: Each proposal, by its very syntax, suggested a range of
non-decorator use cases and semantics. Unfortunately, we have dozens of
syntax proposals with "ranges of implication" which do not overlap, and
therefore cannot be evaluated fairly (very little "apples to apples"
comparison). Most of the remaining discussions addressed Beauty, Fear,
Magic, or Intuition, which take more effort and space to analyze
properly than your typical Usenet post allows.


Robert Brewer
MIS
Amor Ministries
fumanchu[at]amor.org
_______________________________________________
Python-Dev mailing list
Python-Dev[at]python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


nas at arctrix

Aug 24, 2004, 1:58 PM

Post #5 of 7 (874 views)
Permalink
Re: Re: [Python-checkins] python/nondist/peps pep-0318.txt, 1.25, 1.26 [In reply to]

On Tue, Aug 24, 2004 at 02:59:33PM -0500, Skip Montanaro wrote:
> Couldn't you do something like this?
>
> @ast_to_func
> @neils_cool_ast_transform
> @func_to_ast
> def f(a):
> pass

That doesn't work as there is, AFAIK, no way to write func_to_ast().
The necessary information has already been thrown away when it gets
called.

Neil
_______________________________________________
Python-Dev mailing list
Python-Dev[at]python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


pje at telecommunity

Aug 24, 2004, 2:02 PM

Post #6 of 7 (888 views)
Permalink
Re: Re: [Python-checkins] python/nondist/peps pep-0318.txt, 1.25, 1.26 [In reply to]

At 04:58 PM 8/24/04 -0400, Neil Schemenauer wrote:
>On Tue, Aug 24, 2004 at 02:59:33PM -0500, Skip Montanaro wrote:
> > Couldn't you do something like this?
> >
> > @ast_to_func
> > @neils_cool_ast_transform
> > @func_to_ast
> > def f(a):
> > pass
>
>That doesn't work as there is, AFAIK, no way to write func_to_ast().

There is one, but it's ugly and involves inspect.get_source. :)

_______________________________________________
Python-Dev mailing list
Python-Dev[at]python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


greg at cosc

Aug 24, 2004, 8:36 PM

Post #7 of 7 (878 views)
Permalink
Re: Re: [Python-checkins] python/nondist/peps pep-0318.txt, 1.25, 1.26 [In reply to]

> How about we save true AST decorators for "$"? <wink>

Nah, AST decorators should be spelled "@$~" (that's "AST"
written in funny symbols).

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
greg[at]cosc.canterbury.ac.nz +--------------------------------------+
_______________________________________________
Python-Dev mailing list
Python-Dev[at]python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com

Python dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.