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

mypy doesn't escape typevars from generics in self-type #18400

Open
A5rocks opened this issue Jan 1, 2025 · 1 comment · May be fixed by #18401
Open

mypy doesn't escape typevars from generics in self-type #18400

A5rocks opened this issue Jan 1, 2025 · 1 comment · May be fixed by #18401
Labels
bug mypy got something wrong

Comments

@A5rocks
Copy link
Contributor

A5rocks commented Jan 1, 2025

Bug Report

Passing a callable to another which matches the typevar with another typevar doesn't allow passing them into the return type. (if that makes no sense, the reproducer below is simple)

To Reproduce

from typing import Generic, TypeVar, Callable

T = TypeVar("T")
V = TypeVar("V")

class X(Generic[T]):
    def f(self: X[Callable[[V], None]]) -> Callable[[V], V]:
        def inner_f(v: V) -> V:
            return v

        return inner_f

reveal_type(X[Callable[[T], None]]().f())  # N: Revealed type is "def (Never) -> Never"
# ^ this should keep the generic

Expected Behavior

I don't expect a Never.

Your Environment

Checked on mypy playground.

  • Mypy version used: v1.14
  • Mypy command-line flags: --strict
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.12
@A5rocks A5rocks added the bug mypy got something wrong label Jan 1, 2025
@A5rocks A5rocks changed the title mypy doesn't escaped stored typevartuples in a self-type mypy doesn't escape stored typevartuples in a self-type Jan 1, 2025
@A5rocks
Copy link
Contributor Author

A5rocks commented Jan 1, 2025

Turns out this applies to TypeVars too -- I'll update this issue for that (since it's simpler).

@A5rocks A5rocks changed the title mypy doesn't escape stored typevartuples in a self-type mypy doesn't escape stored typevars in a self-type Jan 1, 2025
@A5rocks A5rocks changed the title mypy doesn't escape stored typevars in a self-type mypy doesn't escape typevars from a passed in function Jan 1, 2025
@A5rocks A5rocks changed the title mypy doesn't escape typevars from a passed in function mypy doesn't escape typevars that partially match Jan 1, 2025
@A5rocks A5rocks changed the title mypy doesn't escape typevars that partially match mypy doesn't escape typevars from generics in self-type Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant