Description
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 deprecatedtyping
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.

-
Run
import-linter
locally, fix all the imports, then open a PR for themain
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.