]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39520: Fix un-parsing of ext slices with no dimensions (GH-18304)
authorBatuhan Taşkaya <47358913+isidentical@users.noreply.github.com>
Sun, 1 Mar 2020 20:07:22 +0000 (23:07 +0300)
committerGitHub <noreply@github.com>
Sun, 1 Mar 2020 20:07:22 +0000 (20:07 +0000)
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 fd468b57b477e912f9d3b131ab5d36f0144dc549..d83c47ef155910456abe6f353dcf923c3345f479 100644 (file)
@@ -256,6 +256,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 f376e86ddc4c0d87af9df3703d17c51851fe69b6..1a7cd236aafa19c5c4fb5abf458d002ac879d6f6 100644 (file)
@@ -746,6 +746,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;
 }