Bug 1554186: Fix Python 3 negative import level error r=glandium

Negative value for import level is obsolete in Python 3, which was used on Py2 for implicit relative import. This change ensures the level value to be >=0 on Py3 to fix test failures.

Differential Revision: https://phabricator.services.mozilla.com/D32497

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Kagami Sascha Rosylight 2019-05-29 07:58:19 +00:00
parent 328093cc71
commit 4d696c5df3

View File

@ -388,6 +388,9 @@ class ImportHook(object):
def __call__(self, name, globals=None, locals=None, fromlist=None,
level=-1):
if sys.version_info[0] >= 3 and level < 0:
level = 0
# name might be a relative import. Instead of figuring out what that
# resolves to, which is complex, just rely on the real import.
# Since we don't know the full module name, we can't check sys.modules,