python / python/cpython

Allow `FrameType` to be instantiated

Open
#149,844 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

interpreter-core type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Feature or enhancement

Proposal:

For some reason, FrameType is not allowed to be instantiated. This creates problems when trying to (for example) control an exception traceback, which is common for debuggers, among other uses. This is also inconsistant with most other internal types that exposed to Python and in the types module.

The only reason I can think of is because PyFrame_New requires a PyThreadState object, which is not exposed to Python. However, there are several ways around this:

  • Run PyThreadState_GetUnchecked, raising RuntimeError (or another error) if NULL is returned
  • Expose frames' PyThreadState to the interpreter
  • Pass another frame as a parameter, and get its thread state

This should be relatively trivial to implement and I can't think of any downsides, backwards compatibility concerns, or maintenance overhead. I can probably write a PR if one of the solutions to the thread state parameter is decided.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the FrameType instantiation path and the PyFrame_New and PyThreadState_GetUnchecked entry points named in the issue. Decide how instantiation should obtain or validate a thread state, then confirm that FrameType can be created from Python without breaking the stated traceback and debugger use cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.