-
Notifications
You must be signed in to change notification settings - Fork 766
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
Use of assert/exceptions should follow the code style guide #99
Comments
asserts are only (currently) removed on CPy when doing -O. On PyPy, asserts are always compiled and executed! |
Should we use asserts? Should we extensively time-check arguments at run-time? Where and where not? |
My opinion is: we should use For one thing, most users when seeing a traceback from an Also, there should probably be at least one unit-test covering the assert-ed statement. Essentially, I view |
pypy: http://paste.pound-python.org/show/yeHGJ8p41aVSEFx3gCKW/
fijal (irc):
|
Like a user calling Should we assume users can't read / are dumb? ;) |
Say we would use assert only for this: if an assert fails, it means we have a bug within the library So we wouldn't use assert for checking public API entry points into the library. My main concern. How do we do that? We can't use the new type annotations, as these are just for static code analysis. Right? So we would use plain old: def publish(topic, *args, **kwargs):
if type(topic) != unicode:
raise TypeError("URIs must be unicode - got {} instead".format(type(topic))) ? |
Yes, I think if an error could reasonably be seen by a user, it should be a "real" Exception (or RuntimeError). Or, as above, sometimes the built-in exceptions are the right answer (but, IMO, one should reach for RuntimeError/Exception first).
|
Yeah, I think that's a good approach. |
@meejah @hawkowl ok: https://github.com/tavendo/AutobahnPython/blob/master/DEVELOPERS.md#use-of-assert-vs-exceptions I leave this issue open for actually cleanup up the code according to above guide line. |
related: #486 |
=> can be optimized away when doing compile for pyo's
The text was updated successfully, but these errors were encountered: