##// 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:

r28532:1cbca0b4
r28830:d5762c16 merge
Show More
tz.py
82 lines | 2.0 KiB | text/x-python | PythonLexer
# encoding: utf-8
"""
Timezone utilities
Just UTC-awareness right now
Deprecated since IPython 8.19.0.
"""
# -----------------------------------------------------------------------------
# Copyright (C) 2013 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Imports
# -----------------------------------------------------------------------------
import warnings
from datetime import tzinfo, timedelta, datetime
# -----------------------------------------------------------------------------
# Code
# -----------------------------------------------------------------------------
__all__ = ["tzUTC", "utc_aware", "utcfromtimestamp", "utcnow"]
# constant for zero offset
ZERO = timedelta(0)
def __getattr__(name):
if name not in __all__:
err = f"IPython.utils.tz is deprecated and has no attribute {name}"
raise AttributeError(err)
_warn_deprecated()
return getattr(name)
def _warn_deprecated():
msg = "The module `IPython.utils.tz` is deprecated and will be completely removed."
warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
class tzUTC(tzinfo):
"""tzinfo object for UTC (zero offset)
Deprecated since IPython 8.19.0.
"""
_warn_deprecated()
def utcoffset(self, d):
return ZERO
def dst(self, d):
return ZERO
UTC = tzUTC() # type: ignore[abstract]
def utc_aware(unaware):
"""decorator for adding UTC tzinfo to datetime's utcfoo methods
Deprecated since IPython 8.19.0.
"""
def utc_method(*args, **kwargs):
_warn_deprecated()
dt = unaware(*args, **kwargs)
return dt.replace(tzinfo=UTC)
return utc_method
utcfromtimestamp = utc_aware(datetime.utcfromtimestamp)
utcnow = utc_aware(datetime.utcnow)