Skip to content

Commit 9a2913e

Browse files
committed
py/objlist: Make list += accept all arguments and add test.
1 parent c6926c3 commit 9a2913e

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

py/objlist.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,6 @@ STATIC mp_obj_t list_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) {
121121
return MP_OBJ_UNCAST(s);
122122
}
123123
case MP_BINARY_OP_INPLACE_ADD: {
124-
if (!MP_OBJ_IS_TYPE(rhs, &mp_type_list)) {
125-
return MP_OBJ_NULL; // op not supported
126-
}
127124
list_extend(lhs, rhs);
128125
return lhs;
129126
}

tests/basics/list_extend.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# test list.__iadd__ and list.extend (they are equivalent)
2+
3+
l = [1, 2]
4+
l.extend([])
5+
print(l)
6+
7+
l.extend([3])
8+
print(l)
9+
10+
l.extend([4, 5])
11+
print(l)
12+
13+
l.extend(range(6, 10))
14+
print(l)
15+
16+
l.extend("abc")
17+
print(l)
18+
19+
l = [1, 2]
20+
l += []
21+
print(l)
22+
23+
l += [3]
24+
print(l)
25+
26+
l += [4, 5]
27+
print(l)
28+
29+
l += range(6, 10)
30+
print(l)
31+
32+
l += "abc"
33+
print(l)

0 commit comments

Comments
 (0)