PEP 318 : Def and Class in expressions

Sean Ross sross at connectmail.carleton.ca
Sat Mar 27 14:11:20 EST 2004


"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





More information about the Python-list mailing list