Refactor imports from collections.abc
, typing
and typing_extensions
for Python 3.9
#4353
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview: What does this pull request change?
Refactored imports from
collections.abc
,typing
andtyping_extensions
. This PR is valid as long as we support Python 3.9. Changes might need to be done in the future after dropping support for that version.Motivation and Explanation: Why and how do your changes improve the library?
typing.Callable
is a deprecated alias forcollections.abc.Callable
, which is why I used the latter instead.Any
fromtyping_extensions
when it's perfectly possible to import it fromtyping
(unless we usedAny
as a base class, which we don't), so I did the latter instead.import typing
was used instead offrom typing import X, Y, Z
. Sometimes, both kinds of imports were present in a file at the same time, or there were multiplefrom typing import X, Y, Z
lines in different parts of the code, so I cleaned them.import collections
line in order to usecollections.abc.Hashable
andcollections.abc.Iterable
. In the same file, there was animport typing
to usetyping.Callable
and other things, so I replaced the previous lines withfrom collections.abc import Callable, Hashable, Iterable
.import collections
line in order to usecollections.defaultdict
, but other files simply usedfrom collections import defaultdict
, so I used the latter for consistency.Links to added or changed documentation pages
Further Information and Comments
Reviewer Checklist