Return formatted and marked up source lines.
(
self,
source: Source | None,
line_index: int = -1,
excinfo: ExceptionInfo[BaseException] | None = None,
short: bool = False,
end_line_index: int | None = None,
colno: int | None = None,
end_colno: int | None = None,
)
| 931 | return None |
| 932 | |
| 933 | def get_source( |
| 934 | self, |
| 935 | source: Source | None, |
| 936 | line_index: int = -1, |
| 937 | excinfo: ExceptionInfo[BaseException] | None = None, |
| 938 | short: bool = False, |
| 939 | end_line_index: int | None = None, |
| 940 | colno: int | None = None, |
| 941 | end_colno: int | None = None, |
| 942 | ) -> list[str]: |
| 943 | class="st">""class="st">"Return formatted and marked up source lines."class="st">"" |
| 944 | lines = [] |
| 945 | if source is not None and line_index < 0: |
| 946 | line_index += len(source) |
| 947 | if source is None or line_index >= len(source.lines) or line_index < 0: |
| 948 | class="cm"># `line_index` could still be outside `range(len(source.lines))` if |
| 949 | class="cm"># we're processing AST with pathological position attributes. |
| 950 | source = Source(class="st">"???") |
| 951 | line_index = 0 |
| 952 | space_prefix = class="st">" " |
| 953 | if short: |
| 954 | lines.append(space_prefix + source.lines[line_index].strip()) |
| 955 | lines.extend( |
| 956 | self.get_highlight_arrows_for_line( |
| 957 | raw_line=source.raw_lines[line_index], |
| 958 | line=source.lines[line_index].strip(), |
| 959 | lineno=line_index, |
| 960 | end_lineno=end_line_index, |
| 961 | colno=colno, |
| 962 | end_colno=end_colno, |
| 963 | ) |
| 964 | ) |
| 965 | else: |
| 966 | for line in source.lines[:line_index]: |
| 967 | lines.append(space_prefix + line) |
| 968 | lines.append(self.flow_marker + class="st">" " + source.lines[line_index]) |
| 969 | lines.extend( |
| 970 | self.get_highlight_arrows_for_line( |
| 971 | raw_line=source.raw_lines[line_index], |
| 972 | line=source.lines[line_index], |
| 973 | lineno=line_index, |
| 974 | end_lineno=end_line_index, |
| 975 | colno=colno, |
| 976 | end_colno=end_colno, |
| 977 | ) |
| 978 | ) |
| 979 | for line in source.lines[line_index + 1 :]: |
| 980 | lines.append(space_prefix + line) |
| 981 | if excinfo is not None: |
| 982 | indent = 4 if short else self._getindent(source) |
| 983 | lines.extend(self.get_exconly(excinfo, indent=indent, markall=True)) |
| 984 | return lines |
| 985 | |
| 986 | def get_highlight_arrows_for_line( |
| 987 | self, |