[issue34586] collections.ChainMap should have a get_where method

Raymond Hettinger report at bugs.python.org
Fri Sep 7 04:00:45 EDT 2018


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

> I would argue that all of the examples would benefit from error
> checking done along the lines of the snippet above.

ISTM that this is the wrong stage to perform validation of allowable values.  That should occur upstream when the underlying mappings are first created.  At that earlier stage it possible to give a more timely response to erroneous input and there is access to more information (such as the line and row number of an error in a configuration file).  

It doesn't make sense to me to defer value validation downstream after a ChainMap instance has been formed and after a successful lookup has occurred. That just complicates the task of tracing back to the root cause.

> Maybe the method could be called ChainMap.search?

That would be better than get_where().

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34586>
_______________________________________


More information about the Python-bugs-list mailing list