Patchwork [3,of,7] formatter: convert float value to json

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 17, 2014, 3:11 p.m.
Message ID <0bddd08bf12d7e2c4ad8.1410966684@mimosa>
Download mbox | patch
Permalink /patch/5846/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 17, 2014, 3:11 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1410960061 -32400
#      Wed Sep 17 22:21:01 2014 +0900
# Node ID 0bddd08bf12d7e2c4ad8f7fa2bd8c87dcfaab0a4
# Parent  97d8605b1d91dad17643b7e34a740781c947a8af
formatter: convert float value to json

It will be used to encode ctx.data().
Yuya Nishihara - Sept. 17, 2014, 3:15 p.m.
On Thu, 18 Sep 2014 00:11:24 +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1410960061 -32400
> #      Wed Sep 17 22:21:01 2014 +0900
> # Node ID 0bddd08bf12d7e2c4ad8f7fa2bd8c87dcfaab0a4
> # Parent  97d8605b1d91dad17643b7e34a740781c947a8af
> formatter: convert float value to json
> 
> It will be used to encode ctx.data().

Oops, typo of "ctx.date()".

Patch

diff --git a/mercurial/formatter.py b/mercurial/formatter.py
--- a/mercurial/formatter.py
+++ b/mercurial/formatter.py
@@ -91,8 +91,8 @@  class pickleformatter(baseformatter):
 def _jsonifyobj(v):
     if isinstance(v, tuple):
         return '[' + ', '.join(_jsonifyobj(e) for e in v) + ']'
-    elif isinstance(v, int):
-        return '%d' % v
+    elif isinstance(v, (int, float)):
+        return str(v)
     else:
         return '"%s"' % encoding.jsonescape(v)