473,405 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

from __future__ import decorators

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
8 1568
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
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
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
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

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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Logan | last post by:
Is there a list with all 'from __future__ import ...' statements (which lists all the statements, in which version of Python the feature was introduced and in which version of Python it will become...
5
by: Steve Holden | last post by:
This is even stranger: it makes it if I import the module a second time: import dbimp as dbimp import sys if __name__ == "__main__": dbimp.install() #k = sys.modules.keys() #k.sort() #for...
3
by: Achim Dahlhoff | last post by:
Hi. I'm trying to find out the diffrence between normal classes and classes derived from built-in types. (Which is causing me trouble trying to instantiate a class using C API calls) >>>...
2
by: mithrond | last post by:
i can't use "from __future__ import ..." statement import two statesments in the same time. for the simple code: from __future__ import with_statement, division with file('url.txt','r') as f:...
4
by: lee | last post by:
what are the things that we can do with import from future usage.....i heard its very interesting......thanks
7
by: Ron Adam | last post by:
from __future__ import absolute_import Is there a way to check if this is working? I get the same results with or without it. Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) on win 32 ...
7
by: samslists | last post by:
Am I the only one that thinks this would be useful? :) I'd really like to be able to use python 3.0's print statement in 2.x. Is this at least being considered as an option for 2.6? It seems...
1
by: Malcolm Greene | last post by:
Is there any consensus on what "from __future__ import" options developers should be using in their Python 2.5.2 applications? Is there a consolidated list of "from __future__ import" options to...
0
by: Tim Golden | last post by:
Malcolm Greene wrote: Well, that bit's easy: import __future__ print __future__.all_feature_names TJG
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.