Patchwork [v3] py3: handle meta-path finders that only use pre-python3.4 API

login
register
mail settings
Submitter Ludovic Chabant
Date April 28, 2019, 4:18 a.m.
Message ID <3611368a1af3037427eb.1556425125@devahi>
Download mbox | patch
Permalink /patch/39851/
State Accepted
Headers show

Comments

Ludovic Chabant - April 28, 2019, 4:18 a.m.
# HG changeset patch
# User Ludovic Chabant <ludovic@chabant.com>
# Date 1555683918 0
#      Fri Apr 19 14:25:18 2019 +0000
# Branch stable
# Node ID 3611368a1af3037427eb59635c7dad8dab67c606
# Parent  4a8d9ed864754837a185a642170cde24392f9abf
py3: handle meta-path finders that only use pre-python3.4 API
Yuya Nishihara - April 28, 2019, 8:08 a.m.
On Sun, 28 Apr 2019 04:18:45 +0000, Ludovic Chabant wrote:
> # HG changeset patch
> # User Ludovic Chabant <ludovic@chabant.com>
> # Date 1555683918 0
> #      Fri Apr 19 14:25:18 2019 +0000
> # Branch stable
> # Node ID 3611368a1af3037427eb59635c7dad8dab67c606
> # Parent  4a8d9ed864754837a185a642170cde24392f9abf
> py3: handle meta-path finders that only use pre-python3.4 API

Queued, thanks.

Patch

diff --git a/mercurial/__init__.py b/mercurial/__init__.py
--- a/mercurial/__init__.py
+++ b/mercurial/__init__.py
@@ -54,7 +54,16 @@ 
                 if finder == self:
                     continue
 
-                spec = finder.find_spec(fullname, path, target=target)
+                # Originally the API was a `find_module` method, but it was
+                # renamed to `find_spec` in python 3.4, with a new `target`
+                # argument.
+                find_spec_method = getattr(finder, 'find_spec', None)
+                if find_spec_method:
+                    spec = find_spec_method(fullname, path, target=target)
+                else:
+                    spec = finder.find_module(fullname)
+                    if spec is not None:
+                        spec = importlib.util.spec_from_loader(fullname, spec)
                 if spec:
                     break