-
Notifications
You must be signed in to change notification settings - Fork 6
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
Infallible functions #20
Comments
If a function never fails, why does it need to report a failure? Or do you mean functions that can fail and have to hide that failure, like |
Here's a concrete example: |
That doesn't seem like it is infallible, that seems like the API is flawed. There are infallible functions, e.g. |
Yes, the API is flawed. Same with |
Wouldn't In a sense even (especially?!) |
You're right, it does. My mistake. |
IMO, so few API functions are infallible (in all possible implementations) that any guidelines should say there should be a way to report errors. Any exceptions need to be carefully thought out. When failure is impossible in the current implementation and the check is too expensive, inline the function and let the compiler elide the check. |
|
Can we just add a return value to this function? It's void now, and it's not in the stable ABI, so it shouldn't break anything. |
To 3.13, yes. But for a function that previously didn't set an exception at all, adding such an error case would, IMO, be an API break: there should be a new function and the old one should be deprecated. |
Labelling this as fixable, let's work on it in python/cpython#105184. |
Concrete example: I wanted to add
|
We can work on guidelines for new APIs here: python/devguide#1122 |
It's convenient to have functions which cannot fail: it avoids to have to write boring (complex to write, easy to mess up error handling code, etc.) error code path. For example, getter functions like Well, then things become more complicated :-) Until Python 3.10, |
Also, emitting a warning can cause errors ( |
When a function evolved and then can fail but the API cannot report error, a possible workaround is to log the error with |
Proposed guideline issues: |
Several functions currently never fail, and don't have a way to report failure. This blocks development of features that need an error condition.
The text was updated successfully, but these errors were encountered: