msg152159 - (view) |
Author: Filip Gruszczyński (gruszczy) |
Date: 2012-01-28 11:12 |
It would be cool if use could use with to manage shelf object and forget about close. |
|
|
msg152185 - (view) |
Author: Zachary Richey (zachary r.) |
Date: 2012-01-28 20:03 |
The docs for shelve(see: http://docs.python.org/dev/library/shelve.html#shelve.open) recommend using contextlib.closing for this purpose. |
|
|
msg152236 - (view) |
Author: Filip Gruszczyński (gruszczy) |
Date: 2012-01-29 15:29 |
Oh, I haven't noticed that. Using contextlib.closing solves my problem. Thanks. |
|
|
msg152575 - (view) |
Author: Terry J. Reedy (terry.reedy) *  |
Date: 2012-02-04 01:40 |
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 with closing(urlopen('http://www.python.org')) as page: This is now obsolete as the object returned is now a context manager. A shelf instance would make a better example now, but... I think it reasonable to update shelve.Shelf also. I believe def __enter__(self): return self def __exit__(self, e_typ, e_val, tb): self.close() are all that are needed. (Nick, true?) |
|
|
msg152604 - (view) |
Author: Filip Gruszczyński (gruszczy) |
Date: 2012-02-04 08:55 |
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 ;-)). |
|
|
msg172122 - (view) |
Author: Andrew Svetlov (asvetlov) *  |
Date: 2012-10-05 19:39 |
Filip, please describe why you prevent closing if writeback attribute is not present. I see comment for __del__ related to #1339007, but at __exit__ call __enter__ has called already and __init__ has finished definitely with success. Also I would to see reference to http://bugs.python.org/issue1339007 in __del__ comment to cleaner description of issue. |
|
|
msg172159 - (view) |
Author: Filip Gruszczyński (gruszczy) |
Date: 2012-10-06 01:04 |
Crap, it was so long ago, that I honestly don't remember why I added this if. It made sense back then. |
|
|
msg172177 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2012-10-06 10:52 |
New changeset 3c1df1ede882 by Andrew Svetlov in branch 'default': Issue #13896: Make shelf instances work with 'with' as context managers. http://hg.python.org/cpython/rev/3c1df1ede882 |
|
|
msg172178 - (view) |
Author: Andrew Svetlov (asvetlov) *  |
Date: 2012-10-06 10:54 |
Committed. Thanks. Please fill Python Contributor Agreement: http://www.python.org/psf/contrib/ |
|
|
msg180702 - (view) |
Author: Terry J. Reedy (terry.reedy) *  |
Date: 2013-01-26 19:20 |
The patch did not update the doc. See #17040, with proposed patch. |
|
|