Commit 3ddd714c authored by Arnaud Fontaine's avatar Arnaud Fontaine

py3: ZODB Components: New Exception ModuleNotFoundError which avoids a hack in Python2.

parent 88f40296
......@@ -30,6 +30,7 @@
# There is absolutely no reason to use relative imports when loading a Component
from __future__ import absolute_import
import six
import sys
import imp
import collections
......@@ -51,6 +52,12 @@ class ComponentVersionPackage(ModuleType):
"""
__path__ = []
try:
ModuleNotFoundError
except NameError: # < 3.6
class ModuleNotFoundError(ImportError):
pass
class ComponentDynamicPackage(ModuleType):
"""
A top-level component is a package as it contains modules, this is required
......@@ -420,8 +427,10 @@ class ComponentDynamicPackage(ModuleType):
# load_module(), and returning module 'name' in contrary to __import__
# returning 'erp5' (requiring fromlist parameter which is slower)
return import_module(fullname)
except ModuleNotFoundError:
pass
except ImportError as e:
if str(e) != "No module named " + name:
if six.PY3 or str(e) != "No module named " + name:
LOG("ERP5Type.dynamic", WARNING,
"Could not load Component module %r" % fullname, error=True)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment