Skip to content

Remove imports from deprecated typing modules #1326

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
dlqqq opened this issue Apr 17, 2025 · 1 comment · May be fixed by #1329
Open

Remove imports from deprecated typing modules #1326

dlqqq opened this issue Apr 17, 2025 · 1 comment · May be fixed by #1329
Labels
good first issue Good for newcomers maintenance Change related to maintenance of the repository

Comments

@dlqqq
Copy link
Member

dlqqq commented Apr 17, 2025

Description

PEP 585 makes a lot of built-in types in the Python standard library generic as of Python 3.9. This deprecates a lot of imports from the typing module, since we don't need to import those types anymore to use generic types.

For example, this code was typed using the typing module:

from typing import List
def get_list() -> List[str]:
  return []

However, this is no longer necessary, since the built-in list type can be used as a generic type annotation now:

# look ma, no imports!
def get_list() -> list[str]:
  return []

Proposed solution

  • Add import-linter back to the CI workflows. This was removed in a previous PR, but here's the original one that added it: https://github.com/jupyterlab/jupyter-ai/pull/546/files

  • Add import-linter rules that forbid importing from the deprecated typing modules listed in PEP 585. Those are in the implementation section following the # symbols.

More details (click to expand)

For example, the tool should forbid imports like from typing import List and recommend that list just be used as a type directly.

Here's an image that refers to what I wrote above. Note how the recommended new type is shown first, and then the deprecated typing module follows the # symbol on each line.

Image
  • Run import-linter locally, fix all the imports, then open a PR for the main branch.

  • Do the same for the 2.x branch. Normally the bot can be used to backport changes (@meeseeksdev please backport to 2.x), but there will likely be too many merge conflicts. I recommend just creating a separate branch and re-doing the steps here.

Context

From the PEP:

The deprecated functionality may eventually be removed from the typing module. Removal will occur no sooner than Python 3.9’s end of life, scheduled for October 2025.

@dlqqq dlqqq added the maintenance Change related to maintenance of the repository label Apr 17, 2025
@dlqqq dlqqq changed the title Remove deprecated imports from typing module Remove imports from deprecated typing modules Apr 17, 2025
@dlqqq dlqqq added the good first issue Good for newcomers label Apr 17, 2025
@dlqqq
Copy link
Member Author

dlqqq commented Apr 17, 2025

The PR should also include a full list of all deprecated typing modules & their replacements. That will allow reviewers to verify this against PEP 585.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers maintenance Change related to maintenance of the repository
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant