[New-bugs-announce] [issue44741] Pattern Matching - star subpattern with a subject derived from collections.abc.Sequence

Pierre Quentel report at bugs.python.org
Mon Jul 26 10:23:39 EDT 2021


New submission from Pierre Quentel <pierre.quentel at gmail.com>:

This code

    match range(42):
        case [x, *w, y]:
            z = 0

sets w to a list with 40 items : the length of the subject, minus the number of non-star subpatterns.

But this code (adapted from test_patma_186) enters an infinite loop

    import collections.abc

    class Seq(collections.abc.Sequence):
        def __getitem__(self, i):
            print('get item', i)
            return i
        def __len__(self):
            return 42

    match Seq():
        case [x, *w, y]:
            z = 0

__getitem__ gets called forever, instead of stopping when the expected number of items in w is reached.

----------
components: Interpreter Core
messages: 398226
nosy: quentel
priority: normal
severity: normal
status: open
title: Pattern Matching - star subpattern with a subject derived from collections.abc.Sequence
type: crash
versions: Python 3.10, Python 3.11

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44741>
_______________________________________


More information about the New-bugs-announce mailing list