I'm trying to check if an object has a method start
and a method update
.
I thought I could use abstract base class, just like collections.abc.Iterable
work.
In my case I cannot do class Foo(Interface)
since Foo
is load dynamically, and have no access to Interface
.
What is the idiomatic way to check if an object have specific methods ?
import abc
class Interface(abc.ABC):
@abc.abstractmethod
def start():
pass
@abc.abstractmethod
def update():
pass
class Foo:
def start():
pass
def update():
pass
def main():
foo = Foo()
print(f'{isinstance(foo, Interface) = }') # False
if __name__ == '__main__':
main()