FAQ
"PF" <peufeu at free.fr> wrote in message news:opr5jagci1b723ru at news.free.fr...
Hello,

I'm pleased to see activity on this topic as it pains me to write
"classmethod" two pages of code after the method definition. However I
find the decorators to obfuscate the syntax and lessen the expressivity
(ie. they restrain what can be done).

All these problems come from the fact that the execution of the
"foo=staticmethod(foo)" must be delayed after the execution of the "def"
statement because it must act on the function after it has been defined.

Normal program execution thus flow forces it to be placed after the
"def", while readability would require it to be placed *before* the 'def'.

How to reverse the execution order ? One method would be to use an
expression, but that would get very ugly soon, and Python's indented
syntax does not lend itself well to such twistings. To mix a few previous
postings :

mymethod = staticmethod( def (args):
method code...
)

is just plain ugly.

mymethod = staticmethod( def (args) ):
method code...

is also quite ugly.

I don't like the decorators either.

So the root of the problem is the fact that the source code executes from
top to bottom. I see two solutions.

Check out "Re: Meta-class fun with PEP 318 [was Re: PEP 318 - posting
draft]", for another solution, but only for methods.

decorate("g", staticmethod)
def g():
return "G"

Sean

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 4 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedMar 27, '04 at 6:46p
activeMar 28, '04 at 12:11a
posts4
users4
websitepython.org

People

Translate

site design / logo © 2022 Grokbase