Presenting information about failing Functions and Generators.
| 682 | |
| 683 | @attr.s(auto_attribs=True) |
| 684 | class FormattedExcinfo: |
| 685 | """Presenting information about failing Functions and Generators.""" |
| 686 | |
| 687 | # for traceback entries |
| 688 | flow_marker: ClassVar = ">" |
| 689 | fail_marker: ClassVar = "E" |
| 690 | |
| 691 | showlocals: bool = False |
| 692 | style: "_TracebackStyle" = "long" |
| 693 | abspath: bool = True |
| 694 | tbfilter: bool = True |
| 695 | funcargs: bool = False |
| 696 | truncate_locals: bool = True |
| 697 | chain: bool = True |
| 698 | astcache: Dict[Union[str, Path], ast.AST] = attr.ib( |
| 699 | factory=dict, init=False, repr=False |
| 700 | ) |
| 701 | |
| 702 | def _getindent(self, source: "Source") -> int: |
| 703 | # Figure out indent for the given source. |
| 704 | try: |
| 705 | s = str(source.getstatement(len(source) - 1)) |
| 706 | except KeyboardInterrupt: |
| 707 | raise |
| 708 | except BaseException: |
| 709 | try: |
| 710 | s = str(source[-1]) |
| 711 | except KeyboardInterrupt: |
| 712 | raise |
| 713 | except BaseException: |
| 714 | return 0 |
| 715 | return 4 + (len(s) - len(s.lstrip())) |
| 716 | |
| 717 | def _getentrysource(self, entry: TracebackEntry) -> Optional["Source"]: |
| 718 | source = entry.getsource(self.astcache) |
| 719 | if source is not None: |
| 720 | source = source.deindent() |
| 721 | return source |
| 722 | |
| 723 | def repr_args(self, entry: TracebackEntry) -> Optional["ReprFuncArgs"]: |
| 724 | if self.funcargs: |
| 725 | args = [] |
| 726 | for argname, argvalue in entry.frame.getargs(var=True): |
| 727 | args.append((argname, saferepr(argvalue))) |
| 728 | return ReprFuncArgs(args) |
| 729 | return None |
| 730 | |
| 731 | def get_source( |
| 732 | self, |
| 733 | source: Optional["Source"], |
| 734 | line_index: int = -1, |
| 735 | excinfo: Optional[ExceptionInfo[BaseException]] = None, |
| 736 | short: bool = False, |
| 737 | ) -> List[str]: |
| 738 | """Return formatted and marked up source lines.""" |
| 739 | lines = [] |
| 740 | if source is None or line_index >= len(source.lines): |
| 741 | source = Source("???") |
no outgoing calls