<p dir="ltr">It could also be useful to have @override decorator functionality in zope.interface</p>
<p dir="ltr"><a href="http://zopeinterface.readthedocs.io/en/latest/verify.html">http://zopeinterface.readthedocs.io/en/latest/verify.html</a></p>
<p dir="ltr">zope.interface supports interface verification at test and runtime.</p>
<p dir="ltr">AAIU,  @override would raise an Exception:<br>
- a) when a subclass specifies @override for a method not defined in a superclass<br>
- b) when the argspecs are different</p>
<p dir="ltr">AFAIU, a)-like functionality does not yet exist in zope.interface</p>
<div class="gmail_extra"><br><div class="gmail_quote">On Jul 18, 2016 1:45 PM, "Shrey Desai" <<a href="mailto:shreydesai@me.com">shreydesai@me.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Python Ideas,<div><br></div><div>While working on some object-oriented projects in Java, I noticed that Python does not have an <b>@override</b> decorator for methods that are derived from a parent class but overridden for the unique purposes of a base class. With the creation of the <b>@abstractmethod</b> decorator, the override decorator could follow in clearly distinguishing the logic and design between parent/base classes.</div><div><br></div><div>Why I would think an override decorator might be useful:</div><div><ol><li>For other people reading the code, it would be great to distinguish between methods that are unique to a class and methods that are inherited from a parent class. Not all methods inherited might be overridden, so keeping track of which inherited methods are overridden and which are not would be nice.</li><li>With the advent of static typing from mypy:</li><ol><li>Having the decorator could corroborate the fact that the given method overrides the parent method correctly (correct name + parameter list).</li><li>When the parent class changes, such as the name or parameter list of an abstract method, the children classes should be updated as well. mypy could easily target the methods that need to be altered with the correct method signature.</li><li>If you don’t have an override decorator and overrode a parent method, then there could be some error complaining about this. This would be extremely useful to prevent accidental errors.</li></ol></ol><div><br></div></div><div>There is some interest for this as expressed on Stack Overflow (<a href="http://stackoverflow.com/questions/1167617/in-python-how-do-i-indicate-im-overriding-a-method" target="_blank">http://stackoverflow.com/questions/1167617/in-python-how-do-i-indicate-im-overriding-a-method</a>) and some people have also made packages for this, but having it in the standard distribution would be nice. Thoughts?</div><div><br></div><div>Sincerely,</div><div>Shrey Desai</div><div><a href="https://github.com/shreydesai" target="_blank">https://github.com/shreydesai</a></div></div><br>_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br></blockquote></div></div>