Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

context managers where __exit__ returns bool | None are incorrectly treated as if they never suppress the exception #10

Open
DetachHead opened this issue Dec 2, 2023 · 2 comments · May be fixed by #111
Labels
rejected upstream also a bug in pyright/pylance or feature that isn't in pyright/pylance - they refused to address it type checking / linting issues relating to existing diagnostic rules or proposals for new diagnostic rules

Comments

@DetachHead
Copy link
Owner

import contextlib
from typing import Iterator

@contextlib.contextmanager
def context_func() -> Iterator[None]:
    try:
        yield
    except Exception:
        pass

def foo() -> None:
    with context_func():
        raise Exception

    print("xxx")  # error: Statement is unreachable
@DetachHead DetachHead added the bug label Dec 2, 2023
@DetachHead DetachHead added the rejected upstream also a bug in pyright/pylance or feature that isn't in pyright/pylance - they refused to address it label Feb 14, 2024
@DetachHead
Copy link
Owner Author

rejected upstream issue: microsoft/pyright#6034

@DetachHead DetachHead removed the bug label Feb 14, 2024
@DetachHead DetachHead added the type checking / linting issues relating to existing diagnostic rules or proposals for new diagnostic rules label Mar 24, 2024
@DetachHead
Copy link
Owner Author

AbstractContextManager now takes a second generic for its exit type, which may make this easier to fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rejected upstream also a bug in pyright/pylance or feature that isn't in pyright/pylance - they refused to address it type checking / linting issues relating to existing diagnostic rules or proposals for new diagnostic rules
Projects
None yet
1 participant