mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix fake importer for Python 3
Python 3 does not appear to pass all values to the `__import__` builtin when they do not differ from the defaults. Therefore, the fake import fails because of missing positional args. This fix simply uses the defaults from Python 2 and 3's `__import__` builtin.
This commit is contained in:
parent
016ffbe7f8
commit
7d6b679ac4
1 changed files with 6 additions and 2 deletions
|
@ -437,7 +437,12 @@ class ForceImportErrorOn(object):
|
|||
def restore_import_funtion(self):
|
||||
self.patcher.stop()
|
||||
|
||||
def __fake_import__(self, name, globals_, locals_, fromlist, level=-1):
|
||||
def __fake_import__(self,
|
||||
name,
|
||||
globals_={} if six.PY2 else None,
|
||||
locals_={} if six.PY2 else None,
|
||||
fromlist=[] if six.PY2 else (),
|
||||
level=-1 if six.PY2 else 0):
|
||||
if name in self.__module_names:
|
||||
importerror_fromlist = self.__module_names.get(name)
|
||||
if importerror_fromlist is None:
|
||||
|
@ -453,7 +458,6 @@ class ForceImportErrorOn(object):
|
|||
)
|
||||
)
|
||||
)
|
||||
|
||||
return self.__original_import(name, globals_, locals_, fromlist, level)
|
||||
|
||||
def __enter__(self):
|
||||
|
|
Loading…
Add table
Reference in a new issue