MCPcopy
hub / github.com/Textualize/rich / _render_syntax_error

Method _render_syntax_error

rich/traceback.py:729–749  ·  view source on GitHub ↗
(self, syntax_error: _SyntaxError)

Source from the content-addressed store, hash-verified

727
728 @group()
729 def _render_syntax_error(self, syntax_error: _SyntaxError) -> RenderResult:
730 highlighter = ReprHighlighter()
731 path_highlighter = PathHighlighter()
732 if syntax_error.filename != "<stdin>":
733 if os.path.exists(syntax_error.filename):
734 text = Text.assemble(
735 (f" {syntax_error.filename}", "pygments.string"),
736 (":", "pygments.text"),
737 (str(syntax_error.lineno), "pygments.number"),
738 style="pygments.text",
739 )
740 yield path_highlighter(text)
741 syntax_error_text = highlighter(syntax_error.line.rstrip())
742 syntax_error_text.no_wrap = True
743 offset = min(syntax_error.offset - 1, len(syntax_error_text))
744 syntax_error_text.stylize("bold underline", offset, offset)
745 syntax_error_text += Text.from_markup(
746 "\n" + " " * offset + "[traceback.offset]▲[/]",
747 style="pygments.text",
748 )
749 yield syntax_error_text
750
751 @classmethod
752 def _guess_lexer(cls, filename: str, code: str) -> str:

Callers 1

render_stackMethod · 0.95

Calls 6

ReprHighlighterClass · 0.85
PathHighlighterClass · 0.85
assembleMethod · 0.80
rstripMethod · 0.80
stylizeMethod · 0.80
from_markupMethod · 0.80

Tested by

no test coverage detected