Skip to content

Extend full-scope bidirectional context collection to function calls? #4145

Description

@sharkdp

The following is currently an error:

def accepts_list_of_objects(xs: list[object]): ...

def f():
    xs = ["foo"]
    accepts_list_of_objects(xs)  # Expected `list[object]`, found `list[str]`

This is because we currently only collect bidirectional context from a restricted set of syntactical constructs like method calls, for performance reasons.

After some recent performance improvements, it might be worth exploring this again. @ibraheemdev suggested that we might potentially want to exclude some builtins that are known to contribute no constraints. For example, len(xs) calls are frequent (and known to cause problems in previous attempts), but do not provide any context for the element type of xs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bidirectional inferenceInference of types that takes into account the context of a declared type or expected type

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions