Skip to content

Conversation

irreg
Copy link

@irreg irreg commented Jun 20, 2025

Contextmanager does not process the finalize process in try-finally and may not execute when exiting contextmanager with an error.
Unintended results were observed due to the different state of the file from the application using LSP.

from contextlib import contextmanager


@contextmanager
def sample():
    try:
        yield
        print("a")
    finally:
        print("b")

with sample():
    raise Exception # Show only b

@irreg
Copy link
Author

irreg commented Jun 20, 2025

@microsoft-github-policy-service agree

@LakshyAAAgrawal LakshyAAAgrawal self-requested a review August 1, 2025 19:10
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

Successfully merging this pull request may close these issues.

2 participants