我想了解是否typing
仍需要该软件包?
如果在 Python 3.8 中我这样做:
from typing import Any, Dict
my_dict = Dict[str, Any]
现在通过 PEP 585 在 Python 3.9 中,现在首选将内置类型用于集合,因此:
from typing import Any
my_dict = dict[str, Any]
我还需要使用typing.Any
还是有一个我找不到的内置类型来替换它?
我想了解是否typing
仍需要该软件包?
如果在 Python 3.8 中我这样做:
from typing import Any, Dict
my_dict = Dict[str, Any]
现在通过 PEP 585 在 Python 3.9 中,现在首选将内置类型用于集合,因此:
from typing import Any
my_dict = dict[str, Any]
我还需要使用typing.Any
还是有一个我找不到的内置类型来替换它?
的使用Any
保持不变。PEP 585仅适用于标准集合。
typing
此 PEP 提议在模块中当前可用的所有标准集合中启用对泛型语法的支持。
从 Python 开始3.9
,以下集合成为generic
并且不推荐从中导入这些集合typing
: