contextlib.contextmanager is dangerous because its __exit__ won't get run if an exception is raised, which is rarely what you want:
from contextlib import contextmanager
@contextmanager
def foo():
print('starting')
yield
print('ending')
with foo():
raise Exception
it would be nice if ruff had a rule to enforce try/finally on these types of context managers:
from contextlib import contextmanager
@contextmanager
def foo():
print('starting')
try:
yield
finally:
print('ending')
contextlib.contextmanageris dangerous because its__exit__won't get run if an exception is raised, which is rarely what you want:it would be nice if ruff had a rule to enforce
try/finallyon these types of context managers: