Skip to content

Commit

Permalink
Replace commented return statements with a display() statement
Browse files Browse the repository at this point in the history
Signed-off-by: Ahdra Merali <ahdra.merali@quantumblack.com>
  • Loading branch information
Ahdra Merali committed Feb 1, 2024
1 parent 50bfea3 commit ad63afc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion kedro/ipython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def _prepare_function_body(func: Callable) -> str:
commented_return = line[:line_indentation] + "# " + return_statement
printed_return = (
line[:line_indentation]
+ "print("
+ "display("
+ return_statement[len("return") :].strip()
+ ")\n"
)
Expand Down
10 changes: 5 additions & 5 deletions tests/ipython/test_ipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def test_load_node(self, mocker, dummy_function_file_lines, dummy_pipelines):
random_assignment = "Added for a longer function"
random_assignment += "make sure to modify variable"
# return not dummy_input
print(not dummy_input)"""
display(not dummy_input)"""

expected_cells = [
node_inputs,
Expand Down Expand Up @@ -488,7 +488,7 @@ def test_prepare_function_body(self):
random_assignment = "Added for a longer function"
random_assignment += "make sure to modify variable"
# return not dummy_input
print(not dummy_input)"""
display(not dummy_input)"""

result = _prepare_function_body(dummy_function)
assert result == func_strings
Expand All @@ -500,9 +500,9 @@ def test_get_lambda_function_body(self, lambda_node):
def test_get_nested_function_body(self):
func_strings = """def nested_function(input):
# return not input
print(not input)
display(not input)
# return nested_function(dummy_input)
print(nested_function(dummy_input))"""
display(nested_function(dummy_input))"""

result = _prepare_function_body(dummy_nested_function)
assert result == func_strings
Expand All @@ -511,7 +511,7 @@ def test_get_function_with_loop_body(self):
func_strings = """for x in dummy_list:
continue
# return len(dummy_list)
print(len(dummy_list))"""
display(len(dummy_list))"""

result = _prepare_function_body(dummy_function_with_loop)
assert result == func_strings

0 comments on commit ad63afc

Please sign in to comment.