I have a method that takes a collection which I need to iterate and call “len”. In practice, I pass both List and Set to it. My method looks like:
def my_method(events: Any):
if len(events) > TOO_BIG_TO_ITERATE:
# Some code...
else:
for event in events:
# More code
What can I use instead of Any
to correctly anotate that variable? Of course I cannot use List[Event]
nor Set[Event]
(as I want to use both). Sized
does not allow iteration and Iterable
does not allow len()
.
Is there anything better than Union[Set[Event], List[Event]]
?