asottile / pyupgrade

A tool (and pre-commit hook) to automatically upgrade syntax for newer versions of the language.
MIT License
3.5k stars 177 forks source link

Python 3.12 Generics #914

Closed jack-tutor closed 10 months ago

jack-tutor commented 10 months ago

I really appreciate this tool - it's very useful.

I was wondering whether there is a plan to support conversion to the new (much cleaner) generic typing syntax in 3.12: https://docs.python.org/3/whatsnew/3.12.html#pep-695-type-parameter-syntax.

I could imagine this being very complex (one potential issue would be handling TypeVars used in a generic in one function but imported from another file) especially while maintaining correctness. But I was curious if this has been considered/if there is a concrete plan to support this eventually or a decision that it is beyond the scope of pyupgrade.

Thanks

asottile commented 10 months ago

please spend a few minutes and search the issue tracker next time

jack-tutor commented 10 months ago

I looked at the issue tracker prior to posting this and have since looked.

Searching for the terms of type generic 3.12 695 parameter and looking at all open issues - this is the closest issue I can find: https://github.com/asottile/pyupgrade/issues/836

It's entirely possible I am still missing this - but short of looking through all the closed issues in the repo - I'm not sure how to find the answer here. If nothing else - linking to the answer here would help someone else who might use the same search terms as me.

asottile commented 10 months ago

why not 695 ?

asottile commented 10 months ago

ah you did find the duplicate -- great! next time do that first so you don't even need to waste both of our time opening an issue about it

jack-tutor commented 10 months ago

Are you saying that the issue I am raising here is a duplicate of https://github.com/asottile/pyupgrade/issues/836? That issue is about the new type alias syntax - I am talking about generics (there is overlap, but not complete).

As in this:

def max[T](args: Iterable[T]) -> T:
    ...

class list[T]:
    def __getitem__(self, index: int, /) -> T:
        ...

    def append(self, element: T) -> None:
        ...

This seems to me a distinct concern and feature from what is discussed in 836

asottile commented 10 months ago

yes it is an exact duplicate