Skip to content

Regression: inferred type too wide when using type variable bound #16331

@JukkaL

Description

@JukkaL

The type revealed when type checking the above fragment changed as a side effect of #16184, and this looks like a regression:

from typing import TypeVar

T = TypeVar("T", bound="Base")

class Base:
    def __abs__(self: T) -> T:
        return type(self)()

class C(Base):
    pass

def f(values: list[T]) -> T:
    return values[0]

def g() -> None:
    x = abs(f([C()]))
    reveal_type(x)  # "Base", but expected "C"   <<------

cc @ilevkivskyi

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions