mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
9c4860ce96
* add `configs` to validate_arguments * simplify `validate_arguments` and add annotation for parameter `configs` * change double quotes to single quotes * reformat code * fix mypy error * fix mypy 'maximum semantic analysis' error * rename 'configs' > 'config_params' * change name and usage, start tests * prevent setting fields on custom config * add docs and fix mypy * tweak docs * add change Co-authored-by: quantpy <quantpy@qq.com>
27 lines
517 B
Python
27 lines
517 B
Python
from pydantic import ValidationError, validate_arguments
|
|
|
|
|
|
class Foobar:
|
|
def __init__(self, v: str):
|
|
self.v = v
|
|
|
|
def __add__(self, other: 'Foobar') -> str:
|
|
return f'{self} + {other}'
|
|
|
|
def __str__(self) -> str:
|
|
return f'Foobar({self.v})'
|
|
|
|
|
|
@validate_arguments(config=dict(arbitrary_types_allowed=True))
|
|
def add_foobars(a: Foobar, b: Foobar):
|
|
return a + b
|
|
|
|
|
|
c = add_foobars(Foobar('a'), Foobar('b'))
|
|
print(c)
|
|
|
|
try:
|
|
add_foobars(1, 2)
|
|
except ValidationError as e:
|
|
print(e)
|