Skip to content

false positive Incompatible types in assignment for overloaded function #21784

Description

@sam-s

I declare a variable type and get assignment error for gzip.open but not for open,

To Reproduce

from collections.abc import Callable
from typing import IO
import gzip

foo : Callable[[str, str], IO] = gzip.open

Expected Behavior

no diagnostics

Actual Behavior

error: Incompatible types in assignment (expression has type overloaded function, variable has type "Callable[[str, str], IO[Any]]") [assignment]

but no diagnostics for

from collections.abc import Callable
from typing import IO

foo : Callable[[str, str], IO] = open

Your Environment

  • Mypy version used: mypy 2.3.0
  • Mypy command-line flags: --check-untyped-defs
  • Python version used: 3.14.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions