[Python-Dev] method decorators (PEP 318)
Paul Prescod
paul at prescod.net
Sat Mar 27 18:00:27 EST 2004
Russell Finn wrote:
> Mike Rovner wrote:
>
>
> I came up with nearly the same idea after reading Guido's original post,
> except that I recommend using the existing dictionary literal syntax:
>
> def func (args):
> { author: "Guido", deprecated: True}
> '''doc'''
> pass
>
> Perhaps this was just a typo in Mike's post.
What should happen in this case?
mod_author = "Guido"
author = 5
def func(self, author, mod_author):
{ author: mod_author}
func("Paul", "Bill")
Does the func get:
func.author = "Guido"
or
func.5 = "Guido"
or
func.Paul = "Bill"
or
...
A better solution is:
def func(self, author, mod_author){
author: mod_author
}:
Although this particular example is confusing because of the reused
argument names, it is still reasonably clear that the decorator is
evaluated at _definition time_ not _function run time_.
Paul Prescod
More information about the Python-Dev
mailing list