You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromtypingimportCollection, Union, Listdeffoo(bar: Union[bool, Collection[int]]) ->Union[int, List[int]]:
ifbarisFalse: # or if not bar:return10ifbarisTrue:
return20# otherwise, bar must be a collection (list, tuple, ...)return [i*2foriinbar]
print(foo(True))
print(foo(False))
print(foo([1, 2, 3]))
print(foo((1, 2, 3,)))
Mypy is giving the error
error: Item "bool" of "Union[bool, Collection[int]]" has no attribute "__iter__" (not iterable)
But it should be able to infer that it can't be a bool?
using if / elif /else also gives the error.
ruohola, cdce8p, MetRonnie, he7d3r, eddiebergman and 4 more