Top-rated recipes tagged "dry"http://code.activestate.com/recipes/tags/dry/top/2012-07-12T14:59:11-07:00ActiveState Code RecipesPython code clone detector (Don't Repeat Yourself) (Python)
2012-07-12T14:59:11-07:00frahttp://code.activestate.com/recipes/users/4182629/http://code.activestate.com/recipes/578206-python-code-clone-detector-dont-repeat-yourself/
<p style="color: grey">
Python
recipe 578206
by <a href="/recipes/users/4182629/">fra</a>
(<a href="/recipes/tags/analysis/">analysis</a>, <a href="/recipes/tags/clone/">clone</a>, <a href="/recipes/tags/code/">code</a>, <a href="/recipes/tags/dry/">dry</a>, <a href="/recipes/tags/duplication/">duplication</a>, <a href="/recipes/tags/parse/">parse</a>, <a href="/recipes/tags/similarity/">similarity</a>, <a href="/recipes/tags/static/">static</a>, <a href="/recipes/tags/syntax/">syntax</a>).
Revision 2.
</p>
<p>Find duplicate code in Python 2/3 source files. Write a nice report about it.</p>
<p>Works at the Abstract Syntax Tree level, which is a robust way to detect clones.
See this <a href="http://francois.boutines.free.fr/python-3.2-report.html">code duplicated in the Python 3.2 standard library</a>.</p>
<p><strong>Update</strong>: I cleaned the code a little bit, made it Python 2.7 compatible and faster.</p>
namedtuple.abc - abstract base class + mix-in for named tuples (Python)
2011-04-02T02:07:00-07:00Jan Kaliszewskihttp://code.activestate.com/recipes/users/4172762/http://code.activestate.com/recipes/577629-namedtupleabc-abstract-base-class-mix-in-for-named/
<p style="color: grey">
Python
recipe 577629
by <a href="/recipes/users/4172762/">Jan Kaliszewski</a>
(<a href="/recipes/tags/abc/">abc</a>, <a href="/recipes/tags/collections/">collections</a>, <a href="/recipes/tags/dry/">dry</a>, <a href="/recipes/tags/inheritance/">inheritance</a>, <a href="/recipes/tags/namedtuple/">namedtuple</a>, <a href="/recipes/tags/shortcuts/">shortcuts</a>).
Revision 7.
</p>
<p>If you need</p>
<ul>
<li>to define <strong>named tuple subclasses</strong> (including reusable abstract ones), adding/overriding some methods, in a convenient way;</li>
<li>to have the named tuple ABC (abstract base class) for <strong>isinstance/issubclass</strong> tests;</li>
<li>or simply would like to define your named tuple classes in a <strong>class-syntax-based and DRY way</strong> (without repeating type names...)</li>
</ul>
<p>-- <strong>this recipe is for you.</strong></p>