classification
Title: Support context management protocol in bkfile
Type: enhancement Stage: resolved
Components: Demos and Tools Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: berker.peksag, python-dev, rhettinger, serhiy.storchaka
Priority: normal Keywords: needs review, patch

Created on 2014-11-09 16:07 by serhiy.storchaka, last changed 2015-03-20 07:49 by serhiy.storchaka. This issue is now closed.

Files
File name Uploaded Description Edit
bkfile.diff serhiy.storchaka, 2014-11-09 16:07 review
bkfile2.patch serhiy.storchaka, 2014-11-09 19:07
bkfile3.patch serhiy.storchaka, 2014-12-15 22:19 review
Messages (6)
msg230888 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-11-09 16:07
Proposed patch makes bkfile (file-like class used in freeze) support the context management protocol. This makes bkfile more file-like and makes the use of it simpler and more robust.
msg230893 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-11-09 17:29
This looks correct and it improves readability.

One nit,  please put the doubled with on a single line instead of using the awkward line break (which looks weird with respect to the indentation of the with-block):

+    with open(config_c_in) as infp, bkfile.open(config_c, 'w') as outfp:
msg230899 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-11-09 19:07
Thank you Raymond. I found my old patch written 5 months ago. It drastically simplifies bkfile by using monkey-patching. What approach looks better to you?
msg232683 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2014-12-15 21:35
The second patch raises "RuntimeError: maximum recursion depth exceeded" if the target file is exist.

      File "/home/berker/projects/cpython/default/Tools/freeze/bkfile.py", line 18, in close
        f.close()
    RuntimeError: maximum recursion depth exceeded
msg232687 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-12-15 22:19
Good catch Berker. Updated patch fixes recursion issue.
msg238610 - (view) Author: Roundup Robot (python-dev) Date: 2015-03-20 07:22
New changeset ea8c3166d1c2 by Serhiy Storchaka in branch 'default':
Issue #22826: The result of open() in Tools/freeze/bkfile.py is now better
https://hg.python.org/cpython/rev/ea8c3166d1c2
History
Date User Action Args
2015-03-20 07:49:10serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: commit review -> resolved
2015-03-20 07:22:42python-devsetnosy: + python-dev
messages: + msg238610
2015-03-20 04:43:36berker.peksagsetassignee: serhiy.storchaka
stage: patch review -> commit review
2014-12-15 22:19:52serhiy.storchakasetfiles: + bkfile3.patch

messages: + msg232687
2014-12-15 21:35:20berker.peksagsetnosy: + berker.peksag
messages: + msg232683
2014-12-15 12:20:05serhiy.storchakasetkeywords: + needs review
2014-11-09 19:07:05serhiy.storchakasetfiles: + bkfile2.patch

messages: + msg230899
2014-11-09 17:29:29rhettingersetnosy: + rhettinger
messages: + msg230893
2014-11-09 16:07:35serhiy.storchakacreate