-
-
Notifications
You must be signed in to change notification settings - Fork 120
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
Find out how pydantic validates function calls without calling them #875
Comments
I have a little explanation while I was walking through the code! The class responsible for is ValidatedFunction! In its When we call
The model is created in create_model method, at the end we have a normal BaseModel but instead of class specifications we have function specifications! The validations occur in the validate_model function. |
@thepabloaguilar can we adopt this / similar approach to speed up our |
Well, I have something in mind for a long time, maybe we can use >>> from functools import partial
>>> def f(a, b, c):
... ...
...
>>> p1 = partial(f, 1)
>>> str(p1)
'functools.partial(<function f at 0x105bae160>, 1)'
>>> p2 = partial(p1, 2)
>>> str(p2)
'functools.partial(<function f at 0x105bae160>, 1, 2)'
# We have access to `args`, `kwargs` and `func`
>>> (p2.args, p2.keywords, p.func)
((1, 2), {}, <function a at 0x105b95ca0>) I don't know if it's possible to build something using that approach, it's just thinking! |
We need some logical flag to decide when to actually call a function: https://github.com/dry-python/returns/blob/master/returns/curry.py#L138-L139 |
Hummmm. I want to make some tests around Using >>> import inspect
# Consider `p1` and `p2` from my last example
>>> inspect.signature(p2)
<Signature (c)>
>>> inspect.signature(p1)
<Signature (b, c)>
>>> inspect.getfullargspec(p1)
FullArgSpec(args=['b', 'c'], varargs=None, varkw=None, defaults=None, kwonlyargs=[], kwonlydefaults=None, annotations={})
>>> inspect.getfullargspec(p2)
FullArgSpec(args=['c'], varargs=None, varkw=None, defaults=None, kwonlyargs=[], kwonlydefaults=None, annotations={}) Pydantic: |
We need to chec how
pydantic
validates function arguments without calling the function itself: https://pydantic-docs.helpmanual.io/usage/validation_decorator/#validate-without-calling-the-functionWe need this because our
@curry
implementation relies on this logic. And right now it is very slow.The text was updated successfully, but these errors were encountered: