Skip to content

Allow efficient read access to PyConfig options #99872

Open
@scoder

Description

@scoder

Documentation

The documentation seems to be geared towards embedding scenarios and modifying the configuration, and I couldn't find an example for simply reading a PyConfig field.

PEP 587 seems similarly unhelpful.

Looking through the CPython sources, it appears that what I want to do is this:

    PyThreadState *tstate = _PyThreadState_GET();
    PyConfig* config = &tstate->interp->config;
    int optimize_flag = config->optimization_level;  // formerly known as Py_OptimizeFlag

I'm pretty sure that this is not the official API way to do it, but it's unclear to me what the right way is, given that PyInterpreterState is an opaque struct and the previously simple access to Py_OptimizeFlag has been deprecated as of Py3.12.

Also, it's unclear what way of access should be used in the limited API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions