(self, etb: TracebackType, context: int, tb_offset: int)
| 852 | return [[head] + frames + formatted_exception] |
| 853 | |
| 854 | def get_records(self, etb: TracebackType, context: int, tb_offset: int) -> Any: |
| 855 | assert etb is not None |
| 856 | context = context - 1 |
| 857 | after = context // 2 |
| 858 | before = context - after |
| 859 | if self.has_colors: |
| 860 | theme = theme_table[self._theme_name] |
| 861 | base_style = theme.as_pygments_style() |
| 862 | tb_highlight = theme.extra_style.get(Token.TbHighlight, self.tb_highlight) |
| 863 | style = stack_data.style_with_executing_node(base_style, tb_highlight) |
| 864 | formatter = Terminal256Formatter(style=style) |
| 865 | else: |
| 866 | formatter = None |
| 867 | options = stack_data.Options( |
| 868 | before=before, |
| 869 | after=after, |
| 870 | pygments_formatter=formatter, |
| 871 | ) |
| 872 | |
| 873 | # Collect traceback frames and their module sizes. |
| 874 | cf: Optional[TracebackType] = etb |
| 875 | tbs: list[tuple[TracebackType, int]] = [] |
| 876 | while cf is not None: |
| 877 | try: |
| 878 | mod = inspect.getmodule(cf.tb_frame) |
| 879 | if mod is not None: |
| 880 | mod_name = mod.__name__ |
| 881 | root_name, *_ = mod_name.split(".") |
| 882 | if root_name == "IPython": |
| 883 | cf = cf.tb_next |
| 884 | continue |
| 885 | frame_len = get_line_number_of_frame(cf.tb_frame) |
| 886 | if frame_len == 0: |
| 887 | # File not found or not a .py file (e.g. <string> from |
| 888 | # exec()). Check if source is actually available; if not, |
| 889 | # force the fast path so that FrameInfo's "Could not get |
| 890 | # source" fallback is rendered. |
| 891 | try: |
| 892 | inspect.getsourcelines(cf.tb_frame) |
| 893 | except OSError: |
| 894 | frame_len = FAST_THRESHOLD + 1 |
| 895 | except OSError: |
| 896 | frame_len = FAST_THRESHOLD + 1 |
| 897 | assert cf is not None # narrowing for mypy; guarded by while condition |
| 898 | tbs.append((cf, frame_len)) |
| 899 | cf = cf.tb_next |
| 900 | |
| 901 | # Group consecutive frames by fast/slow and process each group. |
| 902 | # Consecutive slow frames must be processed together so that |
| 903 | # stack_data can detect RepeatedFrames (recursion collapsing). |
| 904 | FIs: list[FrameInfo] = [] |
| 905 | i = 0 |
| 906 | while i < len(tbs): |
| 907 | tb, frame_len = tbs[i] |
| 908 | if frame_len > FAST_THRESHOLD: |
| 909 | frame = tb.tb_frame # type: ignore[union-attr] |
| 910 | lineno = frame.f_lineno |
| 911 | code = frame.f_code |
no test coverage detected