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

False Positive for "Code is unreachable" #1104

Closed
ELC opened this issue Oct 17, 2020 · 1 comment
Closed

False Positive for "Code is unreachable" #1104

ELC opened this issue Oct 17, 2020 · 1 comment

Comments

@ELC
Copy link

ELC commented Oct 17, 2020

Describe the bug
When using context managers defined with classes, and an exception is raised and handled in the __exit__ block without a try/except, the rest of the code is marked as unreachable although it is perfectly reachable if the __exit__ method returns True

To Reproduce

class Example:
    def __enter__(self):
        return self

    def __exit__(self, type, value, traceback):
        return True

with Example() as example:
    raise ValueError

print("Hello World")

The print statement is marked with "Code is unreachable" although it is.

Expected behavior
The return of the __exit__ method should be checked and the warning should be applied only if it is False

Screenshots or Code
image

VS Code extension or command-line
Pyright was used as a VS Code extension.

Pyright Version: v1.1.79

VS Code Info:
Version: 1.50.1 (user setup)
Commit: d2e414d9e4239a252d1ab117bd7067f125afd80a
Date: 2020-10-13T15:06:15.712Z
Electron: 9.2.1
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Windows_NT x64 10.0.19041

@erictraut
Copy link
Collaborator

Marking this as a duplicate of microsoft/pylance-release#494

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants