This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients Zahari.Dim, rhettinger, serhiy.storchaka
Date 2018-09-08.12:15:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1536408954.81.0.56676864532.issue34586@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-09-08 12:15:54serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger, Zahari.Dim
2018-09-08 12:15:54serhiy.storchakasetmessageid: <1536408954.81.0.56676864532.issue34586@psf.upfronthosting.co.za>
2018-09-08 12:15:54serhiy.storchakalinkissue34586 messages
2018-09-08 12:15:54serhiy.storchakacreate