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/2005-March/052479.html below:

[Python-Dev] @decoration of classes

[Python-Dev] @decoration of classes [Python-Dev] @decoration of classesPhillip J. Eby pje at telecommunity.com
Thu Mar 31 04:21:41 CEST 2005
At 10:05 AM 3/31/05 +1000, Nick Coghlan wrote:
>PJE's example of moving the decoration near the top of the class 
>definition without allowing class decoration contains an important caveat: 
>it requires that the decorators be written to support doing that. Allowing 
>class decoration means any appropriate decorators can be used, unmodified, 
>to affect classes as well as functions.

Yeah, but that can be trivially worked around using a 'decorate' function, 
e.g.:

from protocols.advice import addClassAdvisor

def decorate(*decorators):
     decorators = list(decorators)[::-1]
     def callback(cls):
         for dec in decorators:
             cls = cls(dec)
         return cls
     addClassAdvisor(callback)


class SomeClass:
     decorate(dec1,dec2,...)


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