variable declaration

Diez B. Roggisch deetsNOSPAM at
Mon Jan 31 12:28:34 EST 2005

> A decorator is a modifier to a subsequent binding, and it modifies the
> reference and not the referent. So how is it anythng but declarative?

I learned the hard way that it still is simply interpreted - its a pretty
straight forward syntactic sugaring, as this shows:

foo = classmethod(foo)



Now @classmethod has to return a callable that gets passed foo, and the
result is assigned to foo - not more, not less, so it becomes equivalent to
the older type of creating a class method.

Is this a declaration? I'd personally say and think "practically, yes", as I
also view

class Bar:

as a declaration. But obviously some people like Alex Martelli have
different views on this (and are right), because you can do this in python:

if condition:
    class Foo:
        def bar(self):

    class Foo:
        def schnarz(self):

So that makes class statements not as declarative as they are in languages
like java.

So to sum it up (for me at least): things like metaclasses, decorators and
so on make me write code more declarative - if they are a declaration in
the strict sense, I don't bother.


Diez B. Roggisch

More information about the Python-list mailing list