-
Notifications
You must be signed in to change notification settings - Fork 1.4k
io.TextIoWrapper.reconfigure to always flush
#7281
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import os | ||
| from io import BufferedReader, BytesIO, FileIO, RawIOBase, StringIO | ||
| from io import BufferedReader, BytesIO, FileIO, RawIOBase, StringIO, TextIOWrapper | ||
|
|
||
| from testutils import assert_raises | ||
|
|
||
|
|
@@ -58,3 +58,29 @@ def readinto(self, b): | |
|
|
||
| with assert_raises(ValueError): | ||
| f.isatty() | ||
|
|
||
|
|
||
| class Gh6588: | ||
| def __init__(self): | ||
| self.textio = None | ||
| self.closed = False | ||
|
|
||
| def writable(self): | ||
| return True | ||
|
|
||
| def readable(self): | ||
| return False | ||
|
|
||
| def seekable(self): | ||
| return False | ||
|
|
||
| def write(self, data): | ||
| self.textio.reconfigure(encoding="utf-8") | ||
| return len(data) | ||
|
|
||
|
|
||
| raw = Gh6588() | ||
| textio = TextIOWrapper(raw, encoding="utf-8", write_through=True) | ||
| raw.textio = textio | ||
| with assert_raises(AttributeError): | ||
| textio.writelines(["x"]) | ||
|
Comment on lines
+63
to
+86
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This regression test currently validates missing
Proposed test adjustment to exercise reentrant `reconfigure` path class Gh6588:
@@
def write(self, data):
self.textio.reconfigure(encoding="utf-8")
return len(data)
+
+ def flush(self):
+ self.textio.reconfigure(encoding="utf-8")
@@
-with assert_raises(AttributeError):
+with assert_raises(RuntimeError):
textio.writelines(["x"])🤖 Prompt for AI Agents
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ShaharNaveh is this comment correct?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No, the entire point of the test is to align the behavior to be like cpython and to get an |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unused
BytesIOandStringIOimports.Line 2 introduces unused imports that are already flagged by static analysis (F401), which adds noise to linting.
Proposed fix
🧰 Tools
🪛 Flake8 (7.3.0)
[error] 2-2: 'io.BytesIO' imported but unused
(F401)
[error] 2-2: 'io.StringIO' imported but unused
(F401)
🤖 Prompt for AI Agents