[Python-ideas] ChainMap as a context manager

dag.odenhall at gmail.com dag.odenhall at gmail.com
Mon Aug 8 05:43:44 CEST 2011


On 7 August 2011 17:02, Mike Graham <mikegraham at gmail.com> wrote:
> On Sun, Aug 7, 2011 at 10:50 AM, dag.odenhall at gmail.com
> <dag.odenhall at gmail.com> wrote:
>> How about adding the context manager protocol to collections.ChainMap,
>> as an in-place combination of new_child() and parents()? The effect
>> would simulate lexical scope using the with-statement.
>>
>> Trivial to do customly but always nice when builtin or stdlib types
>> support the context manager protocol. :)
>
> I don't understand the utility of such a thing. Can you post a use
> case or two to make it clearer to people like me?

To be quite honest I'm not perfectly sure myself; it just seemed like
such a natural context manager that I got curious if it was just
overlooked or if I was missing something. If it turns out it would
make sense it might be good to realize it early before the 3.3
release?



More information about the Python-ideas mailing list