##// END OF EJS Templates
Semicolon at the end silence output of %%time too.
nfgf -
Show More
@@ -2423,6 +2423,14 b' class InteractiveShell(SingletonConfigurable):'
2423 with self.builtin_trap:
2423 with self.builtin_trap:
2424 args = (magic_arg_s, cell)
2424 args = (magic_arg_s, cell)
2425 result = fn(*args, **kwargs)
2425 result = fn(*args, **kwargs)
2426
2427 # The code below prevents the output from being displayed
2428 # when using magics with decodator @output_can_be_silenced
2429 # when the last Python token in the expression is a ';'.
2430 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):
2431 if DisplayHook.semicolon_at_end_of_expression(cell):
2432 return None
2433
2426 return result
2434 return result
2427
2435
2428 def find_line_magic(self, magic_name):
2436 def find_line_magic(self, magic_name):
@@ -3199,6 +3207,7 b' class InteractiveShell(SingletonConfigurable):'
3199 # Execute the user code
3207 # Execute the user code
3200 interactivity = "none" if silent else self.ast_node_interactivity
3208 interactivity = "none" if silent else self.ast_node_interactivity
3201
3209
3210
3202 has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
3211 has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
3203 interactivity=interactivity, compiler=compiler, result=result)
3212 interactivity=interactivity, compiler=compiler, result=result)
3204
3213
@@ -422,6 +422,7 b' def test_time():'
422 def test_time_no_output_with_semicolon():
422 def test_time_no_output_with_semicolon():
423 ip = get_ipython()
423 ip = get_ipython()
424
424
425 # Test %time cases
425 with tt.AssertPrints(" 123456"):
426 with tt.AssertPrints(" 123456"):
426 with tt.AssertPrints("Wall time: ", suppress=False):
427 with tt.AssertPrints("Wall time: ", suppress=False):
427 with tt.AssertPrints("CPU times: ", suppress=False):
428 with tt.AssertPrints("CPU times: ", suppress=False):
@@ -447,6 +448,32 b' def test_time_no_output_with_semicolon():'
447 with tt.AssertPrints("CPU times: ", suppress=False):
448 with tt.AssertPrints("CPU times: ", suppress=False):
448 ip.run_cell("%time 123000+456 # ;Comment")
449 ip.run_cell("%time 123000+456 # ;Comment")
449
450
451 # Test %%time cases
452 with tt.AssertPrints("123456"):
453 with tt.AssertPrints("Wall time: ", suppress=False):
454 with tt.AssertPrints("CPU times: ", suppress=False):
455 ip.run_cell("%%time\n123000+456\n\n\n")
456
457 with tt.AssertNotPrints("123456"):
458 with tt.AssertPrints("Wall time: ", suppress=False):
459 with tt.AssertPrints("CPU times: ", suppress=False):
460 ip.run_cell("%%time\n123000+456;\n\n\n")
461
462 with tt.AssertPrints("123456"):
463 with tt.AssertPrints("Wall time: ", suppress=False):
464 with tt.AssertPrints("CPU times: ", suppress=False):
465 ip.run_cell("%%time\n123000+456 # Comment\n\n\n")
466
467 with tt.AssertNotPrints("123456"):
468 with tt.AssertPrints("Wall time: ", suppress=False):
469 with tt.AssertPrints("CPU times: ", suppress=False):
470 ip.run_cell("%%time\n123000+456; # Comment\n\n\n")
471
472 with tt.AssertPrints("123456"):
473 with tt.AssertPrints("Wall time: ", suppress=False):
474 with tt.AssertPrints("CPU times: ", suppress=False):
475 ip.run_cell("%%time\n123000+456 # ;Comment\n\n\n")
476
450
477
451 def test_time_last_not_expression():
478 def test_time_last_not_expression():
452 ip.run_cell("%%time\n"
479 ip.run_cell("%%time\n"
General Comments 0
You need to be logged in to leave comments. Login now