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
Auto-generate exceptions.c from a Python file #65442
Comments
There isn't very much that's special about the various exceptions (although maybe there will be some day). Anyway, it seems like we could, if we so desired, define the exceptions in Python and then auto-generate the C code. The other option is to obviously just load the exceptions from Python code, store the various objects in various C attributes, and update the C API for exceptions to operate off of the Python-defined exception objects (question is what performance impact that would have). The key question, though, is whether any of this is actually worth it. =) |
I think I have understood your issue, but can you explain with more details. If I can develop this part, I can propose a patch for your issue. Thank you for your time |
All of the exception code is written in C. My hypothesis is that it isn't necessary to define *all* exceptions in C. Using a technique similar to importlib, I suspect we could write a bunch of the exceptions that are not critical to interpreter startup in Python for easier maintenance and usage by other interpreters. You would need to make sure the Python objects did get set on the proper C global variables for access by C extension code. You could use BaseException or something temporarily for all exceptions before loading the Python code and then replace the temporary placeholders with the actual exceptions. IOW, you would need to:
|
I think this would increase maintenance burden rather than reduce it. The exceptions are currently defined in one place with one pattern. With this proposal there would be two patterns, with the additional burden of deciding which exception should be defined with each pattern (and maintaining this decision as things may change in the future). The C implementation of exceptions uses macros to avoid code duplication for the simple exceptions (those that could be auto generated from python). So even just for those exceptions I don’t think this will reduce maintenance burden. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: