是否可以将 dictview 对象指定为 Python 中的键入提示?
Is it possible to specify dictview object as the typing hint in Python?
我不确定 documentation 是否包含有关视图对象类型的任何具体信息。我无法找到它(即字典源代码中的 <class 'dict_values'>
。有没有办法明确指定此 'view class'?首先它有意义吗?示例:
def func1(arg: dictview) -> None:
pass
您正在寻找 typing.MappingView
类型提示或其任何相关类型,例如 KeysView
、ItemsView
、ValuesView
.
typing.MappingView
现已在 python 3.9 中弃用,您可以使用 collections.abc.MappingView
collections.abc.MappingView
collections.abc.ItemsView
collections.abc.KeysView
collections.abc.ValuesView
我不确定 documentation 是否包含有关视图对象类型的任何具体信息。我无法找到它(即字典源代码中的 <class 'dict_values'>
。有没有办法明确指定此 'view class'?首先它有意义吗?示例:
def func1(arg: dictview) -> None:
pass
您正在寻找 typing.MappingView
类型提示或其任何相关类型,例如 KeysView
、ItemsView
、ValuesView
.
typing.MappingView
现已在 python 3.9 中弃用,您可以使用 collections.abc.MappingView
collections.abc.MappingView
collections.abc.ItemsView
collections.abc.KeysView
collections.abc.ValuesView