From 0ea8569ca740ca32cc2a59a227dfb403e63b9a42 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 20 Aug 2024 10:12:22 -0700 Subject: [PATCH 1/8] do not truncate white space for multi line string --- python_files/normalizeSelection.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/python_files/normalizeSelection.py b/python_files/normalizeSelection.py index 981251289e57..759e2817a059 100644 --- a/python_files/normalizeSelection.py +++ b/python_files/normalizeSelection.py @@ -26,6 +26,20 @@ def _get_statements(selection): This will remove empty newlines around and within the selection, dedent it, and split it using the result of `ast.parse()`. """ + if '"""' in selection or "'''" in selection: + yield selection + return + + # Check if the selection is a multiline string + try: + # Attempt to parse the selection as a string literal + literal = ast.literal_eval(selection) + if isinstance(literal, str): + yield selection + return + except (ValueError, SyntaxError): + pass + # Remove blank lines within the selection to prevent the REPL from thinking the block is finished. lines = (line for line in split_lines(selection) if line.strip() != "") From d461d41e5cce38b58f3aa4c952c06c6c28b1811c Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 20 Aug 2024 11:17:06 -0700 Subject: [PATCH 2/8] adapt to new """ case --- src/test/python_files/terminalExec/sample2_normalized.py | 8 +++++++- src/test/python_files/terminalExec/sample2_raw.py | 9 +++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/test/python_files/terminalExec/sample2_normalized.py b/src/test/python_files/terminalExec/sample2_normalized.py index a333d4e0daae..318c998a2fc2 100644 --- a/src/test/python_files/terminalExec/sample2_normalized.py +++ b/src/test/python_files/terminalExec/sample2_normalized.py @@ -1,7 +1,13 @@ def add(x, y): - """Adds x to y""" + """ + Adds x + to + y + """ # Some comment + return x + y + v = add(1, 7) print(v) diff --git a/src/test/python_files/terminalExec/sample2_raw.py b/src/test/python_files/terminalExec/sample2_raw.py index 6ab7e67637f4..318c998a2fc2 100644 --- a/src/test/python_files/terminalExec/sample2_raw.py +++ b/src/test/python_files/terminalExec/sample2_raw.py @@ -1,8 +1,13 @@ def add(x, y): - """Adds x to y""" + """ + Adds x + to + y + """ # Some comment - + return x + y + v = add(1, 7) print(v) From 7f1f1f54d743473a6f4a18a168e5171716ba0dc0 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 20 Aug 2024 11:18:15 -0700 Subject: [PATCH 3/8] add more whitespaces to test --- src/test/python_files/terminalExec/sample2_normalized.py | 3 +++ src/test/python_files/terminalExec/sample2_raw.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/test/python_files/terminalExec/sample2_normalized.py b/src/test/python_files/terminalExec/sample2_normalized.py index 318c998a2fc2..132089eccc86 100644 --- a/src/test/python_files/terminalExec/sample2_normalized.py +++ b/src/test/python_files/terminalExec/sample2_normalized.py @@ -1,8 +1,11 @@ def add(x, y): """ + Adds x to y + + """ # Some comment diff --git a/src/test/python_files/terminalExec/sample2_raw.py b/src/test/python_files/terminalExec/sample2_raw.py index 318c998a2fc2..132089eccc86 100644 --- a/src/test/python_files/terminalExec/sample2_raw.py +++ b/src/test/python_files/terminalExec/sample2_raw.py @@ -1,8 +1,11 @@ def add(x, y): """ + Adds x to y + + """ # Some comment From 6d524e269d4a7d6e63fa0f2de288f80a5e91e0a0 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 20 Aug 2024 11:32:15 -0700 Subject: [PATCH 4/8] fix test --- src/test/python_files/terminalExec/sample2_normalized.py | 1 - src/test/python_files/terminalExec/sample2_raw.py | 1 - 2 files changed, 2 deletions(-) diff --git a/src/test/python_files/terminalExec/sample2_normalized.py b/src/test/python_files/terminalExec/sample2_normalized.py index 132089eccc86..e68fe95c4b09 100644 --- a/src/test/python_files/terminalExec/sample2_normalized.py +++ b/src/test/python_files/terminalExec/sample2_normalized.py @@ -8,7 +8,6 @@ def add(x, y): """ # Some comment - return x + y diff --git a/src/test/python_files/terminalExec/sample2_raw.py b/src/test/python_files/terminalExec/sample2_raw.py index 132089eccc86..e68fe95c4b09 100644 --- a/src/test/python_files/terminalExec/sample2_raw.py +++ b/src/test/python_files/terminalExec/sample2_raw.py @@ -8,7 +8,6 @@ def add(x, y): """ # Some comment - return x + y From ffd8a8911657f161e4ae1ac9a8c126b36167a781 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 20 Aug 2024 11:34:51 -0700 Subject: [PATCH 5/8] fix --- src/test/python_files/terminalExec/sample2_normalized.py | 1 - src/test/python_files/terminalExec/sample2_raw.py | 1 - 2 files changed, 2 deletions(-) diff --git a/src/test/python_files/terminalExec/sample2_normalized.py b/src/test/python_files/terminalExec/sample2_normalized.py index e68fe95c4b09..230abfda89cb 100644 --- a/src/test/python_files/terminalExec/sample2_normalized.py +++ b/src/test/python_files/terminalExec/sample2_normalized.py @@ -10,6 +10,5 @@ def add(x, y): # Some comment return x + y - v = add(1, 7) print(v) diff --git a/src/test/python_files/terminalExec/sample2_raw.py b/src/test/python_files/terminalExec/sample2_raw.py index e68fe95c4b09..230abfda89cb 100644 --- a/src/test/python_files/terminalExec/sample2_raw.py +++ b/src/test/python_files/terminalExec/sample2_raw.py @@ -10,6 +10,5 @@ def add(x, y): # Some comment return x + y - v = add(1, 7) print(v) From fb9e991922d79b2c8565c5cefd083f8f58795eb2 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 20 Aug 2024 12:11:52 -0700 Subject: [PATCH 6/8] fixing test --- src/test/python_files/terminalExec/sample2_normalized.py | 9 +-------- .../terminalExec/sample2_normalized_selection.py | 9 ++++++++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/test/python_files/terminalExec/sample2_normalized.py b/src/test/python_files/terminalExec/sample2_normalized.py index 230abfda89cb..a333d4e0daae 100644 --- a/src/test/python_files/terminalExec/sample2_normalized.py +++ b/src/test/python_files/terminalExec/sample2_normalized.py @@ -1,12 +1,5 @@ def add(x, y): - """ - - Adds x - to - y - - - """ + """Adds x to y""" # Some comment return x + y diff --git a/src/test/python_files/terminalExec/sample2_normalized_selection.py b/src/test/python_files/terminalExec/sample2_normalized_selection.py index a333d4e0daae..230abfda89cb 100644 --- a/src/test/python_files/terminalExec/sample2_normalized_selection.py +++ b/src/test/python_files/terminalExec/sample2_normalized_selection.py @@ -1,5 +1,12 @@ def add(x, y): - """Adds x to y""" + """ + + Adds x + to + y + + + """ # Some comment return x + y From 1ef07d5b2307d3ee7d6642310296e5a4efd9406a Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 20 Aug 2024 12:22:40 -0700 Subject: [PATCH 7/8] why --- .../python_files/terminalExec/sample2_normalized_selection.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/python_files/terminalExec/sample2_normalized_selection.py b/src/test/python_files/terminalExec/sample2_normalized_selection.py index 230abfda89cb..be7b280479c0 100644 --- a/src/test/python_files/terminalExec/sample2_normalized_selection.py +++ b/src/test/python_files/terminalExec/sample2_normalized_selection.py @@ -12,3 +12,4 @@ def add(x, y): v = add(1, 7) print(v) + From 3ecdbb0057da97b12de7e6776cf86a5619a05929 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 20 Aug 2024 12:51:10 -0700 Subject: [PATCH 8/8] remove unnecessary --- python_files/normalizeSelection.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/python_files/normalizeSelection.py b/python_files/normalizeSelection.py index 759e2817a059..7ea283cc09a6 100644 --- a/python_files/normalizeSelection.py +++ b/python_files/normalizeSelection.py @@ -30,16 +30,6 @@ def _get_statements(selection): yield selection return - # Check if the selection is a multiline string - try: - # Attempt to parse the selection as a string literal - literal = ast.literal_eval(selection) - if isinstance(literal, str): - yield selection - return - except (ValueError, SyntaxError): - pass - # Remove blank lines within the selection to prevent the REPL from thinking the block is finished. lines = (line for line in split_lines(selection) if line.strip() != "")