Skip to content

Incorrect unreachable code detection after return in contextlib.suppress #764

Closed
@jacobbogdanov

Description

@jacobbogdanov

Describe the bug
if there is a return statement in a with contextlib.suppress(Exception) block, then all the code after is grayed out as unreachable.

To Reproduce
See the code example below

Expected behavior
Code after a return in a contextlib.suppress is not marked as unreachable.

Screenshots or Code

import contextlib
from typing import NoReturn

def func() -> int:
    with contextlib.suppress(KeyError):
        return func2()

    return 5  # this line is grayed out

def func2() -> NoReturn:
    raise KeyError

Screen Shot 2020-06-25 at 2 34 14 PM

Screen Shot 2020-06-25 at 2 36 10 PM

VS Code extension or command-line
pyright vscode extension version 1.1.45

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