Skip to content

overloaded method that has NoReturn for certain arguments not detected  #15861

Closed as not planned
@Dr-Irv

Description

@Dr-Irv

Bug Report

If you have a method that has an overload for specific arguments that are not allowed, by having that overload return NoReturn, and a wider default that accepts Any, mypy does not detect the invalid argument.

To Reproduce

from typing import Any, NoReturn, overload


class Goo:
    @overload
    def __add__(self, other: str) -> NoReturn:
        ...

    @overload
    def __add__(self, other: Any) -> bool:
        ...

    def __add__(self, other: Any) -> bool:
        return True


y = Goo()
y + 4
y + "abc"

Expected Behavior

I expect that the line y + "abc" is reported as an invalid operation.

Actual Behavior

Success: no issues found in 1 source file

Your Environment

  • Mypy version used: 1.4.1
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.9.16

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