Problem Description
TypeVars seem to be simply put through repr to get their textual format. TypeVar's __repr__ is missing important information necessary to the use of the class including constraints or bounds and covariance or contravariance.
Proposal
I would like to see TypeVars printed with a more information. For example, instead of just ~T, it could be {variance} T ≤ {bound}. The variance of a type only needs to be know once per type (likely at the occurrence of the TypeVar in the class definition) as TypeVars in functions/methods cannot have variance. Bounds should likely be printed on every occurrence of the TypeVar. Constraints could be represented as a tuple of bounds.
Alternatives
- Stating the bound and variance in the docstring. Docstrings can get out of date, but mypy ensures that annotations remain correct.
- Taking sphinx's approach and adding support for documenting the TypeVar (yuck!).
Problem Description
TypeVars seem to be simply put through
reprto get their textual format. TypeVar's__repr__is missing important information necessary to the use of the class including constraints or bounds and covariance or contravariance.Proposal
I would like to see TypeVars printed with a more information. For example, instead of just
~T, it could be{variance} T ≤ {bound}. The variance of a type only needs to be know once per type (likely at the occurrence of the TypeVar in the class definition) as TypeVars in functions/methods cannot have variance. Bounds should likely be printed on every occurrence of the TypeVar. Constraints could be represented as a tuple of bounds.Alternatives