Skip to content

Method call on constrained typevar emits invalid-argument-type #1503

@sharkdp

Description

@sharkdp

Consider the following example. ty currently emits two errors for the t.method() call because t.method creates a union of bound method objects where C.method and D.method are bound to T@f, respectively. Instead, attribute access should properly distribute across the union C | D and yield a union of bound method objects where C.method is bound to an instance of C, and D.method is bound to an instance of D:

class C:
    def method(self) -> int:
        return 0

class D:
    def method(self) -> str:
        return ""

def f[T: (C, D)](t: T):
    # Argument to bound method `method` is incorrect: Expected `C`, found `T@f` (invalid-argument-type)
    # Argument to bound method `method` is incorrect: Expected `D`, found `T@f` (invalid-argument-type)
    reveal_type(t.method())

https://play.ty.dev/c102d2bd-de4d-497c-9144-9f45def4196a

Related: #138

Metadata

Metadata

Assignees

No one assigned

    Labels

    attribute accessInstance attributes, class attributes, etc.bugSomething isn't workinggenericsBugs or features relating to ty's generics implementation

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions