Skip to content

False positive with --warn-unreachable when calling something with a lambda expression which raises #13863

Description

@bzoracler

Bug Report

--warn-unreachable causes mypy to interpret a lambda-expression-which-always-raises, passed into a callable, to be unreachable.

To Reproduce

from typing import NoReturn

def always_raises() -> NoReturn:
    raise Exception

def accepts_anything(*args: object, **kwargs: object) -> None:
    pass

accepts_anything(lambda: always_raises())

a: int = 3  # mypy: Statement is unreachable [unreachable]

Expected Behavior

No issues

Mypy Environment

Tested on the mypy-play.net playground:

  • Mypy version used: master and 0.981
  • Mypy command-line flags: --warn-unreachable
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions