-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
bpo-40638: Check for attribute lookup failure in builtin_input_impl #20125
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
base: main
Are you sure you want to change the base?
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 |
---|---|---|
|
@@ -75,6 +75,23 @@ class BitBucket: | |
def write(self, line): | ||
pass | ||
|
||
class MalformedInputStream: | ||
def readline(self): | ||
return "foobar\n" | ||
|
||
def fileno(self): | ||
return 0 | ||
|
||
class MalformedOutputStream: | ||
def __init__(self): | ||
self.value = "" | ||
|
||
def fileno(self): | ||
return 1 | ||
|
||
def write(self, value): | ||
self.value += value | ||
|
||
test_conv_no_sign = [ | ||
('0', 0), | ||
('1', 1), | ||
|
@@ -1302,6 +1319,13 @@ def test_input(self): | |
sys.stdin = io.StringIO() | ||
self.assertRaises(EOFError, input) | ||
|
||
# input() in tty mode with a malformed input stream should attempt | ||
# to call .readline() | ||
sys.stdin = MalformedInputStream() | ||
sys.stdout = MalformedOutputStream() | ||
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. Have you considered using a StringIO object for sys.stdout here? |
||
self.assertEqual(input("baz"), "foobar") # strips \n | ||
self.assertEqual(sys.stdout.value, "baz") | ||
|
||
Comment on lines
+1322
to
+1328
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. Having this here is slightly confusing, as it appears like it may affect the following assertion as well. Perhaps put this at the end of this method or in a separate method. |
||
del sys.stdout | ||
self.assertRaises(RuntimeError, input, 'prompt') | ||
del sys.stdin | ||
|
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.
"Malformed" in what way? I think this name could be better.