[Python-Dev] Re: Call for defense of @decorators
tismer at stackless.com
Sat Aug 7 01:04:22 CEST 2004
Martin v. Löwis wrote:
> Christian Tismer wrote:
>> the primary purpose of all the decorator syntax effort
>> is to get the
>> foo = classmethod(foo)
>> into the right place, not after but before the definition.
>> Dunno if this was mentioned before, but why not simply do that?
>> Move the statement right before the def and provide a way
>> that this gets recognized correctly.
>> No syntax change, just the convenience people asked for.
> I don't think this can work. How precisely would you implement
> it? Python traditionally executes source code from top to bottom,
> except for loops.
Hey, this is an implementation detail, isn't it? :-)
I can think of a couple of ways to implement it. One would be
to defer execution of a statement with undefined names until
the end of the whole code block in the case of a class
definition and to resolve the names late.
Cleaner would probably be to have something like a placeholder
for the undefined function, assign to the name a special
object and trap the def statement to resolve the object.
(this comes to me since I'm just dealing with reference objects
in PDF files, which are filled in later).
No, I was really not concerned about how to do this, surely
it won't work with plain sequential execution, but other
proposals (which Guido considered once) like just putting
in front of things also needs some (simpler of course) special
At the risk of getting slogged, I also thought of
myfunc := classmethod(myfunc)
for a short time, with ":=" as a late binding assignment
operator which defers its operation until myfunc is
defined, but I think this is not a popular idea. :-)
To save *some* typing (laziness was also a driver for this
whole decorator nightmare), we could also remove the assignment
and just have a function call like
which reduces the re-typing to two.
Anyway, compared to the expected effect, this whole discussion
appears worse to me than the ternary expression thread last
year, where one at least could learn something new.
Fine that a?b:c and friends were put down. I really hate to
see so much time wasted just for decorators. I could live
with a special rule like my little proposal. I also agree
that all the syntax pirouettes tried so far just add more
ugliness to the language, just for nothing.
Using a single char as a prefix might be a compromise
after all. But must it be "@", such an eye-catching, ugly piece
Looks like macro-alert, hey we get into special mode and
decorate tokens in special contexts for special meaning.
This is even worse than what Prothon tries with ? and !.
If @, why not $, this might attract Perl users to Python.
If we are getting perverse, why not simply go and add decorators
using XML syntax?
<decorator kind="classmethod" comment="we deserve what we ask for"/>
I'd-like-to-ask-green-peace-to-protect-my-language -- chris
Christian Tismer :^) <mailto:tismer at stackless.com>
Mission Impossible 5oftware : Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/
14109 Berlin : PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776
PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04
whom do you want to sponsor today? http://www.stackless.com/
More information about the Python-Dev