Skip to content

(🐞) False error "statement is unreachable" with NoReturn overloaded method #12402

Open
@KotlinIsland

Description

@KotlinIsland

The overloaded version has different behavior to the normal version. because it is returning NoReturn it should silence the 'unreachable' error.

from typing import overload, NoReturn


@overload
def f(a: str) -> int: ...
@overload
def f(a: str, b: NoReturn) -> NoReturn: ...

def f(a: str, b: NoReturn = ...) -> object: ...

    
b: bool
assert b

if not b:
    f("")  # error: Statement is unreachable ✅
    print("hi")

if not b:
    f("", b)  # error: Statement is unreachable ❌
    print("hi")


def f2(a: str, b: NoReturn) -> NoReturn: ...

if not b:
    f2("", b)  # no error ✅
    print("hi")
> Test run complete: 2 passed, 1 failed <

Failures:
---------------------------
if not b:
    f("", b)  # error: Statement is unreachable ❌
    print("hi")
---------------------------

Expected:
no error ✅

Actual:
error: Statement is unreachable ❌

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-reachabilityDetecting unreachable code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions