multilspy icon indicating copy to clipboard operation
multilspy copied to clipboard

fix: finalize even when exiting contextmanager by exception

Open irreg opened this issue 6 months ago • 1 comments

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 avatar Jun 20 '25 15:06 irreg

@microsoft-github-policy-service agree

irreg avatar Jun 20 '25 15:06 irreg