| 293 | } |
| 294 | |
| 295 | def __init__( |
| 296 | self, |
| 297 | trace: Optional[Trace] = None, |
| 298 | *, |
| 299 | width: Optional[int] = 100, |
| 300 | code_width: Optional[int] = 88, |
| 301 | extra_lines: int = 3, |
| 302 | theme: Optional[str] = None, |
| 303 | word_wrap: bool = False, |
| 304 | show_locals: bool = False, |
| 305 | locals_max_length: int = LOCALS_MAX_LENGTH, |
| 306 | locals_max_string: int = LOCALS_MAX_STRING, |
| 307 | locals_max_depth: Optional[int] = None, |
| 308 | locals_hide_dunder: bool = True, |
| 309 | locals_hide_sunder: bool = False, |
| 310 | locals_overlow: Optional[OverflowMethod] = None, |
| 311 | indent_guides: bool = True, |
| 312 | suppress: Iterable[Union[str, ModuleType]] = (), |
| 313 | max_frames: int = 100, |
| 314 | ): |
| 315 | if trace is None: |
| 316 | exc_type, exc_value, traceback = sys.exc_info() |
| 317 | if exc_type is None or exc_value is None or traceback is None: |
| 318 | raise ValueError( |
| 319 | "Value for 'trace' required if not called in except: block" |
| 320 | ) |
| 321 | trace = self.extract( |
| 322 | exc_type, exc_value, traceback, show_locals=show_locals |
| 323 | ) |
| 324 | self.trace = trace |
| 325 | self.width = width |
| 326 | self.code_width = code_width |
| 327 | self.extra_lines = extra_lines |
| 328 | self.theme = Syntax.get_theme(theme or "ansi_dark") |
| 329 | self.word_wrap = word_wrap |
| 330 | self.show_locals = show_locals |
| 331 | self.indent_guides = indent_guides |
| 332 | self.locals_max_length = locals_max_length |
| 333 | self.locals_max_string = locals_max_string |
| 334 | self.locals_max_depth = locals_max_depth |
| 335 | self.locals_hide_dunder = locals_hide_dunder |
| 336 | self.locals_hide_sunder = locals_hide_sunder |
| 337 | self.locals_overflow = locals_overlow |
| 338 | |
| 339 | self.suppress: Sequence[str] = [] |
| 340 | for suppress_entity in suppress: |
| 341 | if not isinstance(suppress_entity, str): |
| 342 | assert ( |
| 343 | suppress_entity.__file__ is not None |
| 344 | ), f"{suppress_entity!r} must be a module with '__file__' attribute" |
| 345 | path = os.path.dirname(suppress_entity.__file__) |
| 346 | else: |
| 347 | path = suppress_entity |
| 348 | path = os.path.normpath(os.path.abspath(path)) |
| 349 | self.suppress.append(path) |
| 350 | self.max_frames = max(4, max_frames) if max_frames > 0 else 0 |
| 351 | |
| 352 | @classmethod |