[issue19282] dbm.open should be a context manager

Claudiu.Popa report at bugs.python.org
Sat Oct 19 08:29:34 CEST 2013


Claudiu.Popa added the comment:

Attached patch checks that the db is actually closed after the `with`. Also, I noticed that dbm.dumb doesn't behave like the rest of the variants, as seen in the following:

>>> import dbm.dumb as d
>>> db = d.open('test.dat', 'c')
>>> db.close()
>>> db.keys()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tank/libs/cpython/Lib/dbm/dumb.py", line 212, in keys
    return list(self._index.keys())
AttributeError: 'NoneType' object has no attribute 'keys'
>>>

vs

>>> import dbm.gnu as g
>>> db = g.open('test.dat', 'c')
>>> db.close()
>>> db.keys()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
_gdbm.error: GDBM object has already been closed
>>>

----------
Added file: http://bugs.python.org/file32215/dbm1.patch

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


More information about the Python-bugs-list mailing list