Skip to content

Avoid triggering reportUnreachable on exception raising? #11041

@hauntsaninja

Description

@hauntsaninja

(Acknowledging that this is a new and disabled-by-default rule)

Currently pyright will trigger reportUnreachable on the following code:

def foo(x: int | str):
    if isinstance(x, int):
        print("int")
    elif isinstance(x, str):
        print("str")
    else:
        raise ValueError  # error

mypy's version of the same rule ignores unreachable statements that are of a small set of forms, like raise (expr) or assert False, or statements are equivalent to a correctly used assert_never: https://github.com/python/mypy/blob/master/mypy/checker.py#L3139-L3165

This makes these diagnostics substantially higher signal

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions