Skip to content

[BUG] Calling a method on a TypeVar fails #150

Open
0 of 2 issues completed
Open
Bug
0 of 2 issues completed
@hmansell

Description

@hmansell

In this example, mypy succeeds, but pyrefly fails.

https://mypy-play.net/?mypy=latest&python=3.12&gist=5f8fe155f983bdb6950f422aee9cd612 has two examples of calling a method a TypeVar that returns Self.

  1. In the case of a TypeVar that lists a union of types, pyrefly doesn't like us calling f() on the variable of type T
  2. In the case of a bounded TypeVar, it seems pyrefly says "Returned type B is not assignable to declared return type TypeVar[TBounded]". It seems to be incorrectly inferring that the Self that f() returns is of type B rather than of the type TBounded.

Pyrefly URL:
https://pyrefly.org/sandbox/?code=GYJw9gtgBALgngBwJYDsDmUkQWEMoBUAUEQMYA2AhgM7VQBCAFAJQBcRUnUAJgKbBRgjar3LBmUALQA+KAGVRwdlxVQQvGAFcQKKCLEdVnMlVpQAwo3ptDnBDWomHUACJWbK+7RJEAKlABeKF9EXgA1ShBGWygAIl9YgBoY82SVF2TmEj4BNGiVACNWYMypWV9lLnUtHSgCgDohLL96ME0UPm5A4NCIqJj41vbOpJiCto6A+iJmnKg8seLfIY7eblKZYJXOys5q7V0GpqIgA

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    UserBugs reported by external users that should be prioritised

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions