<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Oct 6, 2012, at 2:50 PM, <a href="mailto:exarkun@twistedmatrix.com">exarkun@twistedmatrix.com</a> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">On 09:22 pm, <a href="mailto:ardesai@yahoo.com">ardesai@yahoo.com</a> wrote:<br><blockquote type="cite">Given that twisted tutorials and other written materials show examples <br>of derived classes for Protocol, HTTP Request etc., is there a good <br>reason for many classes (almost all I suspect) (e.g. 'class Request' , <br>'class BaseProtocol',&nbsp; 'class _PauseableMixin', etc.) to be old style <br>classes as opposed to a new style python classes?<br><br>Given that newer versions of twisted (and user apps) run on newer <br>versions of python, I initially (a few years ago) tried to call the <br>base class using super(), but was surprised to find twisted implements <br>using old style classes.<br><br><br>New style classes make it easy to call a base class method (by using <br>super).&nbsp; Would the MRO in new style classes make it better or worse? <br>However, nothing wrong with old style classes, esp. if twisted depends <br>on the depth-first MRO of old style classes.<br><br>Can someone clarify whether use of old style classes is intentional <br>(e.g. due to MRO)?<br></blockquote><br>It is intentional in case any applications based on Twisted rely on <br>behavior of classic classes, such as the MRO differences. &nbsp;Classes added <br>to Twisted now are all new-style, though.<br></blockquote></div><br><div>In your own applications, if you want to call the base class using super(), in most cases you may simply do this:</div><div><br></div><div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div>class MyNewStyleThing(OldStyleThingFromTwisted, object):</div></blockquote><br></div><div>Sticking 'object' on the <i style="font-weight: bold; ">end</i>&nbsp;of the inheritance hierarchy is always[1] safe; it will make your new class new-style, and it will keep working if you ever manage to migrate to Python 3, where <i>all</i>&nbsp;classes are new-style; or, if Twisted ever undergoes a "flag day" to switch over to new-style classes for everything.</div><div><br></div><div>(Warning: sticking 'object' on the <i style="font-weight: bold; ">front</i>&nbsp;of your inheritance hierarchy will rarely appear to work, but it will almost always cause weird issues and can easily fail later. &nbsp;Remember to put it on the end.)</div><div><br></div><div>This inspired me to write a new ticket, &lt;<a href="http://twistedmatrix.com/trac/ticket/6076">http://twistedmatrix.com/trac/ticket/6076</a>&gt;, in case anyone would at least like to prevent the type-distinction infection from becoming worse over time.</div><div><br></div><div>Good luck,</div><div><br></div><div>-glyph</div><div><br></div><div>[1]: by which I mean, of course, "almost always". &nbsp;Caveat coder.</div><div><br></div></body></html>