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

TypeVar with values has incompatible type when used Self #14374

Closed
Be3y4uu-K0T opened this issue Dec 30, 2022 · 0 comments · Fixed by #14491
Closed

TypeVar with values has incompatible type when used Self #14374

Be3y4uu-K0T opened this issue Dec 30, 2022 · 0 comments · Fixed by #14491
Labels
bug mypy got something wrong

Comments

@Be3y4uu-K0T
Copy link

Bug Report

I'm not sure what's going on, better check the example. Also mypy experts, please forgive me if this is intentional behavior and not a bug.

To Reproduce

import typing

class A: pass
class B: pass

T = typing.TypeVar('T', A, B)

class C(typing.Generic[T]):

    def method_A(self, argument: T) -> None: pass

    def method_C(self, argument: T) -> typing.Self:
        self.method_A(argument)
        return self

Actual Behavior

main.py:13: error: Argument 1 to "method_A" of "C" has incompatible type "A"; expected "T"  [arg-type]
main.py:13: error: Argument 1 to "method_A" of "C" has incompatible type "B"; expected "T"  [arg-type]
Found 2 errors in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: mypy 1.0.0+dev.9183b28401bd2928d921a068bbbc7e6565e77649 (compiled: no)
  • Mypy command-line flags: none required to reproduce
  • Mypy configuration options from mypy.ini (and other config files): none required to reproduce
  • Python version used: 3.11
@Be3y4uu-K0T Be3y4uu-K0T added the bug mypy got something wrong label Dec 30, 2022
@ilevkivskyi ilevkivskyi changed the title TypeVar has incompatible type when used Self TypeVar with values has incompatible type when used Self Jan 21, 2023
JukkaL pushed a commit that referenced this issue Jan 21, 2023
…es (#14491)

Fixes #14374

It looks like we need to special-case `Self` in `expand_type()` to
support it in generics over `TypeVar` with values, since `Self` is the
only type variable that can legitimately have other type variables in
its upper bound.
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