Message363186
(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. |
|
Date |
User |
Action |
Args |
2020-03-02 15:36:16 | kimiguel | set | recipients:
+ kimiguel, brett.cannon, rhettinger, eric.snow, pablogsal |
2020-03-02 15:36:16 | kimiguel | set | messageid: <1583163376.54.0.165592229385.issue39829@roundup.psfhosted.org> |
2020-03-02 15:36:16 | kimiguel | link | issue39829 messages |
2020-03-02 15:36:16 | kimiguel | create | |
|