-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
io.StringIO constructor info is misleading #95880
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
Comments
I work on this issue^^ |
A more accurate way to phrase it would be to say that the import io
str_io = io.StringIO('foo bar')
str_io.seek(0, io.SEEK_END) # seek to end
# Now writes to the stream append instead of overwrite existing characters
str_io.write(' baz')
assert str_io.getvalue() == 'foo bar baz' |
In that case I suggest changing the docs to:
|
I'll submit a separate PR for this. The text already says, "The stream is positioned at the start of the buffer." The covers the essential technical fact about how it works. The example is needs to remain as it now because it covers the common case. We could add a separate example, but I'm not sure we want to steer people down that path. In a code review, if I saw this:
I would suggest that it be simplified to:
AFAICT, the first way is almost always the wrong way to do it with the IO module. Also, the first way doesn't emulate how we would work with regular files (which is the overall goal of the module). Mark's first suggestion, "Note that if the buffer is written to, the character(s) written will overwrite part or all of any initial_value", was a nice minimal edit. If added, that should go after the line, "The stream is positioned at the start of the buffer." Ideally, it should be reworded in a affirmative tone rather than a cautionary note:
|
@rhettinger Can I submit another PR? I provide better context. |
@najmiehsa I don't think that would be helpful. Let's just do a discussion here and I'll finish it off. I would like to hear what Mark thinks and whether he has further suggestions. The best way to help at this point is to think through the proposed wording and make suggestions. There isn't much of a value add to copying what we're saying here into a PR, that is the least interesting part of the process and it makes it a little more time consuming for the reviewer. |
…-96104) (cherry picked from commit 511dea0) Co-authored-by: Raymond Hettinger <[email protected]>
The io.StringIO constructor says:
I suggest changing this to:
I tried to do this change in the source but the source docs didn't seem to match up with the text shown on docs.python.org, hence this report.
The text was updated successfully, but these errors were encountered: