New submission from Andreas Poehlmann <andr...@poehlmann.io>:

Hello,

I encountered an issue with collections.ChainMap, that was introduced when 
https://bugs.python.org/issue32792 got fixed.

Iterating a ChainMap will call __getitem__ on its underlying maps:


>>> from collections import UserDict, ChainMap
>>> class MyDict(UserDict):
...     def __getitem__(self, k):
...         print("expensive computation", k)
...         return super().__getitem__(k)
... 
>>> set(ChainMap(MyDict(a=1, b=2, c=3)))
expensive computation a
expensive computation b
expensive computation c
{'c', 'b', 'a'}

----------
components: Library (Lib)
messages: 381971
nosy: ap--
priority: normal
severity: normal
status: open
title: collections.ChainMap.__iter__ calls __getitem__ on underlying maps
type: behavior
versions: Python 3.10, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue42487>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to