-
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
Add new select syntax #23
Conversation
I'm not sure I know what you mean by "user error", but I believe that this should be an assertion for several reasons:
Are there any other built-in exceptions that are better suited, in your opinion? |
I don't want to be boring, but it is a fact that assertions are for testing only. https://mail.python.org/pipermail/python-list/2013-November/660401.html As a short reason: your code will be unprotected, if somebody runs it with .pyo :-D ad 1.: Sure, things should and must be checked, but not with assert, but raising something explicitly. ad 2.: As long as the assertions are checking the correctness of the implementation, they are perfectly valid, because that is meant. As soon as the assertion checks user-provided input, it is wrongly designed code. I have no preference to introduce a new error or use a simple pre-defined one. Important is that there is always an error raised. You can even explicitly raise an AssertionError ;-) |
Sorry for the delay- I will check this out as soon as I have internet again. |
@@ -54,6 +54,11 @@ def select(cases): | |||
:return: ``(chosen case, received value)``. | |||
If the chosen case is not an :class:`goless.rcase`, it will be None. | |||
""" | |||
# Sanity check - if the first argument is a list, it should be the only argument | |||
if isinstance(cases[0], list): |
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.
Calling select with no cases should not result in an IndexError. IMO it should just work, like it has.
This is not really a case for an assert, this is a case for a TypeError or ValueError. Sometimes I will use assert to sanitize values, but not for public APIs. |
@MichaelAz I'd like to get this in so I can cut a 0.6.1 release. Can you clean this up, or should I redo your changes? |
I was under the impression I addressed all of your comments but I've missed that last one. I just pushed an update. Anything else or can this be merged? |
Sorry, somehow missed your recent changes. |
Both adressed. |
Select can now accept
*args
and will throw for a combination of a list and*args
as discussed in #22