Skip to content

False positive on calling parametrized bound method (and bad reveal_type) #2334

@randolf-scholz

Description

@randolf-scholz

Describe the Bug

calling parent[T].__init__(self) manually with the correct parameter can be necessary with multiple inheritance, but pyrefly errors here:

from typing import reveal_type

class Foo[T]:
    def __init__(self, /) -> None:
        pass

class Bar[S](Foo[S]):
    def __init__(self, /) -> None:
        reveal_type(Foo.__init__)       # E: [T](Foo[T]) -> None  ✅️
        reveal_type(Foo[S].__init__)    # E: (Foo[S@Bar]) -> None ❌️
        reveal_type(Foo[int].__init__)  # E: (Foo[int]) -> None ❌️
        Foo[S].__init__(self)  # ❌️
INFO sandbox.py:9:20-34: revealed type: [T](self: Foo[T], /) -> None [reveal-type]
INFO sandbox.py:10:20-37: revealed type: BoundMethod[GenericAlias, (self: GenericAlias) -> None] [reveal-type]
INFO sandbox.py:11:20-39: revealed type: BoundMethod[GenericAlias, (self: GenericAlias) -> None] [reveal-type]
ERROR sandbox.py:12:25-29: Expected 0 positional arguments, got 1 in function `object.__init__` [bad-argument-count]

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEALqcROgOZ0Q3G6UN2UYANxiooAfSbEYAHXRyAxlFRw4dAGK5cAbQAqAXURy6Juphhg648awgNrACjgwoYADR0A9AEo6AWgA%2BOgA5XHQYI3RTaLpiFTg5RWVVOgAhVEptAGV9B00dHO9I6PNLa1t7cScXdy9fQJCwiOMYk0ERMUlmGDytQnL0O2tfVoBiOgBRRDo9XPzZ%2BqDQ8JNAUHJAeD%2BW1vbRCSke%2BZz%2Bm0HKkZNxqbpegoABdMp9RcaVwBlyTajWgWFdrukb7SsBj6Y4VYYXSbTAFAp7%2BJZNOjvLYxQ4ggZDKrOVwjcZI9AgNwgACuDGgcBI5EQIHGAFVSVA7KQ6GAiegFKSwgl5FgLMzeDRUPZ0ESaNgYJQHPhpkDnnAGJRiqZBAwiZQomAZCBgiKxQq6MB8ABfTVyAkgMiCMBQUiEBi0KAUcYABVIlutdDQWDw%2BDoCjCkDYqsFEDChDk4yyMBgdAAFgwGMQ4IhPJ4LRZrYReGxPDB0J5MLgFHBPH70AGgxy83zKHRUEJUNBUNhYL7-RBA5Rg2E6LhiJXyXIyAwY2E-CJKHAQ1EALx0TUAZkIAEYAEwm-GGwmodkQETqaAwCienAECkgQ1AA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions