cpython: 8c877ad00bc4 (original) (raw)

--- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -541,7 +541,7 @@ class FrozenImporter: """Load a frozen module.""" is_reload = fullname in sys.modules try:

@@ -568,6 +568,13 @@ class FrozenImporter: """Return if the frozen module is a package.""" return _imp.is_frozen_package(fullname)

+ class _LoaderBasics: @@ -644,9 +651,15 @@ class _LoaderBasics: else: module.package = module.package.rpartition('.')[0] module.loader = self

+ class SourceLoader(_LoaderBasics): @@ -869,7 +882,7 @@ class ExtensionFileLoader: """Load an extension module.""" is_reload = fullname in sys.modules try:

@@ -889,6 +902,12 @@ class ExtensionFileLoader: """Return None as extension modules have no source code.""" return None

+ class _NamespacePath: """Represents a namespace package's path. It uses the module name

--- a/Lib/test/test_import.py +++ b/Lib/test/test_import.py @@ -768,6 +768,98 @@ class ImportlibBootstrapTests(unittest.T self.assertTrue(mod.file.endswith('_bootstrap.py'), mod.file) +class ImportTracebackTests(unittest.TestCase): +

+

+

+

+

+

+

+

+

+ + def test_main(verbose=None): flag = importlib_util.using___import__ try: @@ -777,6 +869,7 @@ def test_main(verbose=None): OverridingImportBuiltinTests, ImportlibBootstrapTests, TestSymbolicallyLinkedPackage,

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 3.3.0 Beta 2? Core and Builtins ----------------- +- Issue #15110: Fix the tracebacks generated by "import xxx" to not show

--- a/Python/import.c +++ b/Python/import.c @@ -8,6 +8,7 @@ #include "errcode.h" #include "marshal.h" #include "code.h" +#include "frameobject.h" #include "osdefs.h" #include "importdl.h" @@ -1375,6 +1376,69 @@ PyImport_ImportModuleNoBlock(const char } +/* Remove importlib frames from the traceback,

+

+

+

+

+

+done:

+} + + PyObject * PyImport_ImportModuleLevelObject(PyObject *name, PyObject *given_globals, PyObject *locals, PyObject *given_fromlist, @@ -1693,6 +1757,8 @@ PyImport_ImportModuleLevelObject(PyObjec Py_XDECREF(package); Py_XDECREF(globals); Py_XDECREF(fromlist);

--- a/Python/importlib.h +++ b/Python/importlib.h @@ -1286,10 +1286,10 @@ unsigned char _Py_M__importlib[] = { 3,1,3,1,3,1,27,11,3,1,21,5,3,1,21,5, 3,1,117,15,0,0,0,66,117,105,108,116,105,110,73,109, 112,111,114,116,101,114,99,1,0,0,0,0,0,0,0,1,

};