]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39520: Fix un-parsing of ext slices with no dimensions (GH-18304)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 11 Mar 2020 20:16:36 +0000 (13:16 -0700)
committerGitHub <noreply@github.com>
Wed, 11 Mar 2020 20:16:36 +0000 (13:16 -0700)
(cherry picked from commit 185903de12de8837bf0dc0008a16e5e56c66a019)

Co-authored-by: Batuhan Taşkaya <47358913+isidentical@users.noreply.github.com>
Lib/test/test_future.py
Misc/NEWS.d/next/Core and Builtins/2020-02-02-00-12-07.bpo-39520.uicBq6.rst [new file with mode: 0644]
Python/ast_unparse.c

index 70da0cf57040603c1cbf43261da3be0eec9a7c13..2aed01095aa7eec4d313ee7b95e85c3dc235ade0 100644 (file)
@@ -245,6 +245,11 @@ class AnnotationsFutureTestCase(unittest.TestCase):
         eq("slice[:-1]")
         eq("slice[1:]")
         eq("slice[::-1]")
+        eq("slice[:,]")
+        eq("slice[1:2,]")
+        eq("slice[1:2:3,]")
+        eq("slice[1:2, 1]")
+        eq("slice[1:2, 2, 3]")
         eq("slice[()]")
         eq("slice[a, b:c, d:e:f]")
         eq("slice[(x for x in a)]")
diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-02-02-00-12-07.bpo-39520.uicBq6.rst b/Misc/NEWS.d/next/Core and Builtins/2020-02-02-00-12-07.bpo-39520.uicBq6.rst
new file mode 100644 (file)
index 0000000..dec6765
--- /dev/null
@@ -0,0 +1,2 @@
+Fix unparsing of ext slices with no items (``foo[:,]``). Patch by Batuhan
+Taskaya.
index 43453f567b05a151eed9fce2b178a06bbe2fa015..93b3ecffb017ed9d179fcdc491a15bc1aec72a9c 100644 (file)
@@ -739,6 +739,7 @@ append_ast_ext_slice(_PyUnicodeWriter *writer, slice_ty slice)
         APPEND_STR_IF(i > 0, ", ");
         APPEND(slice, (slice_ty)asdl_seq_GET(slice->v.ExtSlice.dims, i));
     }
+    APPEND_STR_IF(dims_count == 1, ",");
     return 0;
 }