Reputation: 24618
The latest typing docs has a lot of deprecation notices like the following:
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.
What does this means? Should we not use the generic type Deque
(and several others) anymore? I've looked at the references and didn't connect the dots (could be because I'm an intermediate Python user).
Upvotes: 9
Views: 9651
Reputation: 363405
See PEP585 and Generic Alias Type.
Changes in Python 3.9 remove the necessity for a parallel type hierarchy in the typing
module, so that you can just use collections.deque
directly when annotating a deque-like type.
For example, it means that annotating a deque of ints like
def foo(d: typing.Deque[int]):
...
Should be changed to:
def foo(d: collections.deque[int]):
...
Upvotes: 5
Reputation: 36329
It means that you should be transitioning to using built-in types / types from the standard library instead of the ones provided by typing
. So for example collections.deque[int]
instead of typing.Deque[int]
. The same for list
, tuple
, etc. So tuple[int, str]
is the preferred way.
Upvotes: 16