diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2012-07-31 11:14:18 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2012-07-31 11:14:18 (GMT) |
commit | 42c0766a53d88756158cd0157faa7c8560c70c3b (patch) | |
tree | 8ae8a41fd61a3f24afa68d7331566b23f782f70e /Python/import.c | |
parent | 73a74dad3fe4ff69cdb1ecce73484c1574f93256 (diff) | |
download | cpython-42c0766a53d88756158cd0157faa7c8560c70c3b.zip cpython-42c0766a53d88756158cd0157faa7c8560c70c3b.tar.gz cpython-42c0766a53d88756158cd0157faa7c8560c70c3b.tar.bz2 |
Close #15486: Simplify the mechanism used to remove importlib frames from tracebacks when they just introduce irrelevant noise
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 28 |
1 files changed, 5 insertions, 23 deletions
diff --git a/Python/import.c b/Python/import.c index c4edfac..90a89ee 100644 --- a/Python/import.c +++ b/Python/import.c @@ -1153,9 +1153,7 @@ static void remove_importlib_frames(void) { const char *importlib_filename = "<frozen importlib._bootstrap>"; - const char *exec_funcname = "_exec_module"; - const char *get_code_funcname = "get_code"; - const char *recursive_import = "_recursive_import"; + const char *remove_frames = "_call_with_frames_removed"; int always_trim = 0; int trim_get_code = 0; int in_importlib = 0; @@ -1163,18 +1161,8 @@ remove_importlib_frames(void) PyObject **prev_link, **outer_link = NULL; /* Synopsis: if it's an ImportError, we trim all importlib chunks - from the traceback. If it's a SyntaxError, we trim any chunks that - end with a call to "get_code", We always trim chunks - which end with a call to "_exec_module". */ - - /* Thanks to issue 15425, we also strip any chunk ending with - * _recursive_import. This is used when making a recursive call to the - * full import machinery which means the inner stack gets stripped early - * and the normal heuristics won't fire properly for outer frames. A - * more elegant mechanism would be nice, as this one can misfire if - * builtins.__import__ has been replaced with a custom implementation. - * However, the current approach at least gets the job done. - */ + from the traceback. We always trim chunks + which end with a call to "_call_with_frames_removed". */ PyErr_Fetch(&exception, &value, &base_tb); if (!exception || Py_VerboseFlag) @@ -1207,14 +1195,8 @@ remove_importlib_frames(void) if (in_importlib && (always_trim || - (PyUnicode_CompareWithASCIIString(code->co_name, - exec_funcname) == 0) || - (PyUnicode_CompareWithASCIIString(code->co_name, - recursive_import) == 0) || - (trim_get_code && - PyUnicode_CompareWithASCIIString(code->co_name, - get_code_funcname) == 0) - )) { + PyUnicode_CompareWithASCIIString(code->co_name, + remove_frames) == 0)) { PyObject *tmp = *outer_link; *outer_link = next; Py_XINCREF(next); |