0

I'm creating an interface Mixins that contains methods that will throw error if it is not implemented, however it only happens during run time when the method is called, i would like to have python check if method is implemented before run time.

class TestInterface():
    def get_testing_name(self):
        raise NotImplementedError

    def do_something(self):
        return self.get_testing_name()


class Testing(TestInterface):
    def __init__(self):
        super().do_something()

In my Testing class, i didn't defined get_testing_name method, hence it will raise NotImplementedError. However this will only happen on run time

How do i make sure python check if method is not implemented before run time?

nicker
  • 477
  • 2
  • 6
  • 20
  • 1
    this may be related: https://stackoverflow.com/questions/44576167/force-child-class-to-override-parents-methods/44576235#44576235 – hiro protagonist Mar 27 '19 at 07:05
  • If it is before runtime, then probably it should be done by the IDE? In such a case, most of the IDE could inspect whether an abstract method is implemented. – M Ciel Aug 16 '22 at 03:22

1 Answers1

0

I don't know if I understood you. Maybe that was what you wanted ?:

try:
    t = Testing()
except NotImplementedError:
    print("Fail")
Mikey
  • 400
  • 4
  • 11