In the documentation
exception NotImplementedError This exception is derived from RuntimeError. If you want a user-defined base class to require an abstract method to be overridden in a derived class, you must throw this exception.
is what it reads. For the time being, it seems that you should use it if you absolutely want to override.
# -*- coding: utf-8 -*-
class BaseTest(object):
def hogehoge(self):
raise NotImplementedError()
class Test(BaseTest):
def hogehoge(self):
print "hogehoge"
class Test2(BaseTest):
pass
if __name__ == "__main__":
test = Test()
test.hogehoge()
test2 = Test2()
test2.hogehoge()
Output result
hogehoge
Traceback (most recent call last):
File "test.py", line 22, in <module>
test2.hogehoge()
File "test.py", line 5, in hogehoge
raise NotImplementedError()
NotImplementedError
Recommended Posts