MCPcopy Index your code
hub / github.com/RustPython/RustPython / _format_syntax_error

Method _format_syntax_error

Lib/traceback.py:1376–1466  ·  view source on GitHub ↗

Format SyntaxError exceptions (internal helper).

(self, stype, **kwargs)

Source from the content-addressed store, hash-verified

1374
1375
1376 def _format_syntax_error(self, stype, **kwargs):
1377 """Format SyntaxError exceptions (internal helper)."""
1378 # Show exactly where the problem was found.
1379 colorize = kwargs.get("colorize", False)
1380 if colorize:
1381 theme = _colorize.get_theme(force_color=True).traceback
1382 else:
1383 theme = _colorize.get_theme(force_no_color=True).traceback
1384 filename_suffix = ''
1385 if self.lineno is not None:
1386 yield ' File {}"{}"{}, line {}{}{}\n'.format(
1387 theme.filename,
1388 self.filename or "<string>",
1389 theme.reset,
1390 theme.line_no,
1391 self.lineno,
1392 theme.reset,
1393 )
1394 elif self.filename is not None:
1395 filename_suffix = ' ({})'.format(self.filename)
1396
1397 text = self.text
1398 if isinstance(text, str):
1399 # text = " foo\n"
1400 # rtext = " foo"
1401 # ltext = "foo"
1402 with suppress(Exception):
1403 self._find_keyword_typos()
1404 text = self.text
1405 rtext = text.rstrip('\n')
1406 ltext = rtext.lstrip(' \n\f')
1407 spaces = len(rtext) - len(ltext)
1408 if self.offset is None:
1409 yield ' {}\n'.format(ltext)
1410 elif isinstance(self.offset, int):
1411 offset = self.offset
1412 if self.lineno == self.end_lineno:
1413 end_offset = (
1414 self.end_offset
1415 if (
1416 isinstance(self.end_offset, int)
1417 and self.end_offset != 0
1418 )
1419 else offset
1420 )
1421 else:
1422 end_offset = len(rtext) + 1
1423
1424 if self.text and offset > len(self.text):
1425 offset = len(rtext) + 1
1426 if self.text and end_offset > len(self.text):
1427 end_offset = len(rtext) + 1
1428 if offset >= end_offset or end_offset < 0:
1429 end_offset = offset + 1
1430
1431 # Convert 1-based column offset to 0-based index into stripped text
1432 colno = offset - 1 - spaces
1433 end_colno = end_offset - 1 - spaces

Callers 1

format_exception_onlyMethod · 0.95

Calls 10

_find_keyword_typosMethod · 0.95
suppressClass · 0.90
isinstanceFunction · 0.85
lenFunction · 0.85
getMethod · 0.45
formatMethod · 0.45
rstripMethod · 0.45
lstripMethod · 0.45
isspaceMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected