Skip to content

Commit 0ea52e4

Browse files
committed
add extra newline to execute for return dictionary
1 parent b4e1ddb commit 0ea52e4

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

python_files/normalizeSelection.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,12 @@ def normalize_lines(selection):
120120

121121
# Insert a newline between each top-level statement, and append a newline to the selection.
122122
source = "\n".join(statements) + "\n"
123+
# If selection ends with trailing dictionary or list, remove last new-line for "cleaner run".
123124
if selection[-2] == "}" or selection[-2] == "]":
124125
source = source[:-1]
126+
# If the selection contains trailing return dictionary, insert newline to run automatically.
127+
if check_end_with_return_dict(selection):
128+
source = source + "\n"
125129
except Exception:
126130
# If there's a problem when parsing statements,
127131
# append a blank line to end the block and send it as-is.
@@ -134,6 +138,11 @@ def normalize_lines(selection):
134138
min_key = None
135139

136140

141+
def check_end_with_return_dict(code):
142+
stripped_code = code.strip()
143+
return stripped_code.endswith("}") and "return {" in stripped_code.strip()
144+
145+
137146
def check_exact_exist(top_level_nodes, start_line, end_line):
138147
return [
139148
node

0 commit comments

Comments
 (0)