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

前端 未结 10 1879
长情又很酷
长情又很酷 2020-11-29 15:43

In Java, for example, the @Override annotation not only provides compile-time checking of an override but makes for excellent self-documenting code.

I\

10条回答
  •  生来不讨喜
    2020-11-29 16:34

    Hear is simplest and working under Jython with Java classes:

    class MyClass(SomeJavaClass):
         def __init__(self):
             setattr(self, "name_of_method_to_override", __method_override__)
    
         def __method_override__(self, some_args):
             some_thing_to_do()
    

提交回复
热议问题