Skip to content
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

Closed
brettcannon opened this issue Apr 15, 2014 · 4 comments
Closed

Auto-generate exceptions.c from a Python file #65442

brettcannon opened this issue Apr 15, 2014 · 4 comments
Labels
3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@brettcannon
Copy link
Member

BPO 21243
Nosy @brettcannon, @matrixise, @Vgr255

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:

assignee = None
closed_at = None
created_at = <Date 2014-04-15.18:12:29.123>
labels = ['interpreter-core', 'type-feature', '3.9']
title = 'Auto-generate exceptions.c from a Python file'
updated_at = <Date 2020-03-18.18:28:41.984>
user = 'https://github.com/brettcannon'

bugs.python.org fields:

activity = <Date 2020-03-18.18:28:41.984>
actor = 'brett.cannon'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Interpreter Core']
creation = <Date 2014-04-15.18:12:29.123>
creator = 'brett.cannon'
dependencies = []
files = []
hgrepos = []
issue_num = 21243
keywords = []
message_count = 3.0
messages = ['216354', '242219', '242221']
nosy_count = 3.0
nosy_names = ['brett.cannon', 'matrixise', 'abarry']
pr_nums = []
priority = 'low'
resolution = None
stage = 'needs patch'
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue21243'
versions = ['Python 3.9']

@brettcannon
Copy link
Member Author

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. =)

@brettcannon brettcannon added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Apr 15, 2014
@matrixise
Copy link
Member

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

@brettcannon
Copy link
Member Author

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

@brettcannon brettcannon added the 3.9 only security fixes label Mar 18, 2020
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@iritkatriel
Copy link
Member

iritkatriel commented Apr 21, 2023

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.

@brettcannon brettcannon closed this as not planned Won't fix, can't repro, duplicate, stale May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants