Skip to content

Commit 185903d

Browse files
authored
bpo-39520: Fix un-parsing of ext slices with no dimensions (GH-18304)
1 parent 768d739 commit 185903d

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

Lib/test/test_future.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ def test_annotations(self):
256256
eq("slice[:-1]")
257257
eq("slice[1:]")
258258
eq("slice[::-1]")
259+
eq("slice[:,]")
260+
eq("slice[1:2,]")
261+
eq("slice[1:2:3,]")
262+
eq("slice[1:2, 1]")
263+
eq("slice[1:2, 2, 3]")
259264
eq("slice[()]")
260265
eq("slice[a, b:c, d:e:f]")
261266
eq("slice[(x for x in a)]")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix unparsing of ext slices with no items (``foo[:,]``). Patch by Batuhan
2+
Taskaya.

Python/ast_unparse.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,7 @@ append_ast_ext_slice(_PyUnicodeWriter *writer, slice_ty slice)
746746
APPEND_STR_IF(i > 0, ", ");
747747
APPEND(slice, (slice_ty)asdl_seq_GET(slice->v.ExtSlice.dims, i));
748748
}
749+
APPEND_STR_IF(dims_count == 1, ",");
749750
return 0;
750751
}
751752

0 commit comments

Comments
 (0)