Serhiy Storchaka <[email protected]> added the comment:
I concur with Raymond. The purpose of ChainMap is providing a mapping that
hides the implementation detail of using several mappings as fallbacks. If you
don't want to hide the implementation detail, you don't need to use ChainMap.
ChainMap exposes underlying mappings as the maps attribute, so you can use this
implementation detail if you know that it is a ChainMap an not a general
mapping. It is easy to write a code for searching what mapping contains the
specified key.
for m in cm.maps:
if key in m:
found = m
break
else:
# raise an error or set a default,
# what is appropriate for your concrete case
or even
found = next(m for m in cm.maps if key in m)
if the key is always found or StopIteration is appropriate.
I don't think that such trivial snatch of code is worth adding a special
ChainMap method or even documenting it explicitly in the ChainMap documentation.
----------
nosy: +serhiy.storchaka
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue34586>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com