Skip to content

Call expression type context should affect function argument inference #1356

Closed

Description

@ibraheemdev

Currently, the only type context we have access to when inferring function arguments is the annotated parameter type. However, the call expression annotation is also relevant, e.g.,

def id[T](x: T) -> T:
    return x

def _(i: int):
    x: list[int | None] = id([i])
    reveal_type(x)   # revealed (main): list[int | None] | list[Unknown | int] 

The problem is that we currently infer function arguments before the specializing the function call, and so the type context when inferring the list expression is still a typevar. On the other hand, we use the inferred argument types to infer the specialization, so there's a bit of a circular dependency here.

Activity

  1. added
    bidirectional inferenceInference of types that takes into account the context of a declared type or expected type
    on Oct 14, 2025
  2. ibraheemdev commented on Oct 17, 2025

    @ibraheemdev
    MemberAuthor

    Interestingly, this particular example would be resolved by #136, but something like a TypedDict annotation would not.

  3. self-assigned this
    on Oct 17, 2025
  4. added this to the Beta milestone on Oct 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions