Skip to content

TypeVar for self breaks super #11678

Closed
Closed
@esoma

Description

@esoma
from typing import TypeVar

T = TypeVar('T')

class X:
    def __init__(self: T):
        super().__init__() # error: Argument 2 for "super" not an instance of argument 1

Possibly related to python/typing#909? But it seems the actual super call is handled specially so, possibly not?

It would seem to me if self is a TypeVar we can safely say that it must be compatible with super's arg 2...which seems like a simple fix. If T is bound to an incompatible type we'll get errors elsewhere to cover that situation (error: The erased type of self "__main__.A" is not a supertype of its class "__main__.X").

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions