-
Notifications
You must be signed in to change notification settings - Fork 23
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
[json schema] Do not throw errors when parsing non annotated parameters #1157
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1157 +/- ##
==========================================
+ Coverage 90.69% 90.75% +0.06%
==========================================
Files 129 129
Lines 8189 8286 +97
==========================================
+ Hits 7427 7520 +93
- Misses 762 766 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
|
I don't really see the point of leaving an arg un-annotated, especially if one is going to use the |
Important context: the method The argument to leave arguments unannotated is the one that you have made before: lowering the barriers to contribution for users by not adding hurdles. Forcing them to use type annotations to inherit from BaseDataInterface is a contentious hurdle. My impression is that the Python community is still quite divided about using annotations or not. If you still prefer to force the user to use annotations, then the error can be something like: "The arguments x, y, and z lack type annotations. Add them to initialize the interface." What do you think? |
Why are we always calling this function? Is this necessary? |
If we want to enforce typing, we could use beartype: https://github.com/beartype/beartype |
To validate source data. To me it seems like a nice feature to have and it has been like that since the nwb-conversion-tools times. At least for the If we were to disable source validation under which conditions we would? I personally would prefer the outcome of this PR. Once this PR is merged it will work like this for interfaces and converters:
beartype looks nice. We have something similar with Pydantic validate_call: |
I think these issues are separable:
We don't necessarily need to do validation with the json schema, when working within Python. There are some nuances in the conversion from args to json schema that can cause complications here.
The pydantic library has come a long way since we originally wrote this code, and now facilitates a much simpler approach. Now we can change the code so that instead of attempting to create a json schema and then validate every call with it, we use the method you mentioned, |
This comes from the IBL project.
Summary:
If someone creates their own interface (inherits from BaseDataInterface) but does not annotate the
__init__
function of the json validation will throw an obscure error:The fix, in my view, is to omit validation when the user does not annotate their signature parameters as there is nothing to validate. I added a fix and a test here.