Skip to content

Commit 7242fea

Browse files
authored
gh-158001: Remove global configuration variables from C API (#158020)
Keep 4 variables in the stable ABI: * Py_FileSystemDefaultEncodeErrors * Py_FileSystemDefaultEncoding * Py_HasFileSystemDefaultEncoding * Py_UTF8Mode Mark the 4 variables as ABI only in Misc/stable_abi.toml.
1 parent 9b3fc89 commit 7242fea

20 files changed

Lines changed: 230 additions & 650 deletions

File tree

‎Doc/c-api/interp-lifecycle.rst‎

Lines changed: 1 addition & 273 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ Before Python initialization
1515

1616
In an application embedding Python, the :c:func:`Py_Initialize` function must
1717
be called before using any other Python/C API functions; with the exception of
18-
a few functions and the :ref:`global configuration variables
19-
<global-conf-vars>`.
18+
a few functions.
2019

2120
The following functions can be safely called before Python is initialized:
2221

@@ -75,277 +74,6 @@ The following functions can be safely called before Python is initialized:
7574
been initialized: :c:func:`Py_EncodeLocale`, and :c:func:`Py_RunMain`.
7675

7776

78-
.. _global-conf-vars:
79-
80-
Global configuration variables
81-
------------------------------
82-
83-
Python has variables for the global configuration to control different features
84-
and options. By default, these flags are controlled by :ref:`command line
85-
options <using-on-interface-options>`.
86-
87-
When a flag is set by an option, the value of the flag is the number of times
88-
that the option was set. For example, ``-b`` sets :c:data:`Py_BytesWarningFlag`
89-
to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
90-
91-
92-
.. c:var:: int Py_BytesWarningFlag
93-
94-
This API is kept for backward compatibility: setting
95-
:c:member:`PyConfig.bytes_warning` should be used instead, see :ref:`Python
96-
Initialization Configuration <init-config>`.
97-
98-
Issue a warning when comparing :class:`bytes` or :class:`bytearray` with
99-
:class:`str` or :class:`bytes` with :class:`int`. Issue an error if greater
100-
or equal to ``2``.
101-
102-
Set by the :option:`-b` option.
103-
104-
.. deprecated-removed:: 3.12 3.16
105-
106-
107-
.. c:var:: int Py_DebugFlag
108-
109-
This API is kept for backward compatibility: setting
110-
:c:member:`PyConfig.parser_debug` should be used instead, see :ref:`Python
111-
Initialization Configuration <init-config>`.
112-
113-
Turn on parser debugging output (for expert only, depending on compilation
114-
options).
115-
116-
Set by the :option:`-d` option and the :envvar:`PYTHONDEBUG` environment
117-
variable.
118-
119-
.. deprecated-removed:: 3.12 3.16
120-
121-
122-
.. c:var:: int Py_DontWriteBytecodeFlag
123-
124-
This API is kept for backward compatibility: setting
125-
:c:member:`PyConfig.write_bytecode` should be used instead, see :ref:`Python
126-
Initialization Configuration <init-config>`.
127-
128-
If set to non-zero, Python won't try to write ``.pyc`` files on the
129-
import of source modules.
130-
131-
Set by the :option:`-B` option and the :envvar:`PYTHONDONTWRITEBYTECODE`
132-
environment variable.
133-
134-
.. deprecated-removed:: 3.12 3.16
135-
136-
137-
.. c:var:: int Py_FrozenFlag
138-
139-
This API is kept for backward compatibility: setting
140-
:c:member:`PyConfig.pathconfig_warnings` should be used instead, see
141-
:ref:`Python Initialization Configuration <init-config>`.
142-
143-
Private flag used by ``_freeze_module`` and ``frozenmain`` programs.
144-
145-
.. deprecated-removed:: 3.12 3.16
146-
147-
148-
.. c:var:: int Py_HashRandomizationFlag
149-
150-
This API is kept for backward compatibility: setting
151-
:c:member:`PyConfig.hash_seed` and :c:member:`PyConfig.use_hash_seed` should
152-
be used instead, see :ref:`Python Initialization Configuration
153-
<init-config>`.
154-
155-
Set to ``1`` if the :envvar:`PYTHONHASHSEED` environment variable is set to
156-
a non-empty string.
157-
158-
If the flag is non-zero, read the :envvar:`PYTHONHASHSEED` environment
159-
variable to initialize the secret hash seed.
160-
161-
.. deprecated-removed:: 3.12 3.16
162-
163-
164-
.. c:var:: int Py_IgnoreEnvironmentFlag
165-
166-
This API is kept for backward compatibility: setting
167-
:c:member:`PyConfig.use_environment` should be used instead, see
168-
:ref:`Python Initialization Configuration <init-config>`.
169-
170-
Ignore all :envvar:`!PYTHON*` environment variables, e.g.
171-
:envvar:`PYTHONPATH` and :envvar:`PYTHONHOME`, that might be set.
172-
173-
Set by the :option:`-E` and :option:`-I` options.
174-
175-
.. deprecated-removed:: 3.12 3.16
176-
177-
178-
.. c:var:: int Py_InspectFlag
179-
180-
This API is kept for backward compatibility: setting
181-
:c:member:`PyConfig.inspect` should be used instead, see
182-
:ref:`Python Initialization Configuration <init-config>`.
183-
184-
When a script is passed as first argument or the :option:`-c` option is used,
185-
enter interactive mode after executing the script or the command, even when
186-
:data:`sys.stdin` does not appear to be a terminal.
187-
188-
Set by the :option:`-i` option and the :envvar:`PYTHONINSPECT` environment
189-
variable.
190-
191-
.. deprecated-removed:: 3.12 3.16
192-
193-
194-
.. c:var:: int Py_InteractiveFlag
195-
196-
This API is kept for backward compatibility: setting
197-
:c:member:`PyConfig.interactive` should be used instead, see
198-
:ref:`Python Initialization Configuration <init-config>`.
199-
200-
Set by the :option:`-i` option.
201-
202-
.. deprecated-removed:: 3.12 3.16
203-
204-
205-
.. c:var:: int Py_IsolatedFlag
206-
207-
This API is kept for backward compatibility: setting
208-
:c:member:`PyConfig.isolated` should be used instead, see
209-
:ref:`Python Initialization Configuration <init-config>`.
210-
211-
Run Python in isolated mode. In isolated mode :data:`sys.path` contains
212-
neither the script's directory nor the user's site-packages directory.
213-
214-
Set by the :option:`-I` option.
215-
216-
.. versionadded:: 3.4
217-
218-
.. deprecated-removed:: 3.12 3.16
219-
220-
221-
.. c:var:: int Py_LegacyWindowsFSEncodingFlag
222-
223-
This API is kept for backward compatibility: setting
224-
:c:member:`PyPreConfig.legacy_windows_fs_encoding` should be used instead, see
225-
:ref:`Python Initialization Configuration <init-config>`.
226-
227-
If the flag is non-zero, use the ``mbcs`` encoding with ``replace`` error
228-
handler, instead of the UTF-8 encoding with ``surrogatepass`` error handler,
229-
for the :term:`filesystem encoding and error handler`.
230-
231-
Set to ``1`` if the :envvar:`PYTHONLEGACYWINDOWSFSENCODING` environment
232-
variable is set to a non-empty string.
233-
234-
See :pep:`529` for more details.
235-
236-
.. availability:: Windows.
237-
238-
.. deprecated-removed:: 3.12 3.16
239-
240-
241-
.. c:var:: int Py_LegacyWindowsStdioFlag
242-
243-
This API is kept for backward compatibility: setting
244-
:c:member:`PyConfig.legacy_windows_stdio` should be used instead, see
245-
:ref:`Python Initialization Configuration <init-config>`.
246-
247-
If the flag is non-zero, use :class:`io.FileIO` instead of
248-
:class:`!io._WindowsConsoleIO` for :mod:`sys` standard streams.
249-
250-
Set to ``1`` if the :envvar:`PYTHONLEGACYWINDOWSSTDIO` environment
251-
variable is set to a non-empty string.
252-
253-
See :pep:`528` for more details.
254-
255-
.. availability:: Windows.
256-
257-
.. deprecated-removed:: 3.12 3.16
258-
259-
260-
.. c:var:: int Py_NoSiteFlag
261-
262-
This API is kept for backward compatibility: setting
263-
:c:member:`PyConfig.site_import` should be used instead, see
264-
:ref:`Python Initialization Configuration <init-config>`.
265-
266-
Disable the import of the module :mod:`site` and the site-dependent
267-
manipulations of :data:`sys.path` that it entails. Also disable these
268-
manipulations if :mod:`site` is explicitly imported later (call
269-
:func:`site.main` if you want them to be triggered).
270-
271-
Set by the :option:`-S` option.
272-
273-
.. deprecated-removed:: 3.12 3.16
274-
275-
276-
.. c:var:: int Py_NoUserSiteDirectory
277-
278-
This API is kept for backward compatibility: setting
279-
:c:member:`PyConfig.user_site_directory` should be used instead, see
280-
:ref:`Python Initialization Configuration <init-config>`.
281-
282-
Don't add the :data:`user site-packages directory <site.USER_SITE>` to
283-
:data:`sys.path`.
284-
285-
Set by the :option:`-s` and :option:`-I` options, and the
286-
:envvar:`PYTHONNOUSERSITE` environment variable.
287-
288-
.. deprecated-removed:: 3.12 3.16
289-
290-
291-
.. c:var:: int Py_OptimizeFlag
292-
293-
This API is kept for backward compatibility: setting
294-
:c:member:`PyConfig.optimization_level` should be used instead, see
295-
:ref:`Python Initialization Configuration <init-config>`.
296-
297-
Set by the :option:`-O` option and the :envvar:`PYTHONOPTIMIZE` environment
298-
variable.
299-
300-
.. deprecated-removed:: 3.12 3.16
301-
302-
303-
.. c:var:: int Py_QuietFlag
304-
305-
This API is kept for backward compatibility: setting
306-
:c:member:`PyConfig.quiet` should be used instead, see :ref:`Python
307-
Initialization Configuration <init-config>`.
308-
309-
Don't display the copyright and version messages even in interactive mode.
310-
311-
Set by the :option:`-q` option.
312-
313-
.. versionadded:: 3.2
314-
315-
.. deprecated-removed:: 3.12 3.16
316-
317-
318-
.. c:var:: int Py_UnbufferedStdioFlag
319-
320-
This API is kept for backward compatibility: setting
321-
:c:member:`PyConfig.buffered_stdio` should be used instead, see :ref:`Python
322-
Initialization Configuration <init-config>`.
323-
324-
Force the stdout and stderr streams to be unbuffered.
325-
326-
Set by the :option:`-u` option and the :envvar:`PYTHONUNBUFFERED`
327-
environment variable.
328-
329-
.. deprecated-removed:: 3.12 3.16
330-
331-
332-
.. c:var:: int Py_VerboseFlag
333-
334-
This API is kept for backward compatibility: setting
335-
:c:member:`PyConfig.verbose` should be used instead, see :ref:`Python
336-
Initialization Configuration <init-config>`.
337-
338-
Print a message each time a module is initialized, showing the place
339-
(filename or built-in module) from which it is loaded. If greater or equal
340-
to ``2``, print a message for each file that is checked for when
341-
searching for a module. Also provides information on module cleanup at exit.
342-
343-
Set by the :option:`-v` option and the :envvar:`PYTHONVERBOSE` environment
344-
variable.
345-
346-
.. deprecated-removed:: 3.12 3.16
347-
348-
34977
Initializing and finalizing the interpreter
35078
-------------------------------------------
35179

‎Doc/data/stable_abi.dat‎

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Doc/deprecations/c-api-pending-removal-in-3.16.rst‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,56 +17,56 @@ Pending removal in Python 3.16
1717

1818
* Global configuration variables:
1919

20-
* :c:var:`Py_DebugFlag`:
20+
* :c:var:`!Py_DebugFlag`:
2121
Use :c:member:`PyConfig.parser_debug` or
2222
:c:func:`PyConfig_Get("parser_debug") <PyConfig_Get>` instead.
23-
* :c:var:`Py_VerboseFlag`:
23+
* :c:var:`!Py_VerboseFlag`:
2424
Use :c:member:`PyConfig.verbose` or
2525
:c:func:`PyConfig_Get("verbose") <PyConfig_Get>` instead.
26-
* :c:var:`Py_QuietFlag`:
26+
* :c:var:`!Py_QuietFlag`:
2727
Use :c:member:`PyConfig.quiet` or
2828
:c:func:`PyConfig_Get("quiet") <PyConfig_Get>` instead.
29-
* :c:var:`Py_InteractiveFlag`:
29+
* :c:var:`!Py_InteractiveFlag`:
3030
Use :c:member:`PyConfig.interactive` or
3131
:c:func:`PyConfig_Get("interactive") <PyConfig_Get>` instead.
32-
* :c:var:`Py_InspectFlag`:
32+
* :c:var:`!Py_InspectFlag`:
3333
Use :c:member:`PyConfig.inspect` or
3434
:c:func:`PyConfig_Get("inspect") <PyConfig_Get>` instead.
35-
* :c:var:`Py_OptimizeFlag`:
35+
* :c:var:`!Py_OptimizeFlag`:
3636
Use :c:member:`PyConfig.optimization_level` or
3737
:c:func:`PyConfig_Get("optimization_level") <PyConfig_Get>` instead.
38-
* :c:var:`Py_NoSiteFlag`:
38+
* :c:var:`!Py_NoSiteFlag`:
3939
Use :c:member:`PyConfig.site_import` or
4040
:c:func:`PyConfig_Get("site_import") <PyConfig_Get>` instead.
41-
* :c:var:`Py_BytesWarningFlag`:
41+
* :c:var:`!Py_BytesWarningFlag`:
4242
Use :c:member:`PyConfig.bytes_warning` or
4343
:c:func:`PyConfig_Get("bytes_warning") <PyConfig_Get>` instead.
44-
* :c:var:`Py_FrozenFlag`:
44+
* :c:var:`!Py_FrozenFlag`:
4545
Use :c:member:`PyConfig.pathconfig_warnings` or
4646
:c:func:`PyConfig_Get("pathconfig_warnings") <PyConfig_Get>` instead.
47-
* :c:var:`Py_IgnoreEnvironmentFlag`:
47+
* :c:var:`!Py_IgnoreEnvironmentFlag`:
4848
Use :c:member:`PyConfig.use_environment` or
4949
:c:func:`PyConfig_Get("use_environment") <PyConfig_Get>` instead.
50-
* :c:var:`Py_DontWriteBytecodeFlag`:
50+
* :c:var:`!Py_DontWriteBytecodeFlag`:
5151
Use :c:member:`PyConfig.write_bytecode` or
5252
:c:func:`PyConfig_Get("write_bytecode") <PyConfig_Get>` instead.
53-
* :c:var:`Py_NoUserSiteDirectory`:
53+
* :c:var:`!Py_NoUserSiteDirectory`:
5454
Use :c:member:`PyConfig.user_site_directory` or
5555
:c:func:`PyConfig_Get("user_site_directory") <PyConfig_Get>` instead.
56-
* :c:var:`Py_UnbufferedStdioFlag`:
56+
* :c:var:`!Py_UnbufferedStdioFlag`:
5757
Use :c:member:`PyConfig.buffered_stdio` or
5858
:c:func:`PyConfig_Get("buffered_stdio") <PyConfig_Get>` instead.
59-
* :c:var:`Py_HashRandomizationFlag`:
59+
* :c:var:`!Py_HashRandomizationFlag`:
6060
Use :c:member:`PyConfig.use_hash_seed`
6161
and :c:member:`PyConfig.hash_seed` or
6262
:c:func:`PyConfig_Get("hash_seed") <PyConfig_Get>` instead.
63-
* :c:var:`Py_IsolatedFlag`:
63+
* :c:var:`!Py_IsolatedFlag`:
6464
Use :c:member:`PyConfig.isolated` or
6565
:c:func:`PyConfig_Get("isolated") <PyConfig_Get>` instead.
66-
* :c:var:`Py_LegacyWindowsFSEncodingFlag`:
66+
* :c:var:`!Py_LegacyWindowsFSEncodingFlag`:
6767
Use :c:member:`PyPreConfig.legacy_windows_fs_encoding` or
6868
:c:func:`PyConfig_Get("legacy_windows_fs_encoding") <PyConfig_Get>` instead.
69-
* :c:var:`Py_LegacyWindowsStdioFlag`:
69+
* :c:var:`!Py_LegacyWindowsStdioFlag`:
7070
Use :c:member:`PyConfig.legacy_windows_stdio` or
7171
:c:func:`PyConfig_Get("legacy_windows_stdio") <PyConfig_Get>` instead.
7272
* :c:var:`!Py_FileSystemDefaultEncoding`, :c:var:`!Py_HasFileSystemDefaultEncoding`:

0 commit comments

Comments
 (0)