-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
mmap.read requires an argument #56230
Comments
mmap.read requires a argument. Since most file-like objects do not, this breaks the file-like object illusion. mmap.read argument should be optional, presumably defaulting to the entire mmap'd area. |
Sounds like a reasonable request, although I don't think it's a bug fix in itself (there are probably other places where mmap breaks the file-like expectation). |
Added a patch. It was only a matter of making the size parameter optional. |
Updated the patch to also update the documentation of mmap.read(). |
The patch looks good to me. |
Thanks for the comments. I attached a new patch that uses self.addCleanup(m.close), and also adds a versionchanged directive to the docs. |
I noticed that RawIOBase.read, TextIOBase.read, etc also accept None as the argument, treating it as -1. Should this be implemented, too? |
That's because of the _PyIO_ConvertSsize_t converter, which silently If the patch is fine as-is, I'd like to commit it. |
I'm not sure about the original reason, but I find None as the default "omitted" value prettier than -1 myself, so I think it's a good thing :) |
Antoine Pitrou wrote:
Yeah, and it's also good for consistency with other file-like objects. Can I use _PyIO_ConvertSsize_t? Or should I duplicate its |
If being pretty is the only reason for this choice, then I think that method:: read([n]) is simpler and cleaner . But you've got much more experience than me, so I won't argue any further :-)
I let Antoine answer that. |
There are contexts where it is easier to give the default argument than
I'm not sure. This would require including iomodule.h, which is supposed |
Added a new patch. I duplicated the None converting logic in _io/_iomodule.c to mmapmodule.c, changed the doc to say "read([n])", and expanded the test cases a bit. |
Didn't you forget to attach the patch? |
It seems I did. Attached now for real :) |
Patch looks good to me, thank you :) |
New changeset 964d0d65a2a9 by Charles-François Natali in branch 'default': |
Patch committed. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: