[PATCH] cbor: teach the encoder to handle python `long` type for Windows

Gregory Szorc gregory.szorc at gmail.com
Tue Sep 4 22:59:38 EDT 2018


On Tue, Sep 4, 2018 at 7:33 PM Matt Harbison <mharbison72 at gmail.com> wrote:

> # HG changeset patch
> # User Matt Harbison <matt_harbison at yahoo.com>
> # Date 1536114578 14400
> #      Tue Sep 04 22:29:38 2018 -0400
> # Node ID 5a44192e15a600f244ee7b77a77a2add7731b61c
> # Parent  197521083166579f6c80d7532ec6e919af2fe2cf
> cbor: teach the encoder to handle python `long` type for Windows
>
> The tests for 2**32 and -7000000000 were blowing up, complaining about not
> knowing how to encode type 'long'.  sys.maxint tops out at 2**31-1 on
> Windows,
> but I guess is 2^63-1 on Linux?  I *think* we're OK on the decode side, as
> there
> is an assertion that the decoded value is equal to the original primitive
> value.
>
> diff --git a/mercurial/utils/cborutil.py b/mercurial/utils/cborutil.py
> --- a/mercurial/utils/cborutil.py
> +++ b/mercurial/utils/cborutil.py
> @@ -190,6 +190,7 @@ def streamencodenone(v):
>  STREAM_ENCODERS = {
>      bytes: streamencodebytestring,
>      int: streamencodeint,
> +    long: streamencodeint,
>

This is the reasonable thing to do. However, `long` is not a type on Python
3. So we need to make this conditional on the presence of the `long` type.
But we don't seem to have `long` aliased in pycompat. Maybe we should? Or
you could add a `try...except NameError` block below this dict and swallow
the exception if `long` doesn't exist?


>      list: streamencodearray,
>      tuple: streamencodearray,
>      dict: streamencodemap,
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20180904/ccf81136/attachment.html>


More information about the Mercurial-devel mailing list