Popular recipes tagged "class_decorator" but not "comparison"http://code.activestate.com/recipes/tags/class_decorator-comparison/2013-12-10T02:36:25-08:00ActiveState Code RecipesOptional arguments decorator (Python) 2013-01-28T05:03:43-08:00Maxime H Lapointehttp://code.activestate.com/recipes/users/4185033/http://code.activestate.com/recipes/578435-optional-arguments-decorator/ <p style="color: grey"> Python recipe 578435 by <a href="/recipes/users/4185033/">Maxime H Lapointe</a> (<a href="/recipes/tags/class_decorator/">class_decorator</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/decorators/">decorators</a>, <a href="/recipes/tags/python/">python</a>). Revision 2. </p> <p>If you need your decorator to receive arguments, optional or not, then you should decorate it with the opt_arg_dec decorator to handle all the logic that this implies for you.</p> Composition of classes instead of multiple inheritance (Python) 2011-04-16T03:40:19-07:00Ethan Furmanhttp://code.activestate.com/recipes/users/4177684/http://code.activestate.com/recipes/577658-composition-of-classes-instead-of-multiple-inherit/ <p style="color: grey"> Python recipe 577658 by <a href="/recipes/users/4177684/">Ethan Furman</a> (<a href="/recipes/tags/class_decorator/">class_decorator</a>, <a href="/recipes/tags/composition/">composition</a>, <a href="/recipes/tags/inheritance/">inheritance</a>, <a href="/recipes/tags/multiple_inheritance/">multiple_inheritance</a>). </p> <p>MI can be difficult and confusing, and if the base classes don't cooperate -- well, cooperative MI won't work.</p> <p>One way around this is to use composition instead. This class decorator will combine the source classes with the target class, ensuring that no duplications occur (raises a TypeError if there are any).</p> Keyword Argument Injection with Python Decorators (Python) 2010-09-05T17:06:04-07:00Ahmet Emre Aladağhttp://code.activestate.com/recipes/users/4174877/http://code.activestate.com/recipes/577382-keyword-argument-injection-with-python-decorators/ <p style="color: grey"> Python recipe 577382 by <a href="/recipes/users/4174877/">Ahmet Emre Aladağ</a> (<a href="/recipes/tags/class/">class</a>, <a href="/recipes/tags/class_decorator/">class_decorator</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/injection/">injection</a>, <a href="/recipes/tags/variable/">variable</a>). Revision 2. </p> <p>In most of the object oriented codes we write, we need to set class attributes to the given argument values and this is a very line-consuming thing. To get over these redundant lines, I found a solution using decorators. </p> Bound Inner Classes (Python) 2013-12-10T02:36:25-08:00Larry Hastingshttp://code.activestate.com/recipes/users/2467657/http://code.activestate.com/recipes/577070-bound-inner-classes/ <p style="color: grey"> Python recipe 577070 by <a href="/recipes/users/2467657/">Larry Hastings</a> (<a href="/recipes/tags/class_decorator/">class_decorator</a>, <a href="/recipes/tags/descriptor/">descriptor</a>). Revision 8. </p> <p>This recipe provides the class decorator <code>BoundInnerClass</code>. The decorator makes inner classes symmetric with method calls. Functions declared inside classes become "methods", and when you call them through an object they automatically get a reference to "self". The <code>BoundInnerClass</code> decorator makes this work for inner classes: an inner class decorated with <code>BoundInnerClass</code> gets a reference to that same (now "outer") object passed in automatically to the inner class's <code>__init__</code>.</p> <p>The recipe works unchanged in Python 2.6 and 3.1, and is licensed using the Zlib license.</p>