Popular recipes tagged "metaclasses" but not "encode"http://code.activestate.com/recipes/tags/metaclasses-encode/2011-09-21T05:34:52-07:00ActiveState Code RecipesBless Classes into Singletons (Python) 2011-09-21T05:34:52-07:00Anand B Pillaihttp://code.activestate.com/recipes/users/4169530/http://code.activestate.com/recipes/577875-bless-classes-into-singletons/ <p style="color: grey"> Python recipe 577875 by <a href="/recipes/users/4169530/">Anand B Pillai</a> (<a href="/recipes/tags/metaclasses/">metaclasses</a>, <a href="/recipes/tags/patterns/">patterns</a>, <a href="/recipes/tags/singleton/">singleton</a>). </p> <p>A pattern using metaclasses for "blessing" classes into Singletons.</p> Using Metaclasses and Class Decorators to Inherit Function Docstrings (Python) 2011-06-11T00:59:35-07:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/577743-using-metaclasses-and-class-decorators-to-inherit-/ <p style="color: grey"> Python recipe 577743 by <a href="/recipes/users/4177816/">Eric Snow</a> (<a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/decorators/">decorators</a>, <a href="/recipes/tags/docstring/">docstring</a>, <a href="/recipes/tags/inheritance/">inheritance</a>, <a href="/recipes/tags/metaclass/">metaclass</a>, <a href="/recipes/tags/metaclasses/">metaclasses</a>). Revision 4. </p> <p>You'll find three different approaches to copying the method's docstring to the overriding method on a child class.</p> <p>The function decorator approach is limited by the fact that you have to know the class when you call the decorator, so it can't be used inside a class body. However, <a href="http://code.activestate.com/recipes/577746/">recipe #577746</a> provides a function decorator that does not have this limitation.</p> Easy State Pattern - support for implementing state machines (Python) 2009-06-15T11:25:17-07:00Rodney Drenthhttp://code.activestate.com/recipes/users/4050661/http://code.activestate.com/recipes/576613-easy-state-pattern-support-for-implementing-state-/ <p style="color: grey"> Python recipe 576613 by <a href="/recipes/users/4050661/">Rodney Drenth</a> (<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/decorators/">decorators</a>, <a href="/recipes/tags/metaclasses/">metaclasses</a>, <a href="/recipes/tags/oop/">oop</a>, <a href="/recipes/tags/state_machine/">state_machine</a>, <a href="/recipes/tags/state_pattern/">state_pattern</a>). Revision 3. </p> <p>Provides is a module that gives support for implementing state machines. States are implemented as subclasses, derived from the state machine class. Methods that are state dependant or which cause transitions are declared using decorators. Because states can be subclasses of other states, common behaviour among several states is easily supported. The implementation allows for implementing multiple states or substates within a class.</p> <p>This module best support statem achines implemeting controllers for embedded systems, implementing user interfaces, or in discrete event model simulation. Parsers, which generally have many states and where you would need to define a Transaction method for each different character encountered would be more easily implemented by other means.</p>