Pablo Galindo Salgado <pablog...@gmail.com> added the comment:
I don't think there is anything technically wrong here. The Seq class is relying on the legacy version of the iterator protocol, which specifies that you need to raise IndexError there to stop the iteration. For instance, this version works: import collections.abc class Seq(collections.abc.Sequence): def __getitem__(self, i): if i >= len(self): raise IndexError return i def __len__(self): return 42 match Seq(): case [x, *w, y]: z = 0 print(z) Also, one could argue that Seq has exactly the same problem all over the language. For instance >> list(Seq()) will hang >> [x,*y] = Seq() will hang and so on and so forth. So, if I am a user and I am trying to **predict** how this would behave based on these two experiments my conclusion would be: "Anything that tries to iterate on this thing will hang" I think that whatever we do, we should make it *predictable* and consistency across the language, and IMHO only fixing it in pattern matching doesn't make it predictable. Being said that, I don't think these use cases justifies a major overhaul of how this behaves everywhere. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue44741> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com