Skip to content

Check type variable bounds of self types #2351

Open
@JukkaL

Description

@JukkaL

As follow-up to #2193, check that if self is declared with a type variable type, the type variable has a compatible bound. For example, some of these should be rejected:

T = TypeVar('T')
TA = TypeVar('TA', bound='A')
TC = TypeVar('TC', bound='C')

class A:
    def f(self: T) -> T: ...  # Should be error
    def g(self: TC) -> TC: ...  # Should be error
    def h(self: TA) -> TA: ...  # OK

class C: pass

(We may also want to check variance, but it's a separate issue and less clear.)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions