Skip to content

False negative involving overload and walrus #22264

Open

Description

@hauntsaninja
from typing import overload

@overload
def first(a: int, b: int) -> int: ...
@overload
def first(a: str, b: int) -> str: ...
def first(a: int | str, b: int) -> int | str:
    return a

def f() -> int:
    x: int | str = "hello"
    return first(x, (x := 1))

Found by Codex

Activity

  1. rathodfalguni52-oss commented on Nov 10, 2026

    @rathodfalguni52-oss

    Hi maintainers!

    I would like to work on this issue. I understand that the problem involves incorrect overload resolution when using the walrus operator, resulting in a false negative during type checking.

    My approach would be to first reproduce the issue with a test case, investigate how mypy handles argument evaluation, type narrowing, and overload resolution, and then identify the cause of the incorrect behaviour. Based on my findings, I would work on implementing a fix and adding regression tests to ensure the issue is resolved without affecting existing functionality.

    Could you please let me know if I can take this issue up and whether you have any suggestions regarding the implementation approach?

    Thank you!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions