Skip to content

[Feature Request] TypeVar variance definition alias #813

Description

@jorenham

Defining the two variances of a TypeVar is rather verbose:

T_co = TypeVar("T_co", covariant=True)
T_contra = TypeVar("T_contra", contravariant=True)

So I propose an alternative syntax, similar to that of Scala's variances:

T_co = +TypeVar("T_co")
T_contra = -TypeVar("T_contra")

Co- and contra-variance describe increasing and decreasing specificities of the typevars, respectively. So using + and - to symbolize these "directions" makes intuitive sense.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: featureDiscussions about new features for Python's type annotations

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions