inheritance - In Python, how do I indicate I'm overriding a method? -


For example, in Java, override annotation provides not only override compilation-time checks, but also makes excellent ones for themselves -

Update (23.05.2015): Based on this and FW: Answer I have a PEP An installable package is created

From time to time, I am looking into this question. After looking at the same bug mainly in our code base (again) this happens: When changing the name of a method in the "interface" forgot the class implementing an "interface".

< P> Well, Python is not Java, but Python has power - better than clear and inherent - and there are real solid cases in the real world where this thing will help me.

So here's a sketch of an override decorator.

If you can think of a better solution, then post it here

ex> def overrides (interface_clauses): def overrides (Method): emphasis (dir (interface_class) in method______ return method return overrider

This works as follows:

  class MySuperInterface (Object): def my_method (self): print 'hello world!' The square concrete supplement (MySuperInterface): @ Override (MySuperInterface) def my_method (self): Print 'Hello Kitty!'  

And if you make a faulty version, this will increase an assertion error during class loading:

  class: MySuperInterface: @override (MySuperInterface) ) Def Your_method (self): Print 'Bye Bye Bye!' & Gt; & Gt; AssertionError !!!!!!!  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -