Skip to content

CLN: contextmanagers should yield in a try-finally block #44716

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

Merged
merged 2 commits into from
Dec 2, 2021
Merged

CLN: contextmanagers should yield in a try-finally block #44716

merged 2 commits into from
Dec 2, 2021

Conversation

twoertwein
Copy link
Member

@contextmanagers should yield within a try-finally block to release/reset even when an error occurs.

@jreback
Copy link
Contributor

jreback commented Dec 2, 2021

what motivated this change? e.g. did you see an error on something?

@twoertwein
Copy link
Member Author

what motivated this change? e.g. did you see an error on something?

No error, was just grepping for @contextmanager to see whether they all use try-finally. I think at least the change in file_leak_context should be very useful to verify that IO even closes file handles in case of an error (not sure how important the other two changes are).

Copy link
Member

@jbrockmendel jbrockmendel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jreback jreback added this to the 1.4 milestone Dec 2, 2021
@jreback jreback added the Clean label Dec 2, 2021
@jreback jreback merged commit 449211b into pandas-dev:master Dec 2, 2021
@jreback
Copy link
Contributor

jreback commented Dec 2, 2021

thanks @twoertwein

@twoertwein twoertwein deleted the context branch April 1, 2022 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants