Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > from __future__ import decorators

Reply
Thread Tools

from __future__ import decorators

 
 
Jacek Generowicz
Guest
Posts: n/a
 
      01-13-2005
I have some code, which makes copious use of the @decorator syntax
which was introduced in Python2.4. Now I find myself in a situation
where I have to run the code under Python 2.3. However, I would like
to keep developing the code with the new syntax.

How could I best automate the process of making the syntax digestible
by Python2.3 ?

 
Reply With Quote
 
 
 
 
Thomas Heller
Guest
Posts: n/a
 
      01-13-2005
Jacek Generowicz <(E-Mail Removed)> writes:

> I have some code, which makes copious use of the @decorator syntax
> which was introduced in Python2.4. Now I find myself in a situation
> where I have to run the code under Python 2.3. However, I would like
> to keep developing the code with the new syntax.
>
> How could I best automate the process of making the syntax digestible
> by Python2.3 ?


The only way that I know of is this, although you have to rewrite your
code somewhat:

http://dirtsimple.org/2004/11/using-...22-and-23.html

Thomas

 
Reply With Quote
 
 
 
 
Peter Otten
Guest
Posts: n/a
 
      01-13-2005
Jacek Generowicz wrote:

> I have some code, which makes copious use of the @decorator syntax
> which was introduced in Python2.4. Now I find myself in a situation
> where I have to run the code under Python 2.3. However, I would like
> to keep developing the code with the new syntax.
>
> How could I best automate the process of making the syntax digestible
> by Python2.3 ?


Have a look at Bill Mill's redecorate utility:

http://llimllib.f2o.org/files/redecorate.py

Peter


 
Reply With Quote
 
Jacek Generowicz
Guest
Posts: n/a
 
      01-13-2005
Thomas Heller <(E-Mail Removed)> writes:

> Jacek Generowicz <(E-Mail Removed)> writes:
>
> > I have some code, which makes copious use of the @decorator syntax
> > which was introduced in Python2.4. Now I find myself in a situation
> > where I have to run the code under Python 2.3. However, I would like
> > to keep developing the code with the new syntax.
> >
> > How could I best automate the process of making the syntax digestible
> > by Python2.3 ?

>
> The only way that I know of is this, although you have to rewrite your
> code somewhat:


The whole point would be to keep on developing perfectly normal
Python2.4 code, but have some means of getting it to run on 2.3,
without modification.

> http://dirtsimple.org/2004/11/using-...22-and-23.html


Certainly an interesting approach. Perhaps this can be combined with a
simple textual transformation of the source code which simply replaces
@decorator with add_assignment_advisor(decorator) ... or something
along those lines.

Still, I'd prefer to find a solution on the AST level, but I guess
that's not possible without re-writing the praser.

Crazy idea ... would it be possible to shadow 2.3's parser with one
stolen from 2.4 ?
 
Reply With Quote
 
Jacek Generowicz
Guest
Posts: n/a
 
      01-13-2005
Peter Otten <(E-Mail Removed)> writes:

> Have a look at Bill Mill's redecorate utility:
>
> http://llimllib.f2o.org/files/redecorate.py


Heh, this is exactly the sort of thing I wanted do avoid writing, as
it would be difficult to get right. Looks like it's author has similar
feelings. However, it could well be the most pragmatic solution in my
case.

Thanks.
 
Reply With Quote
 
Skip Montanaro
Guest
Posts: n/a
 
      01-13-2005

Jacek> Crazy idea ... would it be possible to shadow 2.3's parser with
Jacek> one stolen from 2.4 ?

If you're willing to go to that much trouble, why not just upgrade to 2.4?

Skip

 
Reply With Quote
 
Jacek Generowicz
Guest
Posts: n/a
 
      01-13-2005
Skip Montanaro <(E-Mail Removed)> writes:

> Jacek> Crazy idea ... would it be possible to shadow 2.3's parser with
> Jacek> one stolen from 2.4 ?
>
> If you're willing to go to that much trouble, why not just upgrade to 2.4?


*I* upgraded to 2.4 sometime when it was in alpha.
 
Reply With Quote
 
Tim Roberts
Guest
Posts: n/a
 
      01-15-2005
Jacek Generowicz <(E-Mail Removed)> wrote:
>
>I have some code, which makes copious use of the @decorator syntax


I'm very curious to know what kind of application you are writing in which
"copious use of the @decorator syntax" actually solved a problem
productively.
--
- Tim Roberts, http://www.velocityreviews.com/forums/(E-Mail Removed)
Providenza & Boekelheide, Inc.
 
Reply With Quote
 
Jacek Generowicz
Guest
Posts: n/a
 
      01-17-2005
Tim Roberts <(E-Mail Removed)> writes:

> Jacek Generowicz <(E-Mail Removed)> wrote:
> >
> >I have some code, which makes copious use of the @decorator syntax

>
> I'm very curious to know what kind of application you are writing in which
> "copious use of the @decorator syntax" actually solved a problem
> productively.


An application in which, before python2.4, I used to have lots of code
that looked like

def somefun(...):
...
somefun = somedecorator(somefun)




It's not interesting to discuss what "somedecorator" actually
represents. But being able to see that the function is decorated right
next to the "def", as opposed to having to look beyond the end of the
definition certianly makes a significant difference to me.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
from __future__ import print samslists@gmail.com Python 8 04-20-2008 02:12 PM
Recommended "from __future__ import" options for Python 2.5.2? Malcolm Greene Python 1 04-12-2008 07:30 PM
from __future__ import absolute_import ? Ron Adam Python 7 02-09-2007 07:03 PM
a odd thing of "from __future__ import ..." mithrond@gmail.com Python 2 10-15-2006 01:44 AM
'from __future__ import ...' overview Logan Python 3 11-25-2003 11:47 AM



Advertisments