Skip to content
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

Import rewrite issue with TypedDict #683

Closed
cdce8p opened this issue Jul 18, 2022 · 3 comments
Closed

Import rewrite issue with TypedDict #683

cdce8p opened this issue Jul 18, 2022 · 3 comments

Comments

@cdce8p
Copy link

cdce8p commented Jul 18, 2022

In Python 3.11 TypedDict can inherit from Generic which hasn't been possible so far. To use it in prior versions, TypedDict can be imported from typing_extensions. I believe it would make sense to postpone import rewriting for it until 3.11.

Example from the Python docs

from typing import Generic, TypeVar
from typing_extensions import TypedDict

T = TypeVar("T")

class Group(TypedDict, Generic[T]):
    key: T
    group: list[T]

After pyupgrade --py38-plus

from typing import Generic, TypeVar
from typing import TypedDict
...

--
Besides TypedDict, NamedTuple will also be able to inherit from Generic in 3.11 or can be imported from typing_extensions. This isn't an issue yet though, since pyupgrade doesn't rewrite it.

from typing import Generic, TypeVar
from typing_extensions import NamedTuple

T = TypeVar("T")

class Group(NamedTuple, Generic[T]):
    key: T
    group: list[T]
@asottile
Copy link
Owner

makes sense -- want to send a PR to the generator in reorder-python-imports? (where this data is sourced from)

@cdce8p
Copy link
Author

cdce8p commented Jul 18, 2022

makes sense -- want to send a PR to the generator in reorder-python-imports? (where this data is sourced from)

Opened asottile/reorder-python-imports#289

@asottile
Copy link
Owner

via #684

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants