New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validation Decorator #1179
Validation Decorator #1179
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1179 +/- ##
==========================================
- Coverage 100% 99.94% -0.06%
==========================================
Files 21 21
Lines 3666 3666
Branches 718 718
==========================================
- Hits 3666 3664 -2
- Misses 0 2 +2
Continue to review full report at Codecov.
|
This looks great to me! |
For me this is ready to merge. I'll leave it a few days for any further feedback, then merge. |
I hadn't seen this. It looks awesome! |
Just noticed that the decorator is called |
@tiangolo thanks! @StephenBrown2 thanks for pointing that out 🤦♂ PR welcome to fix that. |
don't worry, I'll fix the docs. |
Are there any concerns about memory issues with this? Currently, every function that is wrapped via
|
This feature seems to allow values that can be cast from one form to another. @validate_arguments
def something(x: str, y: Dict[str, str]):
print(x, y) Testing this with the following: Is that by design? Is there a way to enable stricter type checking? |
@stonecharioteer late reply, but this is not actually an issue with When you specify types like from pydantic import BaseModel
class Test(BaseModel):
x: str
Test(x=20) # no error
Test(x=None) # error If you want stricter checking, consider using constrained types with from pydantic import BaseModel, constr, validate_arguments
from pydantic.typing import Dict
strict_str = constr(strict=True)
@validate_arguments
def something(x: strict_str, y: Dict[strict_str, strict_str]):
print(x, y) |
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Change Summary
This adds a
validate_arguments
function decorator which checks the arguments to a function matches type annotations.I'm intending to get an MVP ready and merge that with a note saying this is in open beta and may change.
Still, there's quite a lot here. Feedback very welcome.
Related issue number
fix #347
TODO
kwargs
, orargs
are provided.validate_arguments
the best option? unless someone has a better idea???changes/<pull request or issue id>-<github username>.md
fileTo be done in future (I think this should be done after the initial release of this feature): see #1205