Show More
@@ -270,6 +270,16 b' class ExecutionResult(object):' | |||||
270 | return '<%s object at %x, execution_count=%s error_before_exec=%s error_in_exec=%s info=%s result=%s>' %\ |
|
270 | return '<%s object at %x, execution_count=%s error_before_exec=%s error_in_exec=%s info=%s result=%s>' %\ | |
271 | (name, id(self), self.execution_count, self.error_before_exec, self.error_in_exec, repr(self.info), repr(self.result)) |
|
271 | (name, id(self), self.execution_count, self.error_before_exec, self.error_in_exec, repr(self.info), repr(self.result)) | |
272 |
|
272 | |||
|
273 | @functools.wraps(io_open) | |||
|
274 | def _modified_open(file, *args, **kwargs): | |||
|
275 | if file in {0, 1, 2}: | |||
|
276 | raise ValueError( | |||
|
277 | f"IPython won't let you open fd={file} by default " | |||
|
278 | "as it is likely to crash IPython. If you know what you are doing, " | |||
|
279 | "you can use builtins' open." | |||
|
280 | ) | |||
|
281 | ||||
|
282 | return io_open(file, *args, **kwargs) | |||
273 |
|
283 | |||
274 | class InteractiveShell(SingletonConfigurable): |
|
284 | class InteractiveShell(SingletonConfigurable): | |
275 | """An enhanced, interactive shell for Python.""" |
|
285 | """An enhanced, interactive shell for Python.""" | |
@@ -1323,6 +1333,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
1323 |
|
1333 | |||
1324 | ns['exit'] = self.exiter |
|
1334 | ns['exit'] = self.exiter | |
1325 | ns['quit'] = self.exiter |
|
1335 | ns['quit'] = self.exiter | |
|
1336 | ns["open"] = _modified_open | |||
1326 |
|
1337 | |||
1327 | # Sync what we've added so far to user_ns_hidden so these aren't seen |
|
1338 | # Sync what we've added so far to user_ns_hidden so these aren't seen | |
1328 | # by %who |
|
1339 | # by %who |
@@ -103,6 +103,18 b' class InteractiveShellTestCase(unittest.TestCase):' | |||||
103 | res = ip.run_cell("raise = 3") |
|
103 | res = ip.run_cell("raise = 3") | |
104 | self.assertIsInstance(res.error_before_exec, SyntaxError) |
|
104 | self.assertIsInstance(res.error_before_exec, SyntaxError) | |
105 |
|
105 | |||
|
106 | def test_open_standard_input_stream(self): | |||
|
107 | res = ip.run_cell("open(0)") | |||
|
108 | self.assertIsInstance(res.error_in_exec, ValueError) | |||
|
109 | ||||
|
110 | def test_open_standard_output_stream(self): | |||
|
111 | res = ip.run_cell("open(1)") | |||
|
112 | self.assertIsInstance(res.error_in_exec, ValueError) | |||
|
113 | ||||
|
114 | def test_open_standard_error_stream(self): | |||
|
115 | res = ip.run_cell("open(2)") | |||
|
116 | self.assertIsInstance(res.error_in_exec, ValueError) | |||
|
117 | ||||
106 | def test_In_variable(self): |
|
118 | def test_In_variable(self): | |
107 | "Verify that In variable grows with user input (GH-284)" |
|
119 | "Verify that In variable grows with user input (GH-284)" | |
108 | oldlen = len(ip.user_ns['In']) |
|
120 | oldlen = len(ip.user_ns['In']) |
General Comments 0
You need to be logged in to leave comments.
Login now