[Python-ideas] Have dict().update() return its own reference.

Stefan Behnel stefan_ml at behnel.de
Sat Apr 21 15:40:37 CEST 2012


Masklinn, 21.04.2012 14:53:
> On 2012-04-21, at 02:24 , Steven D'Aprano wrote:
>> Masklinn wrote:
>>> An other potential weirdness of this solution — I don't know how ChainMap
>>> behaves there, the documentation is unclear — is iteration over the map
>>> and mapping.items() versus [(key, mapping[key]) for key in mapping]
>>> potentially having very different behaviors/values since the former is
>>> going to return all key:value pairs but the latter is only going to return
>>> the key:(first value for key) pairs which may lead to significant repetitions
>>> any time a key is present in multiple contexts.
>>
>> No, iteration over the ChainMap returns unique keys, not duplicates.
> 
> Ah, that's good. Would probably warrant mention in the documentation though.

What would you want to see there? "This class works as expected even when
iterating over it"?

Stefan




More information about the Python-ideas mailing list