Merge ~cjwatson/launchpad:py3-importpedant into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 39ccb6adb62049403f9bc8acb262c3c3a61f87c9
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:py3-importpedant
Merge into: launchpad:master
Diff against target: 22 lines (+3/-1)
1 file modified
lib/lp/scripts/utilities/importpedant.py (+3/-1)
Reviewer Review Type Date Requested Status
Thiago F. Pappacena (community) Approve
Review via email: mp+387772@code.launchpad.net

Commit message

Fix import_pedant for Python 3

Description of the change

As of Python 3.3, the default value for the "level" argument to __import__ is 0, and the previous default of -1 (i.e. attempt both absolute and relative imports) is no longer supported.

To post a comment you must log in.
Revision history for this message
Thiago F. Pappacena (pappacena) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/scripts/utilities/importpedant.py b/lib/lp/scripts/utilities/importpedant.py
2index bae2269..e332df7 100644
3--- a/lib/lp/scripts/utilities/importpedant.py
4+++ b/lib/lp/scripts/utilities/importpedant.py
5@@ -8,6 +8,7 @@ import itertools
6 from operator import attrgetter
7 import types
8
9+import six
10 from six.moves import builtins
11
12
13@@ -183,7 +184,8 @@ class NotFoundPolicyViolation(PedantDisagreesError):
14 # The names of the arguments form part of the interface of __import__(...),
15 # and must not be changed, as code may choose to invoke __import__ using
16 # keyword arguments - e.g. the encodings module in Python 2.6.
17-def import_pedant(name, globals={}, locals={}, fromlist=[], level=-1):
18+def import_pedant(name, globals={}, locals={}, fromlist=[],
19+ level=(0 if six.PY3 else -1)):
20 global naughty_imports
21
22 module = original_import(name, globals, locals, fromlist, level)

Subscribers

People subscribed via source and target branches

to status/vote changes: