summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--py/repl.c11
-rw-r--r--tests/basics/list_sort.py15
2 files changed, 24 insertions, 2 deletions
diff --git a/py/repl.c b/py/repl.c
index 412ab2008..bca1be584 100644
--- a/py/repl.c
+++ b/py/repl.c
@@ -29,10 +29,11 @@ bool mp_repl_is_compound_stmt(const char *line) {
return true;
}
- // also "compound" if unmatched open bracket
+ // also "compound" if unmatched open bracket or triple quote
int n_paren = 0;
int n_brack = 0;
int n_brace = 0;
+ int in_triple_quote = 0;
for (const char *l = line; *l; l++) {
switch (*l) {
case '(': n_paren += 1; break;
@@ -41,9 +42,15 @@ bool mp_repl_is_compound_stmt(const char *line) {
case ']': n_brack -= 1; break;
case '{': n_brace += 1; break;
case '}': n_brace -= 1; break;
+ case '"':
+ if (l[1] == '"' && l[2] == '"') {
+ l += 2;
+ in_triple_quote = 1 - in_triple_quote;
+ }
+ break;
}
}
- return n_paren > 0 || n_brack > 0 || n_brace > 0;
+ return n_paren > 0 || n_brack > 0 || n_brace > 0 || in_triple_quote != 0;
}
#endif // MICROPY_ENABLE_REPL_HELPERS
diff --git a/tests/basics/list_sort.py b/tests/basics/list_sort.py
index eff12b9c8..e323ff1c2 100644
--- a/tests/basics/list_sort.py
+++ b/tests/basics/list_sort.py
@@ -1,13 +1,28 @@
l = [1, 3, 2, 5]
+
print(l)
+print(sorted(l))
l.sort()
print(l)
+print(l == sorted(l))
+
+print(sorted(l, key=lambda x: -x))
l.sort(key=lambda x: -x)
print(l)
+print(l == sorted(l, key=lambda x: -x))
+
+print(sorted(l, key=lambda x: -x, reverse=True))
l.sort(key=lambda x: -x, reverse=True)
print(l)
+print(l == sorted(l, key=lambda x: -x, reverse=True))
+
+print(sorted(l, reverse=True))
l.sort(reverse=True)
print(l)
+print(l == sorted(l, reverse=True))
+
+print(sorted(l, reverse=False))
l.sort(reverse=False)
print(l)
+print(l == sorted(l, reverse=False))