-
Notifications
You must be signed in to change notification settings - Fork 2
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
[CQT-289] Avoid creating an Axis (0, 0, 0) #406
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.
OK, let's have a look at the Axis class globally, and try to refine the logic a bit while not duplicating code.
We have already this function _parse_and_validate_axislike
that parses and normalizes:
- I would divide it into two functions: one for parsing and the other one for normalizing, e.g.,
parse
andnormalize
(this latter already exists). Can they both be static methods? - I would add the check for
!(0, 0, 0)
to thatparse
method.
Now, if we go back to the constructor, can we do?
axis_to_parse = axis[0] if axis is a list, otherwise axis
self._value = Axis.parse(axis_to_parse)
self._value = Axis.normalize(self._value)
We can write 3 parametrized tests for each function: constructor, Axis.parse
, and Axis.normalize
.
Let me know how you see it!
@rturrado if we split the functions, parse "should" return the axis object. Shall we return false if the Axis is invalid? |
We should raise a ValueError. |
I agree that usually a ValueError would be best practice. However, the ticket states that we want to create an Axis without a try/catch block: So I believe that in this case, maybe it is better to return False? |
No, Guy, let's try to raise the exception. I wrote that ticket. As you can see, I was valuing options, wondering, not stating anything. |
Ah alright! I'll raise the exception :) |
…into CQT-289-Avoid-creating-an-Axis-0-0-0
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.
Good work, Guy.
I've added a few comments.
…into CQT-289-Avoid-creating-an-Axis-0-0-0
Avoids that an axis of (0, 0, 0) can be created and allows the user to check for this instance before instantiating the class.