-
Notifications
You must be signed in to change notification settings - Fork 65
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
Enhance ValueError messages (#148 and #157) #185
Enhance ValueError messages (#148 and #157) #185
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.
No complaints, I agree that this is much cleaner
@@ -147,11 +147,13 @@ def test_max_connectivity(): | |||
reg = Register.max_connectivity(2, None) | |||
|
|||
# Check min number of atoms | |||
with pytest.raises(ValueError, match=r"The number of qubits(.+)or above"): | |||
with pytest.raises(ValueError, | |||
match=r"The number of qubits(.+)greater than"): |
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.
Cool, I didn't know about this syntax
@LaurentAjdnik So, how do you want to go about this? Doing this for the whole code seems like a big task. But also, I was wondering about how we can enforce it automatically, for anyone contributing to the code base. I had an idea to have a test in CI that would search the code for specific errors and check if their message is valid. For example, it would identify "threshold" value errors and check if the message follows the specific guidelines. What do you think about this? |
Still, I had planned to do it. 😇
Automatically? I have not clue... I can only think of writing guidelines in
Cool! How would you do that? |
Thanks a lot for the initiative!
First, we have to layout all the guidelines for the error messages. At first, we could try to check for specific patterns that all errors of a given type should follow, based on these guidelines. This will be easier said than done, considering the variability that can occur within a single error type (eg |
@LaurentAjdnik do you have anything to add to this PR before I merge it? |
Nope. |
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.
LGTM
Indeed, it does sound like a lot of hassle for something not so worth it. I guess we should keep it simple for now: Let's officialize some guidelines, make sure all existing ValueErrors are updated accordingly (*) and check any PR coming in. (*) Most of the time, when in doubt, people check existing parts of code to make sure they comply to guidelines. That's what I did anyway. 😉 |
I agree. My only concern is the compliance with the guidelines, and the need for the reviewer to remember to check for them. In general, I prefer to have as much checks as possible happening automatically, so as not to pile on the things the reviewer as to look for. But I agree that, at least for now, what you suggest seems sufficient. |
For feedback: First attempt to enhance ValueError messages (see #148 and #157), starting with
register.py
.Guidelines: