mixing statements into J2

Discussion in 'Python' started by Robert Brewer, Aug 26, 2004.

  1. > > > Can we insert conditional expressions in the
    > decorator list ?
    > >
    > > Not with the current patch; however, that option may be

    > allowed in the future.
    >
    > "In the future" means "post-2.4, when we have an idea of what people
    > are doing with it". Right now, there's not a whole lot of use cases
    > for more complex expressions in the decorator area, and there's more
    > potential for horror. Guido made this call on a gut feeling, not on
    > any technical grounds. His gut is usually good on this.
    >
    > > The order of operation would have to be reversed,

    >
    > I don't see why.


    It's not a requirement, but it seems reasonable to me. If you're going
    to set off a decorator suite and then mix in normal Python statements,
    the two models collide over order of operation:

    using:
    if test:
    memoize
    else:
    synchronize
    classmethod
    def foo(self, *args):
    stuff(args)

    The statements get evaluated top-to-bottom, but the decorators get
    applied bottom-to-top. It would be one more confusing issue in an
    already-confusing syntax. Not to mention that the current patch pushes
    decorators onto the stack at compile-time, and then pops them off after
    the function def. Mixing statements into the suite would move decorators
    from compile-time to runtime (at least, I don't see any way to avoid
    that without introducing a whole new layer of pragmas).

    If I felt it were possible, I would have recommended that application
    order in J2 be the opposite of A1. But I figured that would cause
    another two weeks of debate, which we don't have. I certainly see that
    "using:" provides a case for top-to-bottom, where "@decorator" implies
    the opposite.

    > > so *IF* Guido votes yes,
    > > then you need to bring this up again immediately.

    >
    > God no. Please don't. Work with the syntax that's chosen, then we can
    > revisit this for 2.5.


    Waiting until then guarantees the question won't be addressed, due to
    backward-compatibility issues which we will have then which we do not
    have now. Which I'm willing to concede to be a foregone conclusion at
    this point. Perhaps it would be enough just to say (to Guido), "this is
    still an open issue (one of many)"?


    Robert Brewer
    MIS
    Amor Ministries
     
    Robert Brewer, Aug 26, 2004
    #1
    1. Advertising

  2. On Thu, 26 Aug 2004 10:36:08 -0700, Robert Brewer wrote:
    > using:
    > if test:
    > memoize
    > else:
    > synchronize
    > classmethod
    > def foo(self, *args):
    > stuff(args)


    Others have pointed out the illegality of this, I would point out there is
    a legal way for those who may not realize it:

    if test:
    myDec = memoize
    else:
    myDec = syncronize

    using:
    myDec
    classmethod
    def foo(self, *args):
    stuff(*args)



    I quite frequently do this to create modules that adapt to the environment
    they are in... e.g., I don't require Zope support but if you have it I
    will dynamically derive a class from Persistant, or object otherwise:

    base = object
    try:
    import ZODB
    base = ZODB.Persistant
    except:
    # one of those rare cases where a bare except doesn't matter
    pass

    class Whatever(base):
    pass

    (I don't actually do this anywhere but I do the equivalent elsewhere in my
    code.)

    This is one of those things that keeps me from ever wanting to go back to
    C++; you shouldn't make a habit out of this but when you need it there is
    no substitute.
     
    Jeremy Bowers, Aug 27, 2004
    #2
    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. Neil Zanella
    Replies:
    8
    Views:
    1,220
    mfmehdi
    Oct 20, 2006
  2. Harry George
    Replies:
    6
    Views:
    432
    Bart Nessux
    Feb 23, 2004
  3. Vince
    Replies:
    12
    Views:
    770
    Martin Gregorie
    Jan 21, 2008
  4. gabriele renzi

    Mixing Constants into objects

    gabriele renzi, Aug 14, 2005, in forum: Ruby
    Replies:
    10
    Views:
    220
    Joel VanderWerf
    Aug 15, 2005
  5. John Crichton
    Replies:
    6
    Views:
    283
    John Crichton
    Jul 12, 2010
Loading...

Share This Page