Reputation: 656
In the following example
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
I want to do something like B.__init__(self, a:A)
so that the argument in class B is an object of A.
Upvotes: 1
Views: 1170
Reputation: 595
You can always raise 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
Upvotes: 1