|
18 | 18 |
|
19 | 19 | from abc import ABC, abstractmethod |
20 | 20 | from collections.abc import Iterable |
21 | | -from typing import TYPE_CHECKING, Any, Literal, Optional, Protocol, Union, overload |
| 21 | +from typing import TYPE_CHECKING, Literal, Optional, Protocol, Union, overload |
22 | 22 |
|
23 | 23 | from ..schema import OutputFormat |
24 | 24 |
|
|
29 | 29 |
|
30 | 30 |
|
31 | 31 | class ValidationError: |
32 | | - """Validation failed with this specific error. |
| 32 | + """Validation failed with this specific error. """ |
33 | 33 |
|
34 | | - Use :attr:`~data` to access the content. |
35 | | - """ |
36 | | - |
37 | | - data: Any |
38 | | - """Raw error data from one of the underlying validation methods.""" |
39 | | - |
40 | | - message: str |
41 | | - """Human-readable error message suitable for end-user presentation.""" |
| 34 | + def __init__(self, message: str) -> None: |
| 35 | + self._message = message |
42 | 36 |
|
43 | | - path: tuple[Union[str, int], ...] |
44 | | - """Path to the offending value if known.""" |
45 | | - |
46 | | - def __init__(self, data: Any, *, message: Optional[str] = None, |
47 | | - path: Iterable[Union[str, int]] = ()) -> None: |
48 | | - self.data = data |
49 | | - self.message = str(data) if message is None else message |
50 | | - self.path = tuple(path) |
| 37 | + @property |
| 38 | + def message(self) -> str: |
| 39 | + return self._message |
51 | 40 |
|
52 | 41 | def __repr__(self) -> str: |
53 | | - return f'{self.__class__.__name__}(message={self.message!r}, path={self.path!r})' |
| 42 | + return f'<{self.__class__.__qualname__} {self._message!r}>' |
54 | 43 |
|
55 | 44 | def __str__(self) -> str: |
56 | | - return self.message |
| 45 | + return self._message |
57 | 46 |
|
58 | 47 |
|
59 | 48 | class SchemabasedValidator(Protocol): |
|
0 commit comments