Skip to content

Commit d0837d2

Browse files
bpo-39520: Fix un-parsing of ext slices with no dimensions (GH-18304)
(cherry picked from commit 185903d) Co-authored-by: Batuhan Taşkaya <[email protected]>
1 parent b1b1d5f commit d0837d2

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
@@ -245,6 +245,11 @@ def test_annotations(self):
245245
eq("slice[:-1]")
246246
eq("slice[1:]")
247247
eq("slice[::-1]")
248+
eq("slice[:,]")
249+
eq("slice[1:2,]")
250+
eq("slice[1:2:3,]")
251+
eq("slice[1:2, 1]")
252+
eq("slice[1:2, 2, 3]")
248253
eq("slice[()]")
249254
eq("slice[a, b:c, d:e:f]")
250255
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
@@ -739,6 +739,7 @@ append_ast_ext_slice(_PyUnicodeWriter *writer, slice_ty slice)
739739
APPEND_STR_IF(i > 0, ", ");
740740
APPEND(slice, (slice_ty)asdl_seq_GET(slice->v.ExtSlice.dims, i));
741741
}
742+
APPEND_STR_IF(dims_count == 1, ",");
742743
return 0;
743744
}
744745

0 commit comments

Comments
 (0)