Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
JukkaL opened this issue Oct 26, 2023 · 1 comment · Fixed by #16344
Closed

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

JukkaL opened this issue Oct 26, 2023 · 1 comment · Fixed by #16344
Labels
bug mypy got something wrong topic-type-variables

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Oct 26, 2023

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

@ilevkivskyi
Copy link
Member

Inner vs outer context was always a bit arbitrary, but indeed, the new behavior is inconsistent, #16344 should restore the consistency.

ilevkivskyi added a commit that referenced this issue Oct 27, 2023
Fixes #16331

Fix is straightforward: do not use the fallback, where we would not give
the error in the first place.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-type-variables
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants