python / typeshed

Collection of library stubs for Python, with static types
Other
4.29k stars 1.73k forks source link

PEP 695 (Type Parameter Syntax) tracker - Generics #10869

Open srittau opened 11 months ago

srittau commented 11 months ago

This issue is supposed to track when we can start to use the improved generics syntax introduced in Python 3.12 (PEP 695 in typeshed. Support is needed in released versions of:

As this is a syntax change, it's unlikely that we can add support before mypy drops support for running under Python 3.11 and below.

Example from the PEP:

class ClassA[T: str]:
    def method1(self) -> T:
        ...

def func[T](a: T, b: T) -> T:
    ...
Akuli commented 11 months ago

I think we can never fully switch to the new syntax, because sometimes we need to choose a variance that type checkers disagree with, as in #8781.

AlexWaygood commented 11 months ago

I think we can never fully switch to the new syntax, because sometimes we need to choose a variance that type checkers disagree with, as in #8781.

That will be quite rare, though; we can aspire to use the new syntax nearly all of the time

srittau commented 11 months ago

We also occasionally have public type vars, but I agree with Alex that we should at least aspire to use the new syntax. (In five years or so.)