This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steven.daprano
Recipients Mark.Shannon, brandtbucher, gvanrossum, pablogsal, quentel, steven.daprano
Date 2021-07-26.22:51:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1627339862.42.0.882904296796.issue44741@roundup.psfhosted.org>
In-reply-to
Content
How is this not a regression? And a very serious one by the sound of it. All the examples that are said to go into an infinite loop work fine in 3.9.

(Obviously I can't check the match statement example in 3.9.)

If the Sequence Protocol really has been dropped from Python's execution model, shouldn't there be a PEP for such a major change in behaviour? Legacy or not, it is still a part of the language.

At the very least, the examples shouldn't swallow the IndexError and go into an infinite loop.

Brandt said:

> the destructuring is basically the same as if you had written:
> 
> [x, *w, y] = Seq()
> 
> ...which also hangs.


It works fine in 3.9, with or without inheriting from the Sequence ABC.

# Python 3.9
>>> class A:
...     def __len__(self):
...             return 5
...     def __getitem__(self, i):
...             print(i)
...             if i < 5:
...                     return i
...             raise IndexError
... 
>>> [x, *y, z] = A()
0
1
2
3
4
5
>>> x, y, z
(0, [1, 2, 3], 4)


Likewise for list(A()), etc.

The __len__ method isn't needed for iteration to work correctly. I just included it to match Pierre's example.

Inheriting from collections.abc.Sequence does not change the behaviour.

Still in 3.9:

>>> list(A())
0
1
2
3
4
5
[0, 1, 2, 3, 4]


I think that closing this is as Not A Bug was premature. If this isn't a bug, then I have no idea what counts as a bug any longer :-(
History
Date User Action Args
2021-07-26 22:51:02steven.dapranosetrecipients: + steven.daprano, gvanrossum, Mark.Shannon, quentel, pablogsal, brandtbucher
2021-07-26 22:51:02steven.dapranosetmessageid: <1627339862.42.0.882904296796.issue44741@roundup.psfhosted.org>
2021-07-26 22:51:02steven.dapranolinkissue44741 messages
2021-07-26 22:51:02steven.dapranocreate