Python Sized、Iterable 和 Container 的类型提示
Python type hint for Sized, Iterable and Container
我应该在 Python 3 中使用什么类型的提示来描述我将以这 3 种方式使用的论点:
if len(arg):
...
for item in arg:
...
if item in arg:
...
您可以使用collections.abc.Collection
from collections.abc import Collection
def fn(arg: Collection[int]):
pass
我应该在 Python 3 中使用什么类型的提示来描述我将以这 3 种方式使用的论点:
if len(arg):
...for item in arg:
...if item in arg:
...
您可以使用collections.abc.Collection
from collections.abc import Collection
def fn(arg: Collection[int]):
pass