Patchwork [1,of,7] formatter: support json formatting of long type

login
register
mail settings
Submitter Gregory Szorc
Date March 14, 2017, 5:15 a.m.
Message ID <f6f1f5efe05f4e3737dc.1489468543@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/19317/
State Accepted
Headers show

Comments

Gregory Szorc - March 14, 2017, 5:15 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1489455089 25200
#      Mon Mar 13 18:31:29 2017 -0700
# Node ID f6f1f5efe05f4e3737dc198284f548e31a616f4b
# Parent  1c48a8278b2f015fca607dfc652823560a5ac580
formatter: support json formatting of long type

By luck, we appear to not pass any long instances into
the JSON formatter. I suspect this will change with all the
Python 3 porting work. Plus I have another series that will
convert some ints to longs that triggers this.
Yuya Nishihara - March 14, 2017, 8:19 a.m.
On Mon, 13 Mar 2017 22:15:43 -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1489455089 25200
> #      Mon Mar 13 18:31:29 2017 -0700
> # Node ID f6f1f5efe05f4e3737dc198284f548e31a616f4b
> # Parent  1c48a8278b2f015fca607dfc652823560a5ac580
> formatter: support json formatting of long type
> 
> By luck, we appear to not pass any long instances into
> the JSON formatter. I suspect this will change with all the
> Python 3 porting work. Plus I have another series that will
> convert some ints to longs that triggers this.
> 
> diff --git a/mercurial/formatter.py b/mercurial/formatter.py
> --- a/mercurial/formatter.py
> +++ b/mercurial/formatter.py
> @@ -295,7 +295,7 @@ def _jsonifyobj(v):
>          return 'true'
>      elif v is False:
>          return 'false'
> -    elif isinstance(v, (int, float)):
> +    elif isinstance(v, (int, long, float)):
>          return str(v)

Looks okay, but we'll need to export long on Python 3, by pycompat or code
transformer.
Gregory Szorc - March 14, 2017, 4 p.m.
On Tue, Mar 14, 2017 at 1:19 AM, Yuya Nishihara <yuya@tcha.org> wrote:

> On Mon, 13 Mar 2017 22:15:43 -0700, Gregory Szorc wrote:
> > # HG changeset patch
> > # User Gregory Szorc <gregory.szorc@gmail.com>
> > # Date 1489455089 25200
> > #      Mon Mar 13 18:31:29 2017 -0700
> > # Node ID f6f1f5efe05f4e3737dc198284f548e31a616f4b
> > # Parent  1c48a8278b2f015fca607dfc652823560a5ac580
> > formatter: support json formatting of long type
> >
> > By luck, we appear to not pass any long instances into
> > the JSON formatter. I suspect this will change with all the
> > Python 3 porting work. Plus I have another series that will
> > convert some ints to longs that triggers this.
> >
> > diff --git a/mercurial/formatter.py b/mercurial/formatter.py
> > --- a/mercurial/formatter.py
> > +++ b/mercurial/formatter.py
> > @@ -295,7 +295,7 @@ def _jsonifyobj(v):
> >          return 'true'
> >      elif v is False:
> >          return 'false'
> > -    elif isinstance(v, (int, float)):
> > +    elif isinstance(v, (int, long, float)):
> >          return str(v)
>
> Looks okay, but we'll need to export long on Python 3, by pycompat or code
> transformer.
>

I see you queued this. I also see it doesn't break the py3 tests with
3.5.0. Furthermore, there are a handful of "long" usages throughout the
repo. So I guess I left a landmine for whoever hits this with Python 3
porting :/

Patch

diff --git a/mercurial/formatter.py b/mercurial/formatter.py
--- a/mercurial/formatter.py
+++ b/mercurial/formatter.py
@@ -295,7 +295,7 @@  def _jsonifyobj(v):
         return 'true'
     elif v is False:
         return 'false'
-    elif isinstance(v, (int, float)):
+    elif isinstance(v, (int, long, float)):
         return str(v)
     else:
         return '"%s"' % encoding.jsonescape(v)