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 Zahari.Dim
Recipients Zahari.Dim, rhettinger
Date 2018-09-06.10:20:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <CANx7HSYzRXZruKu4eDH5gvyqNP8BONbFVnmxWyupTbS=FodTGQ@mail.gmail.com>
In-reply-to <1536210430.89.0.56676864532.issue34586@psf.upfronthosting.co.za>
Content
I believe an argument for including this functionality in the standard library
is that it facilitates writing better error messages and thus better code. Some
results that are returned when one searches for *python ChainMap* are:

  - <https://stackoverflow.com/questions/23392976/what-is-the-purpose-of-collections-chainmap>
  - <http://www.blog.pythonlibrary.org/2016/03/29/python-201-what-is-a-chainmap/>
  - <http://rahmonov.me/posts/python-chainmap/>

All of these mention prominently a layered configuration of some kind. I would
argue that all of the examples would benefit from error checking done along the
lines of the snippet above.

An additional consideration is that the method is best implemented by copying
the `__getitem__` method, which, while short, contains a couple of non trivial
details.

One analog could be `re.search`, which returns an object with information of
both the value that is found and its location, though the `span` attribute of
the Match object. Maybe the method could be called ChainMap.search?
On Thu, Sep 6, 2018 at 6:07 AM Raymond Hettinger <report@bugs.python.org> wrote:
>
>
> Raymond Hettinger <raymond.hettinger@gmail.com> added the comment:
>
> I haven't run across this requirement before but it does seem plausible that a person might want to know which underlying mapping found a match (compare with the "which" utility in Bash). On the other hand, we haven't had requests for anything like this for other lookup chains such as determining where a variable appears in the sequence locals-to-nested-scopes-to-globals-to-builtins.
>
> Also, I'm not sure I like the proposed API (the method name and signature).  Perhaps, this should be a docs recipe for a ChainMap subclass or be an example of a standalone search function that the takes the *maps* attribute as one of its arguments.  Will discuss this with the other core devs to get their thoughts.
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue34586>
> _______________________________________
History
Date User Action Args
2018-09-06 10:20:59Zahari.Dimsetrecipients: + Zahari.Dim, rhettinger
2018-09-06 10:20:59Zahari.Dimlinkissue34586 messages
2018-09-06 10:20:59Zahari.Dimcreate