New submission from Kim-Adeline Miguel <kimig...@microsoft.com>:
(See #33234) Recently we added Python 3.8 to our CI test matrix, and we noticed a possible backward incompatibility with the list() constructor. We found that __len__ is getting called twice, while before 3.8 it was only called once. Here's an example: class Foo: def __iter__(self): print("iter") return iter([3, 5, 42, 69]) def __len__(self): print("len") return 4 Calling list(Foo()) using Python 3.7 prints: iter len But calling list(Foo()) using Python 3.8 prints: len iter len It looks like this behaviour was introduced for #33234 with PR GH-9846. We realize that this was merged a while back, but at least we wanted to make the team aware of this change in behaviour. ---------- components: Interpreter Core messages: 363186 nosy: brett.cannon, eric.snow, kimiguel, pablogsal, rhettinger priority: normal severity: normal status: open title: __len__ called twice in the list() constructor type: behavior versions: Python 3.8, Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39829> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com