-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
Make shelf instances work with 'with' as context managers #58104
Comments
It would be cool if use could use with to manage shelf object and forget about close. |
The docs for shelve(see: http://docs.python.org/dev/library/shelve.html#shelve.open) recommend using contextlib.closing for this purpose. |
Oh, I haven't noticed that. Using contextlib.closing solves my problem. Thanks. |
contextlib.closing is an adapter for using objects that have a close method but have not be modernized to be context managers by having _enter__ and __exit__ methods added. Its doc gives the example A shelf instance would make a better example now, but... |
closing was solving my problem, but I'll be happy on working on this patch, if you think it's useful after all. I don't think the stage should be test needed, since the patch has tests (I know the drill here ;-)). |
Filip, please describe why you prevent closing if writeback attribute is not present. |
Crap, it was so long ago, that I honestly don't remember why I added this if. It made sense back then. |
New changeset 3c1df1ede882 by Andrew Svetlov in branch 'default': |
Committed. Thanks. |
The patch did not update the doc. See bpo-17040, with proposed patch. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: