Popular recipes tagged "docstring" but not "gzip"http://code.activestate.com/recipes/tags/docstring-gzip/2013-07-01T02:29:40-07:00ActiveState Code RecipesInherit method docstrings without breaking decorators or violating DRY (Python) 2013-07-01T02:29:40-07:00nikratiohttp://code.activestate.com/recipes/users/4180248/http://code.activestate.com/recipes/578587-inherit-method-docstrings-without-breaking-decorat/ <p style="color: grey"> Python recipe 578587 by <a href="/recipes/users/4180248/">nikratio</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>). Revision 2. </p> <p>There are several recipes for inheriting method docstrings. However, most of them either violate DRY (and have you repeat the ancestor class name in the method decorator that sets the docstring), or do break decorators that try to access the docstring (because the docstring is only assigned after class creation). This recipe avoids both problems.</p> <p><strong>Note</strong>: This recipe uses the mro method from <a href="http://code.activestate.com/recipes/577748-calculate-the-mro-of-a-class/" rel="nofollow">http://code.activestate.com/recipes/577748-calculate-the-mro-of-a-class/</a></p> Inherit Method Docstrings Using Only Function Decorators (Python) 2011-06-26T02:28:55-07:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/577746-inherit-method-docstrings-using-only-function-deco/ <p style="color: grey"> Python recipe 577746 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>). Revision 3. </p> <p>This recipe provides a descriptor and a decorator. The decorator will be used on any method in your class to indicate that you want that method to inherit its docstring.</p> <p>This is useful when you are using abstract bases classes and want a method to have the same docstring as the abstract method it implements.</p> <p>This recipe uses <a href="http://code.activestate.com/recipes/577745/">recipe #577745</a>, the deferred_binder module.</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> Docstring inheritance decorator (Python) 2009-07-28T13:42:32-07:00Shai Bergerhttp://code.activestate.com/recipes/users/2014324/http://code.activestate.com/recipes/576862-docstring-inheritance-decorator/ <p style="color: grey"> Python recipe 576862 by <a href="/recipes/users/2014324/">Shai Berger</a> (<a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/descriptor/">descriptor</a>, <a href="/recipes/tags/docstring/">docstring</a>, <a href="/recipes/tags/inheritance/">inheritance</a>, <a href="/recipes/tags/metaprogramming/">metaprogramming</a>). </p> <p>In many cases, a subclass overrides a method in a parent class, just to change its implementation; in such cases, it would be nice to preserve the overridden method's docstring. The decorator below can be used to achieve this without explicit reference to the parent class. It does this by replacing the function with a descriptor, which accesses the parent class when the method is accessed as an attribute.</p> Docstring inheritance class decorator (Python) 2011-11-23T20:12:03-08:00Alec Thomashttp://code.activestate.com/recipes/users/2870300/http://code.activestate.com/recipes/577102-docstring-inheritance-class-decorator/ <p style="color: grey"> Python recipe 577102 by <a href="/recipes/users/2870300/">Alec Thomas</a> (<a href="/recipes/tags/class/">class</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/docstring/">docstring</a>, <a href="/recipes/tags/inheritance/">inheritance</a>). Revision 2. </p> <p>Inherits method docstrings from parent classes.</p> Viewing embedded pictures within docstrings (Python) 2008-10-15T01:27:26-07:00Andre Robergehttp://code.activestate.com/recipes/users/2467063/http://code.activestate.com/recipes/576538-viewing-embedded-pictures-within-docstrings/ <p style="color: grey"> Python recipe 576538 by <a href="/recipes/users/2467063/">Andre Roberge</a> (<a href="/recipes/tags/docstring/">docstring</a>, <a href="/recipes/tags/embedded_image/">embedded_image</a>, <a href="/recipes/tags/viewer/">viewer</a>). </p> <p>Python docstrings are textual information about objects. They can be displayed via help(obj). However, they can not contain images. This recipe allows the inclusion of images (encoded in base 64 in the Python file) inside docstrings in a transparent way. The images are indicated as "docpicture = file_name.ext" inside the docstring, and the encoded data is in variable "file_name" inside the same module.</p>