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,...)


_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to