Skip to content

Refactor imports from collections.abc, typing and typing_extensions for Python 3.9 #4353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

chopan050
Copy link
Contributor

Overview: What does this pull request change?

Refactored imports from collections.abc, typing and typing_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 for collections.abc.Callable, which is why I used the latter instead.
  • There were some imports of Any from typing_extensions when it's perfectly possible to import it from typing (unless we used Any as a base class, which we don't), so I did the latter instead.
  • Sometimes, import typing was used instead of from typing import X, Y, Z. Sometimes, both kinds of imports were present in a file at the same time, or there were multiple from typing import X, Y, Z lines in different parts of the code, so I cleaned them.
  • There was an import collections line in order to use collections.abc.Hashable and collections.abc.Iterable. In the same file, there was an import typing to use typing.Callable and other things, so I replaced the previous lines with from collections.abc import Callable, Hashable, Iterable.
  • There was an import collections line in order to use collections.defaultdict, but other files simply used from collections import defaultdict, so I used the latter for consistency.

Links to added or changed documentation pages

Further Information and Comments

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

@@ -234,7 +233,7 @@
# Serialize it with only the type of the object. You can change this to whatever string when debugging the serialization process.
return str(type(obj))

def _cleaned_iterable(self, iterable: typing.Iterable[Any]):
def _cleaned_iterable(self, iterable: Iterable[Any]):

Check notice

Code scanning / CodeQL

Explicit returns mixed with implicit (fall through) returns Note

Mixing implicit and explicit returns may indicate an error as implicit returns always return None.
@chopan050 chopan050 added the maintenance refactoring, typos, removing clutter/dead code, and other code quality improvements label Jul 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance refactoring, typos, removing clutter/dead code, and other code quality improvements
Projects
Status: 🆕 New
Development

Successfully merging this pull request may close these issues.

1 participant