I'm having a module-structure in python3.8 like this:
module
|- __init__.py
|- foo.py
|- bar.py
with
# init.py
from .foo import Foo
from .bar import Bar
__all__ = ['Foo', 'Bar', ]
I now want to implement a multiplication foo * bar. So I'm writing:
# foo.py
from .bar import Bar
class Foo:
def __init__(self):
self.value = 5
def __mul__(self, other):
if not isinstance(other, Bar): raise ValueError('')
return self.value * other.number
and
# bar.py
from .foo import Foo
class Bar:
def __init__(self):
self.number = 2
def __mul__(self, other):
if not isinstance(other, Foo): raise ValueError('')
return other * self
This unfortunately doesn't work as expected. Is there a way for type-checking in this case? I know I could import Foo inside of Bar.__mul__ – but that seems rather untidy to me.