[Python-Dev] method decorators (PEP 318) (original) (raw)
Skip Montanaro skip at pobox.com
Fri Mar 26 14:33:00 EST 2004
- Previous message: [Python-Dev] method decorators (PEP 318)
- Next message: [Python-Dev] method decorators (PEP 318)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Robert> However, the idea of putting such attributes at the same level
Robert> as the rest of the function block is ugly to me--newbies are
Robert> going to go mad the first few times, trying to figure out *when*
Robert> such statements are evaluated.
An excellent point. It seems to me that @statements would have to be restricted to occur only at the beginning of a function (immediately after the def line or the docstring). If not, you'll probably get people (newbies at least) trying to write stuff like this:
def foo(a):
if a > 5:
@attr: "bob"
elif a > 0:
@attr: "skip"
else:
@attr: "guido"
The other forms (via a decorator, using explicit attribute assignments after the definition) make it explicit that these attribute assignments don't occur in the context of function execution.
Skip
- Previous message: [Python-Dev] method decorators (PEP 318)
- Next message: [Python-Dev] method decorators (PEP 318)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]