-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-107954, PEP 741: Add PyConfig_Get() function #123472
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
Changes from all commits
4c79a52
988dca5
2d592a6
4e0951e
edc9974
4616b52
135d862
2324465
0c20c8a
67210db
262738f
fcf0918
a39857e
2014c52
4a3595c
8c321f1
1556b95
b655e93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1605,6 +1605,75 @@ customized Python always running in isolated mode using | |
:c:func:`Py_RunMain`. | ||
|
||
|
||
Runtime Python configuration API | ||
================================ | ||
|
||
The configuration option *name* parameter must be a non-NULL null-terminated | ||
UTF-8 encoded string. | ||
|
||
Some options are read from the :mod:`sys` attributes. For example, the option | ||
``"argv"`` is read from :data:`sys.argv`. | ||
|
||
|
||
.. c:function:: PyObject* PyConfig_Get(const char *name) | ||
|
||
Get the current runtime value of a configuration option as a Python object. | ||
|
||
* Return a new reference on success. | ||
* Set an exception and return ``NULL`` on error. | ||
|
||
The object type depends on the configuration option. It can be: | ||
|
||
* ``bool`` | ||
* ``int`` | ||
* ``str`` | ||
* ``list[str]`` | ||
* ``dict[str, str]`` | ||
|
||
The caller must hold the GIL. The function cannot be called before | ||
Python initialization nor after Python finalization. | ||
vstinner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.. versionadded:: 3.14 | ||
|
||
|
||
.. c:function:: int PyConfig_GetInt(const char *name, int *value) | ||
|
||
Similar to :c:func:`PyConfig_Get`, but get the value as a C int. | ||
vstinner marked this conversation as resolved.
Show resolved
Hide resolved
10000
div>
|
||
|
||
* Return ``0`` on success. | ||
* Set an exception and return ``-1`` on error. | ||
|
||
.. versionadded:: 3.14 | ||
|
||
|
||
.. c:function:: PyObject* PyConfig_Names(void) | ||
|
||
Get all configuration option names as a ``frozenset``. | ||
|
||
* Return a new reference on success. | ||
* Set an exception and return ``NULL`` on error. | ||
|
||
The caller must hold the GIL. The function cannot be called before | ||
Python initialization nor after Python finalization. | ||
|
||
.. versionadded:: 3.14 | ||
|
||
|
||
.. c:function:: int PyConfig_Set(const char *name, PyObject *value) | ||
|
||
Set the current runtime value of a configuration option. | ||
|
||
* Raise a :exc:`ValueError` if there is no option *name*. | ||
* Raise a :exc:`ValueError` if *value* is an invalid value. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does it mean to be an invalid value? is it when it's NULL? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example, pass a negative number when a bool is expected. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC you accept >= 0 for bools but not < 0 right? maybe this could be added in the docs (maybe add something after the The object type depends on the configuration option. It can be:
* ``bool`` (nonnegative integer) Something like that? |
||
* Raise a :exc:`ValueError` if the option is read-only (cannot be set). | ||
* Raise a :exc:`TypeError` if *value* has not the proper type. | ||
|
||
The caller must hold the GIL. The function cannot be called before | ||
Python initialization nor after Python finalization. | ||
|
||
.. versionadded:: 3.14 | ||
|
||
|
||
Py_GetArgcArgv() | ||
================ | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.