errors.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. """
  2. This file is about errors in Python files and not about exception handling in
  3. Jedi.
  4. """
  5. def parso_to_jedi_errors(grammar, module_node):
  6. return [SyntaxError(e) for e in grammar.iter_errors(module_node)]
  7. class SyntaxError:
  8. """
  9. Syntax errors are generated by :meth:`.Script.get_syntax_errors`.
  10. """
  11. def __init__(self, parso_error):
  12. self._parso_error = parso_error
  13. @property
  14. def line(self):
  15. """The line where the error starts (starting with 1)."""
  16. return self._parso_error.start_pos[0]
  17. @property
  18. def column(self):
  19. """The column where the error starts (starting with 0)."""
  20. return self._parso_error.start_pos[1]
  21. @property
  22. def until_line(self):
  23. """The line where the error ends (starting with 1)."""
  24. return self._parso_error.end_pos[0]
  25. @property
  26. def until_column(self):
  27. """The column where the error ends (starting with 0)."""
  28. return self._parso_error.end_pos[1]
  29. def get_message(self):
  30. return self._parso_error.message
  31. def __repr__(self):
  32. return '<%s from=%s to=%s>' % (
  33. self.__class__.__name__,
  34. self._parso_error.start_pos,
  35. self._parso_error.end_pos,
  36. )