Skip to content

Conversation

@Vaishnavi-Iyer67
Copy link

Problem

Mypy fails to infer the type of a variable assigned via a named expression (:=)
when that variable is referenced in another keyword argument of the same call.

Although Python guarantees left-to-right evaluation order for function arguments,
mypy currently type-checks keyword arguments independently, leading to a false
positive has-type error.

Minimal example

def f(notifications: str, initial_reference: str) -> int:
    return 42

f(
    initial_reference=(request_reference := "abc"),
    notifications=request_reference,  # error: Cannot determine type
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants