Skip to content

Implement mmap.mmap.__repr__ #79134

Closed
Closed

Description

@cool-RR
mannequin
BPO 34953
Nosy @ericvsmith, @cool-RR, @serhiy-storchaka, @zhangyangyu, @pablogsal, @thautwarm, @tirkarthi
PRs
  • bpo-34953: Implement mmap.mmap.__repr__ #9891
  • 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 = None
    closed_at = <Date 2019-10-17.10:42:49.761>
    created_at = <Date 2018-10-10.16:53:18.806>
    labels = ['extension-modules', 'type-feature', '3.9']
    title = 'Implement `mmap.mmap.__repr__`'
    updated_at = <Date 2019-10-17.10:42:49.746>
    user = 'https://github.com/cool-RR'

    bugs.python.org fields:

    activity = <Date 2019-10-17.10:42:49.746>
    actor = 'xiang.zhang'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-10-17.10:42:49.761>
    closer = 'xiang.zhang'
    components = ['Extension Modules']
    creation = <Date 2018-10-10.16:53:18.806>
    creator = 'cool-RR'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 34953
    keywords = ['patch']
    message_count = 10.0
    messages = ['327503', '327517', '327734', '327759', '327767', '327805', '327806', '327807', '327833', '354838']
    nosy_count = 7.0
    nosy_names = ['eric.smith', 'cool-RR', 'serhiy.storchaka', 'xiang.zhang', 'pablogsal', 'thautwarm', 'xtreak']
    pr_nums = ['9891']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue34953'
    versions = ['Python 3.9']

    Activity

    1. added
      stdlib
      3.8 (EOL)
      type-feature
      on Oct 10, 2018
    2. ericvsmith commented on Oct 10, 2018

      @ericvsmith
      Member

      What do you propose the repr would look like?

    3. added
      interpreter-core
      and removed
      stdlib
      on Oct 10, 2018
    4. cool-RR commented on Oct 11, 2018

      cool-RRmannequin
      MannequinAuthor

      There are a few ways we can go with this, depending on how verbose we want to be and how willing we are to make calls to the data. Here are a few pieces of information we could expose:

      • Length
      • Whether it's a file or anonymous memory
      • The entire contents
      • The clipped contents
      • Whether it's opened or closed
      • The access type

      So here's an example:

      <mmap.mmap object; length=514 access=ACCESS_READ>
      

      And another:

      <mmap.mmap object; length=514 content=b'This is my' ... b'file.'>
      

      I don't know whether we're able to include the file name on there, that would be nice.

    5. thautwarm commented on Oct 15, 2018

      thautwarmmannequin
      Mannequin

      How about this:

      # opened
      <mmap.mmap is_closed=False fileno=-1 access=ACCESS_READ length=514 offset=0 entire_contents=b"This is my"...b"file">
      
      # closed
      <mmap.mmap is_closed=True fileno=-1 access=ACCESS_READ>
      
      
    6. cool-RR commented on Oct 15, 2018

      cool-RRmannequin
      MannequinAuthor

      thautwarm, your suggestions look good. I'm not sure why you used
      entire_contents, do you want to show the entire content there? Because I saw that the sample you used had truncation. It might be unsafe to show the entire mmap, because it could be huge. I'd truncate in some way or other. (Either show just the beginning, or just the beginning and the end.)

    7. thautwarm commented on Oct 15, 2018

      thautwarmmannequin
      Mannequin

      @ram Rachum

      Yes yes yes, actually the entire contents will be truncated when its length is bigger than a specific integer(now it's 50). For we use ... to represent the ignored contents, start ... end could also be called entire_contents :-)

    8. zhangyangyu commented on Oct 16, 2018

      @zhangyangyu
      Member

      I don't like the idea to display the contents in the repr, no matter entire or clipped. I think it's not suitable and for contents, just read the object manually. For me, a closed status plus the constructor arguments is a good choice.

    9. ericvsmith commented on Oct 16, 2018

      @ericvsmith
      Member

      I agree with Xiang Zhang: I don't think we should show any content. Especially since basically every file will be truncated, and more often than not the interesting content isn't at the start or end of the file.

    10. serhiy-storchaka commented on Oct 16, 2018

      @serhiy-storchaka
      Member

      I think that performing any IO operations in repr() is not a good idea.

    11. thautwarm commented on Oct 16, 2018

      thautwarmmannequin
      Mannequin

      I think it depends on the use case. If repr wouldn't be invoked except debugging,some IO operations might not be that bad.

      I'm to make some adjustments to avoid displaying the contents if nothing evidence that IO operations is not bad.

    12. zhangyangyu commented on Oct 17, 2019

      @zhangyangyu
      Member

      New changeset d8ca235 by Xiang Zhang (Taine Zhao) in branch 'master':
      bpo-34953: Implement mmap.mmap.__repr__ (GH-9891)
      d8ca235

    13. added
      3.9 (EOL)
      extension-modules
      and removed
      3.8 (EOL)
      interpreter-core
      on Oct 17, 2019
    14. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.9 (EOL)extension-modulestype-feature

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions