Skip to content

Reject bound covariant type variable in an argument type #734

Open
@JukkaL

Description

@JukkaL

We should reject a bound covariant type variable in an argument type (i.e., in a contravariant position). For example, this should be rejected:

T = TypeVar('T', covariant=True)
class A(Generic[T]):
    def foo(self, x: T) -> None: ...  # Can't use as argument type! Return type is okay.

Similarly, a contravariant type variable should not be used in a return type.

The actual rule is probably a bit more involved than what I gave above, but this would probably cover most cases.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions