[PATCH 1 of 2] py3: conditionalize the raise statement

Yuya Nishihara yuya at tcha.org
Tue Aug 9 11:49:09 EDT 2016


On Mon, 08 Aug 2016 14:05:37 -0500, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit at gmail.com>
> # Date 1470680471 -19800
> #      Mon Aug 08 23:51:11 2016 +0530
> # Node ID 9a344ce563ce2221bdfc9031b8f249d9da2f08b0
> # Parent  37b6f0ec6241a62de90737409458cd622e2fac0d
> py3: conditionalize the raise statement
> 
> raise E,V,T is not acceptable in Python 3, thats is conditionalized.
> Moreover this will result in syntax error so we have to use exec() to
> execute this. Related PEP- https://www.python.org/dev/peps/pep-3109/#id14
> 
> Moreover this patch also contain an update to test-check-py3-compat.t
> 
> diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
> --- a/mercurial/bundle2.py
> +++ b/mercurial/bundle2.py
> @@ -989,7 +989,10 @@
>              outdebug(ui, 'closing payload chunk')
>              # abort current part payload
>              yield _pack(_fpayloadsize, 0)
> -            raise exc_info[0], exc_info[1], exc_info[2]
> +            if sys.version_info[0] >= 3:
> +                raise exc_info[0](exc_info[1]).with_traceback(exc_info[2])
> +            else:
> +                exec("""raise exc_info[0], exc_info[1], exc_info[2]""")

This would be better fit for import-time hack, but it wouldn't be easy to
process at token level. So I'm okay for this change, though exec() would add
extra frame to traceback.

Any ideas?


More information about the Mercurial-devel mailing list