Python 键入弃用
Python typing deprecation
最新的 typing docs 有很多弃用通知,如下所示:
class typing.Deque(deque, MutableSequence[T])
A generic version of collections.deque.
New in version 3.5.4.
New in version 3.6.1.
Deprecated since version 3.9: collections.deque now supports []. See PEP 585 and Generic Alias Type.
这是什么意思?我们是否应该不再使用泛型类型 Deque
(以及其他几个)?我查看了参考资料,但没有把这些点联系起来(可能是因为我是中级 Python 用户)。
见PEP585 and Generic Alias Type。
Python 3.9 中的更改消除了 typing
模块中并行类型层次结构的必要性,因此您可以在注释类似双端队列的类型时直接使用 collections.deque
。
意思是
def foo(d: typing.Deque):
...
应改为:
def foo(d: collections.deque):
...
这意味着您应该过渡到使用标准库中的内置类型/类型,而不是 typing
提供的类型。因此,例如 collections.deque[int]
而不是 typing.Deque[int]
。 list
、tuple
等也是如此。所以tuple[int, str]
是首选方式。
最新的 typing docs 有很多弃用通知,如下所示:
class typing.Deque(deque, MutableSequence[T])
A generic version of collections.deque.
New in version 3.5.4.
New in version 3.6.1.
Deprecated since version 3.9: collections.deque now supports []. See PEP 585 and Generic Alias Type.
这是什么意思?我们是否应该不再使用泛型类型 Deque
(以及其他几个)?我查看了参考资料,但没有把这些点联系起来(可能是因为我是中级 Python 用户)。
见PEP585 and Generic Alias Type。
Python 3.9 中的更改消除了 typing
模块中并行类型层次结构的必要性,因此您可以在注释类似双端队列的类型时直接使用 collections.deque
。
意思是
def foo(d: typing.Deque):
...
应改为:
def foo(d: collections.deque):
...
这意味着您应该过渡到使用标准库中的内置类型/类型,而不是 typing
提供的类型。因此,例如 collections.deque[int]
而不是 typing.Deque[int]
。 list
、tuple
等也是如此。所以tuple[int, str]
是首选方式。