Skip to content

TypeVar with values has incompatible type when used Self #14374

@Be3y4uu-K0T

Description

@Be3y4uu-K0T

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions