# chatty3.py "[Decorated]" import decorators,customdec; decorators.decorated() class C: def f(): "[chattymethod2, staticmethod]" c=C()
# example1.py import decorators def do_nothing(self): "No magic docstring here" dec_do_nothing = decorators.decorated(do_nothing) def identity(x): "[staticmethod]" return x dec_identity = decorators.decorated(identity) def name(cls): "[classmethod]" return cls.__name__ dec_name = decorators.decorated(name) class OldStyle: do_nothing = dec_do_nothing identity = dec_identity
# module.py "Magically decorated module" import decorators,sys thismodule=sys.modules[__name__] class MyClass: "[Decorated]" newmod=decorators.decorated(thismodule)
"[Decorated]" import decorators,customdec; decorators.decorated() class desc(object): def __get__(self,obj,cls): print obj,cls class C(object): def f(cls): "[classmethod]" print cls g=desc() C.g C().g
# example2.py from decorators import decorated from example1 import do_nothing, identity, name class B(object): "This is a regular class" B = decorated(B) # does nothing class C(B): "[Decorated]" do_nothing = do_nothing identity = identity name = name C = decorated(C) # regenerates the class converting methods in decorators c = C() class D: # old style "[Decorated]" def identity(x): "[staticmethod]" return x
# example1.py import decorators def do_nothing(self): "No magic docstring here" dec_do_nothing=decorators.decorated(do_nothing) def identity(x): "[staticmethod]" return x dec_identity=decorators.decorated(identity) def name(cls): "[classmethod]" return cls.__name__ dec_name=decorators.decorated(name) class OldStyle: do_nothing=dec_do_nothing identity=dec_identity class NewStyle(object): name=dec_name o=OldStyle() # creates an old style instance n=NewStyle() # creates a new style instance
# chatty3.py "[Decorated]" import decorators, customdec decorators.decorated() class C: def f(): "[chattymethod2, staticmethod]" c = C()
# module.py "Magically decorated module" import decorators, sys thismodule = sys.modules[__name__] class MyClass: "[Decorated]" newmod = decorators.decorated(thismodule)
# example2.py from decorators import decorated from example1 import do_nothing,identity,name class B(object): "This is a regular class" B=decorated(B) # does nothing class C(B): "[Decorated]" do_nothing=do_nothing identity=identity name=name C=decorated(C) # regenerates the class converting methods in decorators c=C() class D: # old style "[Decorated]" def identity(x): "[staticmethod]" return x D=decorated(D) d=D()