python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.54k stars 2.84k forks source link

Support infer_variance= parameter for TypeVar (PEP 695) #17811

Open JukkaL opened 2 months ago

JukkaL commented 2 months ago

Feature

See this section of PEP for details.

Pitch

This is probably the most significant omission from full PEP 695 support (though this mostly impacts users of older Python versions).

jonaslb commented 3 weeks ago

this mostly impacts users of older Python versions

Is there a reason that this is expected to be mostly relevant for users of older Python versions? It seems to me to be a very useful addition when implemented. Variance almost always needs to be specified according to the inference rules anyway (and you might need both _co and _contra variants of a type variable instead of only one).

JelleZijlstra commented 3 weeks ago

@jonaslb because in Python 3.12 and newer, you can use the native generic syntax, which always implicitly infers variance.