MCPcopy Index your code
hub / github.com/python/cpython / __init__

Method __init__

Lib/traceback.py:1064–1242  ·  view source on GitHub ↗
(self, exc_type, exc_value, exc_traceback, *, limit=None,
            lookup_lines=True, capture_locals=False, compact=False,
            max_group_width=15, max_group_depth=10, save_exc_type=True, _seen=None)

Source from the content-addressed store, hash-verified

1062 """
1063
1064 def __init__(self, exc_type, exc_value, exc_traceback, *, limit=None,
1065 lookup_lines=True, capture_locals=False, compact=False,
1066 max_group_width=15, max_group_depth=10, save_exc_type=True, _seen=None):
1067 # NB: we need to accept exc_traceback, exc_value, exc_traceback to
1068 # permit backwards compat with the existing API, otherwise we
1069 # need stub thunk objects just to glue it together.
1070 # Handle loops in __cause__ or __context__.
1071 is_recursive_call = _seen is not None
1072 if _seen is None:
1073 _seen = set()
1074 _seen.add(id(exc_value))
1075
1076 self.max_group_width = max_group_width
1077 self.max_group_depth = max_group_depth
1078
1079 self.stack = StackSummary._extract_from_extended_frame_gen(
1080 _walk_tb_with_full_positions(exc_traceback),
1081 limit=limit, lookup_lines=lookup_lines,
1082 capture_locals=capture_locals)
1083
1084 self._exc_type = exc_type if save_exc_type else None
1085
1086 # Capture now to permit freeing resources: only complication is in the
1087 # unofficial API _format_final_exc_line
1088 self._str = _safe_string(exc_value, 'exception')
1089 try:
1090 self.__notes__ = getattr(exc_value, '__notes__', None)
1091 except Exception as e:
1092 self.__notes__ = [
1093 f'Ignored error getting __notes__: {_safe_string(e, '__notes__', repr)}']
1094
1095 self._is_syntax_error = False
1096 self._have_exc_type = exc_type is not None
1097 if exc_type is not None:
1098 self.exc_type_qualname = exc_type.__qualname__
1099 self.exc_type_module = exc_type.__module__
1100 else:
1101 self.exc_type_qualname = None
1102 self.exc_type_module = None
1103
1104 if exc_type and issubclass(exc_type, SyntaxError):
1105 # Handle SyntaxError's specially
1106 self.filename = exc_value.filename
1107 lno = exc_value.lineno
1108 self.lineno = str(lno) if lno is not None else None
1109 end_lno = exc_value.end_lineno
1110 self.end_lineno = str(end_lno) if end_lno is not None else None
1111 self.text = exc_value.text
1112 self.offset = exc_value.offset
1113 self.end_offset = exc_value.end_offset
1114 self.msg = exc_value.msg
1115 self._is_syntax_error = True
1116 self._exc_metadata = getattr(exc_value, "_metadata", None)
1117 elif exc_type and issubclass(exc_type, ImportError) and \
1118 getattr(exc_value, "name_from", None) is not None:
1119 wrong_name = getattr(exc_value, "name_from", None)
1120 suggestion = _compute_suggestion_error(exc_value, exc_traceback, wrong_name)
1121 if suggestion:

Callers

nothing calls this directly

Calls 15

_load_linesMethod · 0.95
setFunction · 0.85
idFunction · 0.85
_safe_stringFunction · 0.85
strFunction · 0.85
isasciiMethod · 0.80
TracebackExceptionClass · 0.70
addMethod · 0.45

Tested by

no test coverage detected