Python type hint for Sized, Iterable and Container

Viewed 713

What type hint should I use in Python 3 to describe an argument that I will use in these 3 ways:

  • if len(arg): ...
  • for item in arg: ...
  • if item in arg: ...
1 Answers

You may use collections.abc.Collection

from collections.abc import Collection

def fn(arg: Collection[int]):
    pass
Related