-
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
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, |
Oh, I see how you are thinking. I fully agree with this reasoning that they are two distinct responsibilities! I was under the wrong impression that you wanted to have a JSON validation mechanism for source data of some sort. My bad. I think that Pydantic (or Beartype) does a better job and offers many advantages: easier to opt out, automatic handling of non-annotated parameters, etc. For your information, we already have a So, what do you think of the following plan?
The first point makes sense because the For the second point, we are already performing validate_call at the interface level, so removing what is arguably redundant functionality makes sense. |
Sounds great! |
I implemented your feedback, @bendichter, and changed from omission to error and modified the test. Thanks for the discussion. |
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 8287 +98
==========================================
+ Hits 7427 7521 +94
- Misses 762 766 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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.