Patchwork hgweb: fix the MRO in Python 3

login
register
mail settings
Submitter Martijn Pieters
Date Oct. 8, 2016, 5:12 p.m.
Message ID <8475a954a40385035b57.1475946751@mjpieters-mbp>
Download mbox | patch
Permalink /patch/16959/
State Accepted
Headers show

Comments

Martijn Pieters - Oct. 8, 2016, 5:12 p.m.
# HG changeset patch
# User Martijn Pieters <mjpieters@fb.com>
# Date 1475946679 -7200
#      Sat Oct 08 19:11:19 2016 +0200
# Node ID 8475a954a40385035b57abe05af31308597a0b3c
# Parent  2c8ec8c2ddfeb2d229b81eb5b11e3639fb34b0a0
hgweb: fix the MRO in Python 3

object should appear at the end, otherwise it tries to pre-empt the other
new-style classes in the MRO, resulting in an unresolvable MRO in Py3. We still
need to include object because otherwise in 2.7 we end up with an old-style
class if threading is not supported, new-style if it is.
Pulkit Goyal - Oct. 8, 2016, 5:18 p.m.
On Sat, Oct 8, 2016 at 7:12 PM, Martijn Pieters <mj@zopatista.com> wrote:
> # HG changeset patch
> # User Martijn Pieters <mjpieters@fb.com>
> # Date 1475946679 -7200
> #      Sat Oct 08 19:11:19 2016 +0200
> # Node ID 8475a954a40385035b57abe05af31308597a0b3c
> # Parent  2c8ec8c2ddfeb2d229b81eb5b11e3639fb34b0a0
> hgweb: fix the MRO in Python 3
>
> object should appear at the end, otherwise it tries to pre-empt the other
> new-style classes in the MRO, resulting in an unresolvable MRO in Py3. We still
> need to include object because otherwise in 2.7 we end up with an old-style
> class if threading is not supported, new-style if it is.
>
> diff --git a/mercurial/hgweb/server.py b/mercurial/hgweb/server.py
> --- a/mercurial/hgweb/server.py
> +++ b/mercurial/hgweb/server.py
> @@ -263,7 +263,7 @@
>          return open(opt, 'a')
>      return default
>
> -class MercurialHTTPServer(object, _mixin, httpservermod.httpserver):
> +class MercurialHTTPServer(_mixin, httpservermod.httpserver, object):

It's an excellent one :D

>
>      # SO_REUSEADDR has broken semantics on windows
>      if os.name == 'nt':
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Pierre-Yves David - Oct. 8, 2016, 9:37 p.m.
On 10/08/2016 07:12 PM, Martijn Pieters wrote:
> # HG changeset patch
> # User Martijn Pieters <mjpieters@fb.com>
> # Date 1475946679 -7200
> #      Sat Oct 08 19:11:19 2016 +0200
> # Node ID 8475a954a40385035b57abe05af31308597a0b3c
> # Parent  2c8ec8c2ddfeb2d229b81eb5b11e3639fb34b0a0
> hgweb: fix the MRO in Python 3
>
> object should appear at the end, otherwise it tries to pre-empt the other
> new-style classes in the MRO, resulting in an unresolvable MRO in Py3. We still
> need to include object because otherwise in 2.7 we end up with an old-style
> class if threading is not supported, new-style if it is.

Pushed, thanks
timeless - Oct. 21, 2016, 1:08 p.m.
Is there a checkcode test for this?
Martijn Pieters - Oct. 21, 2016, 1:11 p.m.
On 21 Oct 2016, at 14:08, timeless <timeless@gmail.com> wrote:
> Is there a checkcode test for this?

No, but tests simply fail when you make this mistake. In this *specific case* that was only visible in the Python 3 tests because the base classes used in Python 2 were old-style classes, so in *Python 2* the base class order happened to be legal.

Martijn
timeless - Oct. 26, 2016, 8:15 p.m.
> Is there a checkcode test for this?

Martijn Pieters wrote:
> No, but tests simply fail when you make this mistake.
> In this *specific case* that was only visible in the Python 3 tests because the base classes used in Python 2 were old-style classes, so in *Python 2* the base class order happened to be legal.

I'm asking because I'm pretty sure I played w/ this specific glob of
code, and, from memory, the error messages weren't the easiest to
decipher. check-code warnings tend to be much easier for me to work
from to get to correct code.

But it doesn't sound like this is usually something that's easily
identified, so I'll drop the question.

Patch

diff --git a/mercurial/hgweb/server.py b/mercurial/hgweb/server.py
--- a/mercurial/hgweb/server.py
+++ b/mercurial/hgweb/server.py
@@ -263,7 +263,7 @@ 
         return open(opt, 'a')
     return default
 
-class MercurialHTTPServer(object, _mixin, httpservermod.httpserver):
+class MercurialHTTPServer(_mixin, httpservermod.httpserver, object):
 
     # SO_REUSEADDR has broken semantics on windows
     if os.name == 'nt':