You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
thautwarm commented on Oct 15, 2018
thautwarmmannequin
Mannequin
More actions
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>
cool-RR commented on Oct 15, 2018
cool-RRmannequin
MannequinAuthor
More actions
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.)
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 :-)
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.
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.
Activity
ericvsmith commentedon Oct 10, 2018
What do you propose the repr would look like?
cool-RR commentedon Oct 11, 2018
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:
So here's an example:
And another:
I don't know whether we're able to include the file name on there, that would be nice.
thautwarm commentedon Oct 15, 2018
How about this:
cool-RR commentedon Oct 15, 2018
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.)thautwarm commentedon Oct 15, 2018
@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 ... endcould also be called entire_contents :-)zhangyangyu commentedon Oct 16, 2018
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.
ericvsmith commentedon Oct 16, 2018
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.
serhiy-storchaka commentedon Oct 16, 2018
I think that performing any IO operations in repr() is not a good idea.
thautwarm commentedon Oct 16, 2018
I think it depends on the use case. If
reprwouldn'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.
zhangyangyu commentedon Oct 17, 2019
New changeset d8ca235 by Xiang Zhang (Taine Zhao) in branch 'master':
bpo-34953: Implement
mmap.mmap.__repr__(GH-9891)d8ca235