You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
title="Make shelf instances work with 'with' as context managers"updated_at=<Date2013-01-26.19:20:15.938>user='https://bugs.python.org/gruszczy'
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?)
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.
I see comment for __del__ related to bpo-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.