By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,818 Members | 1,313 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,818 IT Pros & Developers. It's quick & easy.

from __future__ import decorators

P: n/a
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 ?

Jul 18 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Jacek Generowicz <ja**************@cern.ch> 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

Jul 18 '05 #2

P: n/a
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
Jul 18 '05 #3

P: n/a
Thomas Heller <th*****@python.net> writes:
Jacek Generowicz <ja**************@cern.ch> 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 ?
Jul 18 '05 #4

P: n/a
Peter Otten <__*******@web.de> 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.
Jul 18 '05 #5

P: n/a

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

Jul 18 '05 #6

P: n/a
Skip Montanaro <sk**@pobox.com> 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.
Jul 18 '05 #7

P: n/a
Jacek Generowicz <ja**************@cern.ch> 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, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #8

P: n/a
Tim Roberts <ti**@probo.com> writes:
Jacek Generowicz <ja**************@cern.ch> 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.
Jul 18 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.