This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Auto-generate exceptions.c from a Python file
Type: enhancement Stage: needs patch
Components: Interpreter Core Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: abarry, brett.cannon, matrixise
Priority: low Keywords:

Created on 2014-04-15 18:12 by brett.cannon, last changed 2022-04-11 14:58 by admin.

Messages (3)
msg216354 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2014-04-15 18:12
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. =)
msg242219 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2015-04-29 09:50
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
msg242221 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2015-04-29 12:43
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:

1. Identify which exceptions are necessary to load the Python code holding some built-in exceptions
2. Write Python code for the exceptions which are not necessary for interpreter startup
3. Load the Python file during startup ala importlib
4. Make sure the exceptions make it into the builtin namespace
5. Make sure the exceptions end up in the proper C global variables
History
Date User Action Args
2022-04-11 14:58:01adminsetgithub: 65442
2020-03-18 18:28:41brett.cannonsetversions: + Python 3.9, - Python 3.6
2015-11-04 01:27:55abarrysetnosy: + abarry
2015-11-03 22:01:15matrixisesetversions: + Python 3.6, - Python 3.5
2015-04-29 12:43:27brett.cannonsetmessages: + msg242221
2015-04-29 09:50:15matrixisesetnosy: + matrixise
messages: + msg242219
2014-04-15 18:12:29brett.cannoncreate