Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support context management protocol in bkfile #67015

Closed
serhiy-storchaka opened this issue Nov 9, 2014 · 6 comments
Closed

Support context management protocol in bkfile #67015

serhiy-storchaka opened this issue Nov 9, 2014 · 6 comments
Assignees
Labels
type-feature A feature request or enhancement

Comments

@serhiy-storchaka
Copy link
Member

BPO 22826
Nosy @rhettinger, @berkerpeksag, @serhiy-storchaka
Files
  • bkfile.diff
  • bkfile2.patch
  • bkfile3.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2015-03-20.07:49:10.228>
    created_at = <Date 2014-11-09.16:07:35.817>
    labels = ['type-feature']
    title = 'Support context management protocol in bkfile'
    updated_at = <Date 2015-03-20.07:49:10.227>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2015-03-20.07:49:10.227>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2015-03-20.07:49:10.228>
    closer = 'serhiy.storchaka'
    components = ['Demos and Tools']
    creation = <Date 2014-11-09.16:07:35.817>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['37152', '37157', '37456']
    hgrepos = []
    issue_num = 22826
    keywords = ['patch', 'needs review']
    message_count = 6.0
    messages = ['230888', '230893', '230899', '232683', '232687', '238610']
    nosy_count = 4.0
    nosy_names = ['rhettinger', 'python-dev', 'berker.peksag', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue22826'
    versions = ['Python 3.5']

    @serhiy-storchaka
    Copy link
    Member Author

    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.

    @serhiy-storchaka serhiy-storchaka added the type-feature A feature request or enhancement label Nov 9, 2014
    @rhettinger
    Copy link
    Contributor

    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:

    @serhiy-storchaka
    Copy link
    Member Author

    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?

    @berkerpeksag
    Copy link
    Member

    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
    

    @serhiy-storchaka
    Copy link
    Member Author

    Good catch Berker. Updated patch fixes recursion issue.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Mar 20, 2015

    New changeset ea8c3166d1c2 by Serhiy Storchaka in branch 'default':
    Issue bpo-22826: The result of open() in Tools/freeze/bkfile.py is now better
    https://hg.python.org/cpython/rev/ea8c3166d1c2

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants