##// END OF EJS Templates
Fix showing SystemExit exception raise inside except handler (#14503)...
Fix showing SystemExit exception raise inside except handler (#14503) Doing something like this: ```python try: 5 / 0 except Exception as e: raise SystemExit ``` was hitting an error inside UltraTB, creating a long traceback of its internals (which, ironically, UltraTB itself then displays correctly :-). `ListTB.get_exception_only()` calls the `ListTB.structured_traceback()` method *specifically* - even if `self` is a subclass, it won't use the subclass's method. However, the exception chaining in that method uses recursion by calling `self.structured_traceback()`, which will use a subclass's method. Tuples were added as an option there to support exception chaining, but not all of the machinery in connected classes expects a tuple. This just skips the exception chaining logic for the `etb=None` case, when we're showing the exception only. I'm not sure this is necessarily the best fix, but I didn't want to spend too much time following code around a module that's old enough to vote. Closes #12104

File last commit:

r28379:fb537d51
r28830:d5762c16 merge
Show More
module_paths.py
72 lines | 2.3 KiB | text/x-python | PythonLexer
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937 """Utility functions for finding modules
Utility functions for finding modules on sys.path.
"""
#-----------------------------------------------------------------------------
# Copyright (c) 2011, the IPython Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
# Stdlib imports
Alyssa Whitwell
Deprecate use of imp library, condense module_paths module to only one function, update tests
r24460 import importlib
Nathan Goldbaum
support using '%run -m' for modules importable via an import hook
r25582 import sys
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
# Third-party imports
# Our own imports
#-----------------------------------------------------------------------------
# Globals and constants
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Local utilities
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Classes and functions
#-----------------------------------------------------------------------------
Alyssa Whitwell
Deprecate use of imp library, condense module_paths module to only one function, update tests
r24460 def find_mod(module_name):
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937 """
Alyssa Whitwell
Deprecate use of imp library, condense module_paths module to only one function, update tests
r24460 Find module `module_name` on sys.path, and return the path to module `module_name`.
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
Matthias Bussonnier
whats new 8.15
r28379 * If `module_name` refers to a module directory, then return path to `__init__` file.
* If `module_name` is a directory without an __init__file, return None.
* If module is missing or does not have a `.py` or `.pyw` extension, return None.
* Note that we are not interested in running bytecode.
* Otherwise, return the fill path of the module.
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937
Parameters
----------
module_name : str
Matthias Bussonnier
reformat docstring in IPython utils
r26419
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937 Returns
-------
Alyssa Whitwell
Deprecate use of imp library, condense module_paths module to only one function, update tests
r24460 module_path : str
Path to module `module_name`, its __init__.py, or None,
depending on above conditions.
Jörgen Stenarson
Moving helper functions to utils.module_paths, adding tests.
r4937 """
Nikita Kniazev
module_paths: Fix confusing things
r27075 spec = importlib.util.find_spec(module_name)
module_path = spec.origin
Alyssa Whitwell
Deprecate use of imp library, condense module_paths module to only one function, update tests
r24460 if module_path is None:
Nikita Kniazev
module_paths: Fix confusing things
r27075 if spec.loader in sys.meta_path:
return spec.loader
Alyssa Whitwell
Deprecate use of imp library, condense module_paths module to only one function, update tests
r24460 return None
else:
split_path = module_path.split(".")
Christopher Brown
Fix extension detection...
r24836 if split_path[-1] in ["py", "pyw"]:
Alyssa Whitwell
Deprecate use of imp library, condense module_paths module to only one function, update tests
r24460 return module_path
else:
return None