Skip to content

function call that returns Never incorrectly marked as unreachable when function that's defined later with multiple argument decorator is called #13043

Closed

Description

@DetachHead

sorry for the wacky title

from typing import TypeVar, Literal
from typing_extensions import assert_never

Fn = TypeVar("Fn")


def foo(fn: Fn, value: bool = False) -> Fn:
    ...


def bar(value: Literal[True]) -> None:
    if value:
        baz()
    else:
        assert_never(value) # error: Statement is unreachable  [unreachable]


@foo
def baz() -> None:
    ...

playground

functions that return Never are not supposed to be marked as unreachable - see #10916 (comment)

Activity

  1. KotlinIsland commented on Jun 30, 2022

    @KotlinIsland
    Contributor

    Looks similar to #8900

    minified:

    from typing import _T as T
    
    def foo() -> None:
        return bar()
        exit()  # error: Statement is unreachable  [unreachable]
    
    def deco(fn: T, a: bool = False) -> T: ...
    
    @deco
    def bar() -> None: ...
  2. DetachHead commented on Aug 11, 2022

    @DetachHead
    ContributorAuthor

    also causes an invalid 'Expression has type "Any"' error:

    from typing import TypeVar
    
    Fn = TypeVar("Fn")
    
    def foo(fn: Fn, value: bool = False) -> Fn:
        ...
    
    
    def f() -> None:
        baz()
        try:
            ...
        except Exception as ex:  # error: Expression has type "Any"  [misc]
            pass
    
    @foo
    def baz() -> None:
        ...

    playground

    very related (probably the same issue?): #13167

  3. added 2 commits that reference this issue on Sep 1, 2022
    19c3869
    3eb30a8
  4. added a commit that references this issue on Sep 2, 2022
    0a8d425
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

    bugmypy got something wrongtopic-reachabilityDetecting unreachable code

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions