A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2004-March/043577.html below:

[Python-Dev] method decorators (PEP 318)

[Python-Dev] method decorators (PEP 318)Alex Martelli aleaxit at yahoo.com
Sat Mar 27 03:09:21 EST 2004
On 2004 Mar 27, at 06:27, Barry Warsaw wrote:
    ...
> attributes, but decorators can also do the trick in a nasty way:
>
> def foobar [
>     lambda f: f.author = 'Guido van Rossum',
>     lambda f: f.deprecated = True,
>     classmethod] (self, arg):
>     # Now what?

Not necessarily all that nasty:

def foobar [ with_attributes(
         author="Guido van Rossum",
         deprecated=True),
     classmethod] (cls, args):
         pass

with a built-in 'with_attributes' equivalent to:

def with_attributes(f, **kwds):
     for k, v in kwds.iteritems():
         setattr(f, k, v)
     return f


Alex


More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4