Skip to content

Fix @contextmanager example - #517

Open
decorator-factory wants to merge 1 commit into
labex-labs:masterfrom
decorator-factory-clones:push-mwkopvxoxmrl
Open

Fix @contextmanager example#517
decorator-factory wants to merge 1 commit into
labex-labs:masterfrom
decorator-factory-clones:push-mwkopvxoxmrl

Conversation

@decorator-factory

Copy link
Copy Markdown

A @contextmanager with yield that's not in a try block is wrong 99% of the time.

See: https://docs.python.org/3/library/contextlib.html#contextlib.contextmanager
If the with block exits with an exception, the generator receives that exception at the yield point.

Also see: https://docs.astral.sh/ruff/rules/fallible-context-manager/

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.

1 participant