mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
6914410f38
* starting validation_decorator * correct skip_pre_38 * fix coverage and type hints * mypy tests and move to class based decorator * 3.6 fix, prevent duplicate github actions * correct py 3.6 check * better errors * cleaner field names for args and kwargs * add change and comments * starting docs * back to 3.7 for docs * docs * bump * add async example and fix print indents * allow type annotations as strings * python 3.8 in docs
18 lines
380 B
Python
18 lines
380 B
Python
from pydantic import validate_arguments, ValidationError
|
|
|
|
@validate_arguments
|
|
def repeat(s: str, count: int, *, separator: bytes = b'') -> bytes:
|
|
b = s.encode()
|
|
return separator.join(b for _ in range(count))
|
|
|
|
a = repeat('hello', 3)
|
|
print(a)
|
|
|
|
b = repeat('x', '4', separator=' ')
|
|
print(b)
|
|
|
|
try:
|
|
c = repeat('hello', 'wrong')
|
|
except ValidationError as exc:
|
|
print(exc)
|