(
errors: Sequence[Any], config: Type['BaseConfig'], loc: Optional['Loc'] = None
)
| 97 | |
| 98 | |
| 99 | def flatten_errors( |
| 100 | errors: Sequence[Any], config: Type['BaseConfig'], loc: Optional['Loc'] = None |
| 101 | ) -> Generator['ErrorDict', None, None]: |
| 102 | for error in errors: |
| 103 | if isinstance(error, ErrorWrapper): |
| 104 | if loc: |
| 105 | error_loc = loc + error.loc_tuple() |
| 106 | else: |
| 107 | error_loc = error.loc_tuple() |
| 108 | |
| 109 | if isinstance(error.exc, ValidationError): |
| 110 | yield from flatten_errors(error.exc.raw_errors, config, error_loc) |
| 111 | else: |
| 112 | yield error_dict(error.exc, config, error_loc) |
| 113 | elif isinstance(error, list): |
| 114 | yield from flatten_errors(error, config, loc=loc) |
| 115 | else: |
| 116 | raise RuntimeError(f'Unknown error object: {error}') |
| 117 | |
| 118 | |
| 119 | def error_dict(exc: Exception, config: Type['BaseConfig'], loc: 'Loc') -> 'ErrorDict': |
no test coverage detected