假设我有一个函数,接受一个Garthok
、一个Iterable[Garthok]
、一个Iterable[Iterable[Garthok]]
等。
def narfle_the_garthoks(arg):
if isinstance(arg, Iterable):
for value in arg:
narfle_the_garthoks(arg)
else:
arg.narfle()
有没有一种方法可以指定参数的类型提示,表明它接受任何级别的Garthok
的Iterable
?我怀疑没有,但是想检查一下是否遗漏了什么。
作为解决方法,我只是指定了几个深度级别,然后以 Iterable[Any]
结束。
Union[Garthok,
Iterable[Union[Garthok,
Iterable[Union[Garthok,
Iterable[Union[Garthok, Iterable[Any]]]]]]]]