[PATCH 1 of 6] sortdict: have update() accept either dict or iterable of key/value pairs

Angel Ezquerra angel.ezquerra at gmail.com
Mon Mar 9 17:24:56 CDT 2015


On Mon, Mar 9, 2015 at 2:27 PM, Yuya Nishihara <yuya at tcha.org> wrote:
> On Mon, 9 Mar 2015 00:05:00 -0700, Ryan McElroy wrote:
>> On 3/8/2015 4:56 AM, Yuya Nishihara wrote:
>> > # HG changeset patch
>> > # User Yuya Nishihara <yuya at tcha.org>
>> > # Date 1424267633 -32400
>> > #      Wed Feb 18 22:53:53 2015 +0900
>> > # Node ID 023d0f46318665e8d01fe42fb58ac1726532b4c0
>> > # Parent  62c4a963489d0ff8887b1e5d2c9458d1e3384536
>> > sortdict: have update() accept either dict or iterable of key/value pairs
>> I'm always skeptical about making APIs accept more things -- it makes
>> the code harder to understand and change in the future. I'd prefer that
>> all callers of this function be changed to pass key-value pair
>> iterables.
>
> I agree with you in general, but Python dict accepts both. Our sortdict should
> be the same.

I agree with Yuya. The sortdict class is basically mercurial's 2.4
compatible OrderedDict. As a dict-like class it makes a lot of sense
for its update method to acceot the same sort of inputs as a regular
dict, that is dicts or an iterable of key, value pairs.

Angel


More information about the Mercurial-devel mailing list