I want to be able to pass an instance of Foo
to another instance of Foo
.
My below code doesn't work for two reasons:
I need to use
Foo
inMyTypes
beforeFoo
is known. I get a NameError that Foo is not knownIn my check
isinstance(values,Foo)
my instance ofFoo
is not recognized and I get my TypeError "Type not supported".
Can someone explain me how I can fix this?
Thanks!
MyTypes = (list,np.ndarray, Foo)
class Foo():
def __init__(self,values:MyTypes) -> None:
self.values = self._unpack_values(values)
def _unpack_values(self,values):
if not isinstance(values,MyTypes):
raise TypeError("Type not supported")
else:
if isinstance(values, list):
return "list"
elif isinstance(values, Foo):
return "Foo"
elif isinstance(values, np.ndarray):
return "np.ndarray"
else:
return ValueError("Something went wrong")
f = Foo(values=Foo(values=[1,2,3]))