Skip to content

Regression: overload signatures with default parameters no longer reported as overlapping #18581

Closed as not planned
@sterliakov

Description

@sterliakov

Bug Report

Since 1.11.0 and up to current master mypy no longer reports overloads in the snippet below as overlapping. 1.10.1 detects the overlap correctly.

According to the recent typing spec update for overloads, this is a bug:

If two overloads can accept the same set of arguments, they are said to "partially overlap". If two overloads partially overlap, the return type of the former overload should be assignable to the return type of the latter overload. If this condition doesn't hold, it is indicative of a programming error and should be reported by type checkers.

This bisects to #17392 - this false negative was missed there. cc @ilevkivskyi

To Reproduce

https://mypy-play.net/?mypy=1.11.0&python=3.10&flags=strict&gist=9f4be4dac4c302b9d556746cdbffa251

from typing import overload

@overload
def fn(x: str = ...) -> str: ...
@overload
def fn(x: int = ...) -> int: ...
def fn(x: int | str = 0) -> int | str:
    return x

Expected Behavior

Since fn() is allowed for both signatures, they overlap, so 1.10.1 output should remain there:

main.py:4: error: Overloaded function signatures 1 and 2 overlap with incompatible return types  [overload-overlap]

Actual Behavior

Mypy accepts the snippet.

Your Environment

  • Mypy version used: 1.11.0 through current master vs 1.10.1
  • Mypy command-line flags: --strict and without
  • Mypy configuration options from mypy.ini (and other config files): n/a
  • Python version used: 3.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions