Skip to content

[red-knot] Distinguish static-member lookup with and without instance variables #16367

@sharkdp

Description

@sharkdp

Summary

We currently distinguish between Type::member (with descriptor protocol) and Type::static_member (without descriptor protocol). The former corresponds to obj.attr, the latter corresponds to getattr_static(obj, "attr"). However, to model some details in the descriptor protocl correctly, we would also need to distinguish between a static member lookup with and without instance variables. The lookup without instance variables corresponds to find_name_in_mro here. We currently approximate both using member_static.

One example where this leads to incorrect behavior is the following example:

def some_function(x: int) -> str:
    return "a"

class C:
    def __init__(self):
        self.function = some_function


c = C()
c.function(1)  # We currently emit errors here because `function` is treated as a bound method

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingtyMulti-file analysis & type inference

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions