-
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
Ambiguous return values #1
Comments
|
|
Maybe ambiguous return values are OK themselves, but it's the way we disambiguate that needs improving? Maybe we should look focus on Why is an |
IMO that's a related, but slightly different issue. I'd consider creating a separate issue for those problems. |
It' not a different issue, it's this issue. And I'm sure we've already discussed it elsewhere. Ambiguous return values force us to access globals state. This has two problems:
|
Trouble is, they need to do that anyway if
Yup. Users ideally need assert |
We should have an issue for that, and think how we can avoid being stuck with every mistake forever in the new api. |
I don't see why. If all functions are explicit in their output on whether there was an error or not, then why should users need |
We could change the title of this issue to "PyErr_Occurred() should not be part of the API". |
Because you need Removing |
I don't think this issue is about alternative implementations or about the problems with maintaining global state. It is about the uncertainty that remains when an API requires calling For example, with Redesigning these "ambiguous" APIs incrementally to avoid this trap feels like a worthwhile improvement, since it can be done on a shorter timescale than redesigning the entire global error state system. We just need to word the motivation carefully, in particular we want to avoid the requirement to call (Separately, we might want to do an audit of code that calls |
|
I presume you are referring to collation_callback. I'm guessing that C code not under your control calls this function multiple times without checking for an error response (since that sqlite API doesn't seem to be designed to have an error response). That makes sense -- and yeah, if we're solving hypothetical problems, if the interpreter did not manage global error state at all (or at least did not provide access to it) you could solve it differently (e.g. put a flag in the To me, the problem we're trying to fix here is APIs that require using |
Exactly.
Yep. |
See also python/devguide#1121 |
I do not think that there is a serious problem urging us to to fix it. In most of these cases the value used to indicate error is an uncommon, unexpected result, so it usually does not have significant performance impact.
Functions like An alternate approach is used in |
I don't think that this project only lists issues which MUST be fixed immediately. It's also about issues which should be avoided when designing new APIs. |
|
Consistency is vital. |
The Python C API has a big pile of legacy APIs. Many functions with known issues are kept for "backward compatibility": remove them is not worth it. Are you suggesting to quicky shift towards a "sane only" API by eaggerly remove the legacy APIs? I propose to design a new API which would be smaller and with no known issues: issue #54. |
See python/devguide#1123 for proposed guidelines. |
A 2016 bug for this: python/cpython#70963 |
Guideline proposal: capi-workgroup/api-evolution#13 |
I propose new PyLong API which returns 0 on success and -1 on error: python/cpython#120389 |
For converters from Python object there is another convention, used with the |
In addition to standard converters in the public C API ( |
Some C API functions can return a value which may or may not indicate an error, and require disambiguation with PyErr_Occurred(). They should be replaced by new versions with unambiguous return values.
Ambiguous return values
PyCapsule_GetDestructor
PyCapsule_GetContext
PyCapsule_GetName
PyDict_GetItemWithError
PyFloat_AsDouble
PyFloat_Unpack2
PyFloat_Unpack4
PyFloat_Unpack8
PyIter_Next
PyLong_AsLong
PyLong_AsLongAndOverflow
PyLong_AsLongLong
PyLong_AsLongLongAndOverflow
PyLong_AsSsize_t
PyLong_AsUnsignedLong
PyLong_AsSize_t
PyLong_AsUnsignedLongLong
PyLong_AsUnsignedLongMask
PyLong_AsDouble
PyLong_AsVoidPtr
PyMarshal_ReadLongFromFile
PyMarshal_ReadShortFromFile
PyNumber_AsSsize_t
PyUnicode_Compare
no return value, but can set an exception that can only be checked with PyErr_Occurred:
PyMarshal_WriteObjectToFile
The text was updated successfully, but these errors were encountered: