Patchwork [2,of,2] formatter: use dict.update() to set arguments passed to write functions

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 26, 2015, 5:27 a.m.
Message ID <7a6f477ee7ffac05e01d.1443245277@mimosa>
Download mbox | patch
Permalink /patch/10653/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 26, 2015, 5:27 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1443012887 -32400
#      Wed Sep 23 21:54:47 2015 +0900
# Node ID 7a6f477ee7ffac05e01db296a2a71cc56bece8ba
# Parent  bca566c50dc08a27c25d28cc138bc8197b2b7c5b
formatter: use dict.update() to set arguments passed to write functions

This isn't important, but update() is better than loop in general.
Pierre-Yves David - Sept. 28, 2015, 9:32 a.m.
On 09/25/2015 10:27 PM, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1443012887 -32400
> #      Wed Sep 23 21:54:47 2015 +0900
> # Node ID 7a6f477ee7ffac05e01db296a2a71cc56bece8ba
> # Parent  bca566c50dc08a27c25d28cc138bc8197b2b7c5b
> formatter: use dict.update() to set arguments passed to write functions\\\

Series pushed to the clowncopter, thanks.

Patch

diff --git a/mercurial/formatter.py b/mercurial/formatter.py
--- a/mercurial/formatter.py
+++ b/mercurial/formatter.py
@@ -50,14 +50,12 @@  class baseformatter(object):
         '''do default text output while assigning data to item'''
         fieldkeys = fields.split()
         assert len(fieldkeys) == len(fielddata)
-        for k, v in zip(fieldkeys, fielddata):
-            self._item[k] = v
+        self._item.update(zip(fieldkeys, fielddata))
     def condwrite(self, cond, fields, deftext, *fielddata, **opts):
         '''do conditional write (primarily for plain formatter)'''
         fieldkeys = fields.split()
         assert len(fieldkeys) == len(fielddata)
-        for k, v in zip(fieldkeys, fielddata):
-            self._item[k] = v
+        self._item.update(zip(fieldkeys, fielddata))
     def plain(self, text, **opts):
         '''show raw text for non-templated mode'''
         pass