exceptions.py 501 B

1234567891011121314151617181920
  1. from __future__ import annotations
  2. from typing import TYPE_CHECKING
  3. if TYPE_CHECKING:
  4. from typing_extensions import Final
  5. class ParseError(Exception):
  6. path: Final[str]
  7. lineno: Final[int]
  8. msg: Final[str]
  9. def __init__(self, path: str, lineno: int, msg: str) -> None:
  10. super().__init__(path, lineno, msg)
  11. self.path = path
  12. self.lineno = lineno
  13. self.msg = msg
  14. def __str__(self) -> str:
  15. return f"{self.path}:{self.lineno + 1}: {self.msg}"