from __future__ import decorators

Discussion in 'Python' started by Jacek Generowicz, Jan 13, 2005.

  1. 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 ?
    Jacek Generowicz, Jan 13, 2005
    #1
    1. Advertising

  2. Jacek Generowicz <> 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-24-decorators-with-22-and-23.html

    Thomas
    Thomas Heller, Jan 13, 2005
    #2
    1. Advertising

  3. Jacek Generowicz

    Peter Otten Guest

    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
    Peter Otten, Jan 13, 2005
    #3
  4. Thomas Heller <> writes:

    > Jacek Generowicz <> 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-24-decorators-with-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 ?
    Jacek Generowicz, Jan 13, 2005
    #4
  5. Peter Otten <> 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.
    Jacek Generowicz, Jan 13, 2005
    #5
  6. 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
    Skip Montanaro, Jan 13, 2005
    #6
  7. Skip Montanaro <> 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.
    Jacek Generowicz, Jan 13, 2005
    #7
  8. Jacek Generowicz

    Tim Roberts Guest

    Jacek Generowicz <> 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,
    Providenza & Boekelheide, Inc.
    Tim Roberts, Jan 15, 2005
    #8
  9. Tim Roberts <> writes:

    > Jacek Generowicz <> 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.
    Jacek Generowicz, Jan 17, 2005
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Logan
    Replies:
    3
    Views:
    766
    Michael Hudson
    Nov 25, 2003
  2. Replies:
    2
    Views:
    311
  3. Ron Adam
    Replies:
    7
    Views:
    502
    Ron Adam
    Feb 9, 2007
  4. Replies:
    8
    Views:
    693
    Roy Smith
    Apr 20, 2008
  5. Malcolm Greene
    Replies:
    1
    Views:
    365
    Dan Bishop
    Apr 12, 2008
Loading...

Share This Page