msg200191 - (view) |
Author: Nick Guenther (kousu) |
Date: 2013-10-18 07:45 |
This code doesn't work. I think it should. import dbm with dbm.open("what is box.db", "c") as db: db["Bpoind"] = Boing Indeed, there is nothing supporting PEP 343 for dbm on my system: [kousu@galleon ~]$ grep -r __exit__ /usr/lib/python3.3/dbm [kousu@galleon ~]$ |
|
|
msg200232 - (view) |
Author: PCManticore (Claudiu.Popa) *  |
Date: 2013-10-18 09:10 |
Working on a patch for this. |
|
|
msg200241 - (view) |
Author: PCManticore (Claudiu.Popa) *  |
Date: 2013-10-18 10:45 |
Here's a patch. |
|
|
msg200336 - (view) |
Author: Terry J. Reedy (terry.reedy) *  |
Date: 2013-10-19 00:16 |
I agree with the revised title. Test_context_manager() should also test that db is actually closed after the with statement. I presume you can use self.assertRaises and try to do something with db that will fail if it is properly closed. with self.assertRaises(): db['a'] = 'a' # or whatever I haven't looked at the C code. |
|
|
msg200376 - (view) |
Author: PCManticore (Claudiu.Popa) *  |
Date: 2013-10-19 06:29 |
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 "", line 1, in 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 "", line 1, in _gdbm.error: GDBM object has already been closed >>> |
|
|
msg200697 - (view) |
Author: Raymond Hettinger (rhettinger) *  |
Date: 2013-10-21 04:57 |
This seems like a reasonable request. |
|
|
msg201545 - (view) |
Author: PCManticore (Claudiu.Popa) *  |
Date: 2013-10-28 14:47 |
There is for the inconsistency of dbm.dumb, with a patch. |
|
|
msg201818 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2013-10-31 14:33 |
Patch looks reasonable to me - if nobody beats me to it, I'll commit this before beta 1 :) |
|
|
msg203119 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2013-11-17 06:00 |
New changeset c2f1bb56760d by Nick Coghlan in branch 'default': Close #19282: Native context management in dbm http://hg.python.org/cpython/rev/c2f1bb56760d |
|
|
msg203120 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2013-11-17 06:03 |
Thanks Claudiu! Additional tweaks in the committed version: - added a paragraph to the docs about the with statement support and moved the versionchanged note there - changed the example in the docs to use a with statement - added a basic test that the dumbdbm impl was actually closed, with a comment referencing issue 19385 (since that isn't subject to the beta 1 deadline) |
|
|
msg203121 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2013-11-17 06:04 |
I also changed the signature of the enter/exit methods to just use PyObject * (rather than dbmobject *), since that allowed a bunch of casts to be removed and eliminated a couple of compiler warnings about type mismatches. |
|
|
msg203123 - (view) |
Author: PCManticore (Claudiu.Popa) *  |
Date: 2013-11-17 07:34 |
Cool, thanks! |
|
|
msg212941 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2014-03-08 17:54 |
New changeset 200207e50cbf by R David Murray in branch 'default': whatsnew: dbm.open is context manager. (#19282) http://hg.python.org/cpython/rev/200207e50cbf |
|
|