-
Notifications
You must be signed in to change notification settings - Fork 5
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
Pass types for repeated containers #119
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes a lot of sense, this possibility was only introduced in a later PR after my initial refactor upstream. Did you check if this interacts with any attribute type checking we have going on? For instance when something of the wrong type gets passed in. Otherwise I think LGTM.
@jbachurski Is this test covering that failure mode? Also, is it acceptable that the errors are now raised from different places and not our custom validation? Do you see any potential issues with that, and if yes, what other tests would you add? The errors are now raised from protobuf/onnx:
whereas before, they originated from our validation:
note that for strings, we always raised from the call to
|
I think it would be preferable if we could display a more descriptive error message than the protobuf error message. Given this is coupled with the ONNX version anyway, can you catch the exception accurately? |
The encode AttributeError looks like an oversight. The protobuf error isn’t that bad, but I agree with Aditya it might be useful to be more descriptive why and when the error got raised. I was primarily concerned whether the error is handled gracefully at all - testing for expected error messages isn’t something I did enough but it’s good to start setting these standards. |
I think it is fine to rely on upstream for this kind of validation. We can always improve error messages, but this is good for now. Thanks a lot! |
Can we still merge #122 here? It has other small improvements:
|
I agree it should be merged here - I don't think it's good that we are testing for the |
* what is this * Hacky implementation * Don't encode and raise a better error * Separate type checking to a function * abstracted calls to make_attribute and deduce_type in parent + improved error messages * Revert to old type validation since we'd like to try with caching first * Changelog * Update src/spox/_attributes.py Co-authored-by: Jakub Bachurski <[email protected]> * Kuba's comments * Christian's comments * Change custom exception name * Don't use a custom exception * Update CHANGELOG.rst Co-authored-by: Christian Bourjau <[email protected]> * Exception message --------- Co-authored-by: Jakub Bachurski <[email protected]> Co-authored-by: Christian Bourjau <[email protected]>
FYI, this will also enable empty sequences to be serialised! |
The most time-consuming thing in
make_attribute
is iterating the values. By passing the attribute type, we save one pass, which could run 10-30% faster (depending on the amount of other work done).