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 with generic TypeVar inheritance #12633

Closed
cdce8p opened this issue Apr 20, 2022 · 4 comments · Fixed by #12656
Closed

Regression with generic TypeVar inheritance #12633

cdce8p opened this issue Apr 20, 2022 · 4 comments · Fixed by #12656
Assignees
Labels
bug mypy got something wrong priority-0-high topic-inheritance Inheritance and incompatible overrides topic-type-variables

Comments

@cdce8p
Copy link
Collaborator

cdce8p commented Apr 20, 2022

Bug Report
Regression added with #12590. Currently also part of the v0.950 release branch.
/CC: @JukkaL

To Reproduce

from dataclasses import dataclass
from typing import Any, Callable, Generic, TypeVar


T = TypeVar("T")

@dataclass
class Parent(Generic[T]):
    f: Callable[[T], Any]

@dataclass
class Child(Parent[T]): ...


class A: ...
def func(obj: A) -> bool: ...

reveal_type(Child[A](func).f)

Expected Behavior

test.py:18: note: Revealed type is "def (test.A) -> Any"

Actual Behavior

test.py:18: note: Revealed type is "def (T`1) -> Any"
test.py:18: error: Argument 1 to "Child" has incompatible type "Callable[[A], bool]"; expected "Callable[[T], Any]"

Your Environment

  • Mypy version used: mypy 0.960+dev.50213b520b131fc1dd037dfcc1938beba1f4e177
@cdce8p cdce8p added the bug mypy got something wrong label Apr 20, 2022
@cdce8p cdce8p changed the title Regression with generic type var inheritance Regression with generic TypeVar inheritance Apr 20, 2022
@JukkaL JukkaL self-assigned this Apr 25, 2022
@hynek
Copy link
Member

hynek commented May 12, 2022

It looks like this regression also affects the attrs plugin. Would it be possible to fix it for it too, please?

@JukkaL
Copy link
Collaborator

JukkaL commented May 12, 2022

@hynek I'm working on it and should have a PR up soon.

@hynek
Copy link
Member

hynek commented May 12, 2022

Wonderful, thank you Jukka!

@Tinche
Copy link
Contributor

Tinche commented May 12, 2022

@JukkaL My hero ❤️ (no sarcasm)

JukkaL added a commit that referenced this issue May 13, 2022
Move the attrs plugin to a later pass, so that we won't have placeholders. Fix
various issues related to forward references and generic inheritance, including
some crashes.

This is follow-up to #12762 and related to #12656 and #12633.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-0-high topic-inheritance Inheritance and incompatible overrides topic-type-variables
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants