Files
pydantic/tests/mypy/modules/fail4.py
T
Samuel Colvin 6914410f38 Validation Decorator (#1179)
* 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
2020-02-05 17:27:12 +00:00

27 lines
375 B
Python

from pydantic import validate_arguments
@validate_arguments
def foo(a: int, *, c: str = 'x') -> str:
return c * a
# ok
x: str = foo(1, c='hello')
# fails
foo('x')
foo(1, c=1)
foo(1, 2)
foo(1, d=2)
# mypy assumes foo is just a function
callable(foo.raw_function)
@validate_arguments
def bar() -> str:
return 'x'
# return type should be a string
y: int = bar()