Skip to content

Commit

Permalink
error details from python errors PydanticValueError (#185)
Browse files Browse the repository at this point in the history
* working on PydanticValueError, fix #183

* rust class working

* linting

* add benchmarks

* improvements to PydanticValueError

* custom int context value processing

* fix tests
  • Loading branch information
samuelcolvin committed Jul 21, 2022
1 parent 9caaaed commit 663fdee
Show file tree
Hide file tree
Showing 14 changed files with 481 additions and 196 deletions.
4 changes: 2 additions & 2 deletions pydantic_core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ._pydantic_core import SchemaError, SchemaValidator, ValidationError, __version__
from ._pydantic_core import PydanticValueError, SchemaError, SchemaValidator, ValidationError, __version__
from ._types import Config, Schema

__all__ = '__version__', 'Config', 'Schema', 'SchemaError', 'SchemaValidator', 'ValidationError'
__all__ = '__version__', 'Config', 'Schema', 'SchemaValidator', 'SchemaError', 'ValidationError', 'PydanticValueError'
30 changes: 27 additions & 3 deletions pydantic_core/_pydantic_core.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from typing import Any, Dict, List, Optional, Union
import sys
from typing import Any, Dict, List, Optional, TypedDict, Union

from pydantic_core._types import Config, Schema

if sys.version_info < (3, 11):
from typing_extensions import NotRequired
else:
from typing import NotRequired

__all__ = '__version__', 'SchemaValidator', 'SchemaError', 'ValidationError', 'PydanticValueError'
__version__: str

class SchemaValidator:
Expand All @@ -16,11 +23,28 @@ class SchemaValidator:
) -> bool: ...
def validate_assignment(self, field: str, input: Any, data: Dict[str, Any]) -> Dict[str, Any]: ...

class SchemaError(ValueError):
class SchemaError(Exception):
pass

class ErrorDetails(TypedDict):
kind: str
loc: List[Union[int, str]]
message: str
input_value: Any
context: NotRequired[Dict[str, Any]]

class ValidationError(ValueError):
title: str

def error_count(self) -> int: ...
def errors(self) -> List[Dict[str, Any]]: ...
def errors(self) -> List[ErrorDetails]: ...

class PydanticValueError(ValueError):
kind: str
message_template: str
context: Optional[Dict[str, Union[str, int]]]

def __init__(
self, kind: str, message_template: str, context: Optional[Dict[str, Union[str, int]]] = None
) -> None: ...
def message(self) -> str: ...
Loading

0 comments on commit 663fdee

Please sign in to comment.