[issue17939] Misleading information about slice assignment in docs

New submission from Stefan Chrobot: http://docs.python.org/3/reference/simple_stmts.html#assignment-statements The docs says: "If the target is a slicing: The primary expression in the reference is evaluated. It should yield a mutable sequence object (such as a list). The assigned object should be a sequence object of the same type." This seems wrong, because the assigned object can be any iterable: a = [4, 5, 6] a[0:0] = range(1, 4) # a is now [1, 2, 3, 4, 5, 6] ---------- assignee: docs@python components: Documentation messages: 188738 nosy: docs@python, stefanchrobot priority: normal severity: normal status: open title: Misleading information about slice assignment in docs type: enhancement versions: Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17939> _______________________________________

Changes by Ezio Melotti <ezio.melotti@gmail.com>: ---------- nosy: +ezio.melotti _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17939> _______________________________________

Terry J. Reedy added the comment: Since range objects have a known length, that example is not enough to show 'any iterable'. However, generators do not even have a __length_hint__ and they work too. a = [1,2,3] a[0:1] = (i for i in range(4)) print(a)
[0, 1, 2, 3, 2, 3]
---------- nosy: +terry.reedy _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17939> _______________________________________

Change by Irit Katriel <iritkatriel@yahoo.com>: ---------- versions: +Python 3.10, Python 3.8, Python 3.9 -Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue17939> _______________________________________
participants (4)
-
Ezio Melotti
-
Irit Katriel
-
Stefan Chrobot
-
Terry J. Reedy