[New-bugs-announce] [issue34494] simple "sequence" class ignoring __len__

Tyler Reddy report at bugs.python.org
Sat Aug 25 01:26:30 EDT 2018

New submission from Tyler Reddy <treddy at dal.ca>:

Downstream in NumPy we've noticed that a "sequence" object defined as below will hang (infinite __getitem__ calls) if we try to turn it into an array. The same holds in CPython for converting it to a list:

class OneList:

    def __len__(self):
        # this won't be checked by
        # PySequence_Fast and several
        # over C API calls
        return 1

    def __getitem__(self, x):
        # called indefinitely by
        # i.e., PySequence_Fast
        return 1

Just to confirm -- this is intentional / desired behavior:

list(OneList()) should hang in CPython?


messages: 324037
nosy: treddy
priority: normal
severity: normal
status: open
title: simple "sequence" class ignoring __len__
type: behavior
versions: Python 3.6

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list