В следующем примере
class A():
def __init__(self):
self.foo = 'foo'
class B():
def __init__(self, a):
self.a = a
a = A()
B(a) # right
B('a') # wrong
Я хочу сделать что-то вроде B.__init__(self, a:A)
чтобы аргумент в классе B был объектом A.
Вы всегда можете поднять ValueError
:
class B():
def __init__(self, a: A):
if not isinstance(a, A):
raise ValueError("a must an object of class A")
self.a = a