Meta-class fun with PEP 318 [was Re: PEP 318 - posting draft]

Sean Ross sross at connectmail.carleton.ca
Sat Mar 27 19:30:31 CET 2004


"Sean Ross" <sross at connectmail.carleton.ca> wrote in message
news:iEj9c.52673$re.2965819 at news20.bellglobal.com...
> class MetaDecorate(type):
>     "Enables delayed decoration and annotation of methods"
>     def __new__(klass, name, bases, _dict):
>         if "decorated" in _dict:
>             for method, (decorators, attributes) in
> _dict["decorated"].iteritems():
>                 _dict[method] = delayed_decorate(_dict[method],
*decorators,
> **attributes)
>             del _dict["decorated"]
>         return type.__new__(klass, name, bases, _dict)

Sorry, that part got a bit messed up:

class MetaDecorate(type):
    "Enables delayed decoration and annotation of methods"
    def __new__(klass, name, bases, _dict):
        if "decorated" in _dict:
            for m, (d, a) in _dict["decorated"].iteritems():
                _dict[m] = delayed_decorate(_dict[m], *d, **a)
            del _dict["decorated"]
        return type.__new__(klass, name, bases, _dict)





More information about the Python-list mailing list