py2/py3: Fix __import__ fromlist argument.
__import__ `fromlist` argument was wrong. It was working anyway with Python2 but not anymore with Python3, raising a `ModuleNotFoundError` exception. According to Python `__import__(name, globals, locals, fromlist)` documentation: When the `name` variable is of the form `package.module`, normally, the top-level package (the `name` up till the first dot) is returned, *not* the module named by `name`. However, when a non-empty `fromlist` argument is given, the module named by `name` is returned. Thus, the following patterns were wrong: * __import__(MODULE_NAME, globals(), locals(), MODULE_NAME) => Iterate through each character of MODULE_NAME as fromlist is expected to be a list/tuple. * __import__(MODULE_NAME, globals(), locals(), [MODULE_NAME]) => This works but actually tries to import MODULE_NAME object from MODULE_NAME module (no error if it cannot). The goal of such __import__ calls were for __import__ to return the right-end module instead of the top-level package. In such case, `fromlist=['']` is the way to go as it __import__ does not check if the object exists in the module if it's an empty string. However, it is even better and easier to read to use importlib.import_module() for that... Also, add `from __future__ import absolute_import` because python2 tries both relative and absolute import (level=-1 __import__ parameter) whereas python3 does absolute import by default (level=0). Co-authored-by: Kazuhiko SHIOZAKI <kazuhiko@nexedi.com>
Status | Job ID | Name | Coverage | ||||||
---|---|---|---|---|---|---|---|---|---|
External | |||||||||
passed |
#703068
external
|
ERP5.CodingStyleTest-Master |
02:30:43
|
||||||
failed |
#703066
external
|
ERP5.PerformanceTest-Master |
00:35:18
|
||||||
failed |
#703067
external
|
ERP5.UnitTest-Master |
05:02:28
|
||||||
passed |
#703451
external
|
SlapOS.Eggs.UnitTest-Master.Python2 |
00:15:10
|
||||||
passed |
#703057
external
|
SlapOS.Eggs.UnitTest-Master.Python3 |
00:50:22
|
||||||
passed |
#703046
external
|
Wendelin.UnitTest-Master |
00:55:40
|
||||||
passed |
#702981
external
retried
|
ERP5.CodingStyleTest-Master |
01:54:56
|
||||||
failed |
#703008
external
retried
|
ERP5.PerformanceTest-Master |
00:35:26
|
||||||
failed |
#702966
external
retried
|
ERP5.UnitTest-Master |
02:30:10
|
||||||
passed |
#703426
external
retried
|
SlapOS.Eggs.UnitTest-Master.Python2 |
00:17:50
|
||||||
passed |
#702975
external
retried
|
SlapOS.Eggs.UnitTest-Master.Python2 |
00:15:21
|
||||||
passed |
#703024
external
retried
|
SlapOS.Eggs.UnitTest-Master.Python2 |
01:10:45
|
||||||
passed |
#703102
external
retried
|
SlapOS.Eggs.UnitTest-Master.Python2 |
00:18:55
|
||||||
passed |
#702990
external
retried
|
SlapOS.Eggs.UnitTest-Master.Python3 |
00:18:03
|
||||||
failed |
#702969
external
retried
|
Wendelin.UnitTest-Master |
00:41:09
|
||||||
passed |
#703003
external
retried
|
Wendelin.UnitTest-Master |
00:39:29
|
||||||