This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2012年01月28日 11:12 by gruszczy, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| 13896.patch | gruszczy, 2012年01月28日 11:12 | review | ||
| Messages (10) | |||
|---|---|---|---|
| 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) * (Python committer) | 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) * (Python committer) | 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) (Python triager) | 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) * (Python committer) | 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) * (Python committer) | Date: 2013年01月26日 19:20 | |
The patch did not update the doc. See #17040, with proposed patch. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:26 | admin | set | github: 58104 |
| 2013年01月26日 19:20:15 | terry.reedy | set | messages: + msg180702 |
| 2012年10月06日 10:54:40 | asvetlov | set | status: open -> closed resolution: fixed messages: + msg172178 stage: patch review -> resolved |
| 2012年10月06日 10:52:39 | python-dev | set | nosy:
+ python-dev messages: + msg172177 |
| 2012年10月06日 01:04:27 | gruszczy | set | messages: + msg172159 |
| 2012年10月05日 19:40:03 | asvetlov | set | assignee: asvetlov |
| 2012年10月05日 19:39:09 | asvetlov | set | messages: + msg172122 |
| 2012年09月26日 10:58:43 | asvetlov | set | nosy:
+ asvetlov |
| 2012年09月10日 21:14:53 | berker.peksag | set | versions: + Python 3.4, - Python 3.3 |
| 2012年09月06日 05:49:00 | Miguel.Angel.García | set | nosy:
+ Miguel.Angel.García |
| 2012年02月04日 09:51:16 | terry.reedy | set | stage: test needed -> patch review |
| 2012年02月04日 08:55:03 | gruszczy | set | messages: + msg152604 |
| 2012年02月04日 01:41:00 | terry.reedy | set | versions:
+ Python 3.3 type: enhancement nosy: + terry.reedy, ncoghlan title: shelf doesn't work with 'with' -> Make shelf instances work with 'with' as context managers messages: + msg152575 stage: test needed |
| 2012年01月29日 15:29:01 | gruszczy | set | messages: + msg152236 |
| 2012年01月28日 20:03:26 | zachary r. | set | nosy:
+ zachary r. messages: + msg152185 |
| 2012年01月28日 11:12:56 | gruszczy | set | files:
+ 13896.patch keywords: + patch |
| 2012年01月28日 11:12:29 | gruszczy | create | |