Skip to content

False positive overload-overlap with booleans and integer literals #20084

Open

Description

@bzoracler

Bug Report, To Reproduce, & Actual Behaviour

The following 2 cases trigger overload-overlap, when neither of them should (see mypy Playground).

from typing import overload, Literal

@overload
def display_str_literal(val: Literal[False], /) -> Literal["BooleanFalse"]: ...  # E: ... overload-overlap
@overload
def display_str_literal(val: Literal[0], /) -> Literal["Zero"]: ...
from typing import overload, Literal

@overload
def display_str_literal_2(val: bool, /) -> Literal["Boolean"]: ...
@overload
def display_str_literal_2(val: Literal[-1], /) -> Literal["NegativeOne"]: ...
  • Mypy version used: 1.18.2
  • Python version used: 3.12, 3.13

Activity

  1. wyattscarpenter commented on Oct 18, 2025

    @wyattscarpenter
    Contributor

    As a workaround, the second one will work if you use Literal[True, False] instead of bool (related to #14764).

  2. jorenham commented on Oct 18, 2025

    @jorenham
    Contributor

    As a workaround, the second one will work if you use Literal[True, False] instead of bool (related to #14764).

    Note that ruff (pyupgrade if I remember correctly) can report this as an error (depending on your config, of course). Using literals also tends to negatively affect type-checker analysis times (although it's probably negligible in most cases). So I think that in this case I'd prefer using a classic # type: ignore[overload-overlap] as workaround.

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