[issue13896] Make shelf instances work with 'with' as context managers

Terry J. Reedy report at bugs.python.org
Sat Feb 4 02:41:01 CET 2012


Terry J. Reedy <tjreedy at udel.edu> added the comment:

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?)

----------
nosy: +ncoghlan, terry.reedy
stage:  -> test needed
title: shelf doesn't work with 'with' -> Make shelf instances work with 'with' as context managers
type:  -> enhancement
versions: +Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13896>
_______________________________________


More information about the Python-bugs-list mailing list