Skip to content

Commit 4ed1083

Browse files
committed
Merge branch 'main' into pythongh-114271-remove-tstate_lock
2 parents 40e4b36 + d9f4cbe commit 4ed1083

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+2213
-2294
lines changed

.github/CODEOWNERS

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Python/flowgraph.c @markshannon @iritkatriel
3737
Python/ast_opt.c @isidentical
3838
Python/bytecodes.c @markshannon @gvanrossum
3939
Python/optimizer*.c @markshannon @gvanrossum
40+
Python/optimizer_analysis.c @Fidget-Spinner
41+
Python/tier2_redundancy_eliminator_bytecodes.c @Fidget-Spinner
4042
Lib/test/test_patma.py @brandtbucher
4143
Lib/test/test_type_*.py @JelleZijlstra
4244
Lib/test/test_capi/test_misc.py @markshannon @gvanrossum

Doc/conf.py

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666

6767
rst_epilog = f"""
6868
.. |python_version_literal| replace:: ``Python {version}``
69+
.. |python_x_dot_y_literal| replace:: ``python{version}``
70+
.. |usr_local_bin_python_x_dot_y_literal| replace:: ``/usr/local/bin/python{version}``
6971
"""
7072

7173
# There are two options for replacing |today|: either, you set today to some

Doc/library/datetime.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,7 @@ Other constructor:
18111811
be truncated).
18121812
4. Fractional hours and minutes are not supported.
18131813

1814-
Examples::
1814+
Examples:
18151815

18161816
.. doctest::
18171817

Doc/library/dbm.rst

+62-23
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@
88

99
--------------
1010

11-
:mod:`dbm` is a generic interface to variants of the DBM database ---
12-
:mod:`dbm.gnu` or :mod:`dbm.ndbm`. If none of these modules is installed, the
11+
:mod:`dbm` is a generic interface to variants of the DBM database:
12+
13+
* :mod:`dbm.sqlite3`
14+
* :mod:`dbm.gnu`
15+
* :mod:`dbm.ndbm`
16+
17+
If none of these modules are installed, the
1318
slow-but-simple implementation in module :mod:`dbm.dumb` will be used. There
1419
is a `third party interface <https://www.jcea.es/programacion/pybsddb.htm>`_ to
1520
the Oracle Berkeley DB.
@@ -25,8 +30,8 @@ the Oracle Berkeley DB.
2530
.. function:: whichdb(filename)
2631

2732
This function attempts to guess which of the several simple database modules
28-
available --- :mod:`dbm.gnu`, :mod:`dbm.ndbm` or :mod:`dbm.dumb` --- should
29-
be used to open a given file.
33+
available --- :mod:`dbm.sqlite3`, :mod:`dbm.gnu`, :mod:`dbm.ndbm`,
34+
or :mod:`dbm.dumb` --- should be used to open a given file.
3035

3136
Return one of the following values:
3237

@@ -56,10 +61,6 @@ the Oracle Berkeley DB.
5661
The Unix file access mode of the file (default: octal ``0o666``),
5762
used only when the database has to be created.
5863

59-
.. |incompat_note| replace::
60-
The file formats created by :mod:`dbm.gnu` and :mod:`dbm.ndbm` are incompatible
61-
and can not be used interchangeably.
62-
6364
.. function:: open(file, flag='r', mode=0o666)
6465

6566
Open a database and return the corresponding database object.
@@ -144,6 +145,46 @@ then prints out the contents of the database::
144145

145146
The individual submodules are described in the following sections.
146147

148+
:mod:`dbm.sqlite3` --- SQLite backend for dbm
149+
---------------------------------------------
150+
151+
.. module:: dbm.sqlite3
152+
:platform: All
153+
:synopsis: SQLite backend for dbm
154+
155+
.. versionadded:: 3.13
156+
157+
**Source code:** :source:`Lib/dbm/sqlite3.py`
158+
159+
--------------
160+
161+
This module uses the standard library :mod:`sqlite3` module to provide an
162+
SQLite backend for the :mod:`dbm` module.
163+
The files created by :mod:`dbm.sqlite3` can thus be opened by :mod:`sqlite3`,
164+
or any other SQLite browser, including the SQLite CLI.
165+
166+
.. function:: open(filename, /, flag="r", mode=0o666)
167+
168+
Open an SQLite database.
169+
The returned object behaves like a :term:`mapping`,
170+
implements a :meth:`!close` method,
171+
and supports a "closing" context manager via the :keyword:`with` keyword.
172+
173+
:param filename:
174+
The path to the database to be opened.
175+
:type filename: :term:`path-like object`
176+
177+
:param str flag:
178+
179+
* ``'r'`` (default): |flag_r|
180+
* ``'w'``: |flag_w|
181+
* ``'c'``: |flag_c|
182+
* ``'n'``: |flag_n|
183+
184+
:param mode:
185+
The Unix file access mode of the file (default: octal ``0o666``),
186+
used only when the database has to be created.
187+
147188

148189
:mod:`dbm.gnu` --- GNU database manager
149190
---------------------------------------
@@ -160,11 +201,10 @@ The :mod:`dbm.gnu` module provides an interface to the :abbr:`GDBM (GNU dbm)`
160201
library, similar to the :mod:`dbm.ndbm` module, but with additional
161202
functionality like crash tolerance.
162203

163-
:class:`!gdbm` objects behave similar to :term:`mappings <mapping>`,
164-
except that keys and values are always converted to :class:`bytes` before storing,
165-
and the :meth:`!items` and :meth:`!values` methods are not supported.
204+
.. note::
166205

167-
.. note:: |incompat_note|
206+
The file formats created by :mod:`dbm.gnu` and :mod:`dbm.ndbm` are incompatible
207+
and can not be used interchangeably.
168208

169209
.. exception:: error
170210

@@ -211,8 +251,9 @@ and the :meth:`!items` and :meth:`!values` methods are not supported.
211251

212252
A string of characters the *flag* parameter of :meth:`~dbm.gnu.open` supports.
213253

214-
In addition to the dictionary-like methods, :class:`gdbm` objects have the
215-
following methods and attributes:
254+
:class:`!gdbm` objects behave similar to :term:`mappings <mapping>`,
255+
but :meth:`!items` and :meth:`!values` methods are not supported.
256+
The following methods are also provided:
216257

217258
.. method:: gdbm.firstkey()
218259

@@ -269,14 +310,13 @@ and the :meth:`!items` and :meth:`!values` methods are not supported.
269310

270311
The :mod:`dbm.ndbm` module provides an interface to the
271312
:abbr:`NDBM (New Database Manager)` library.
272-
:class:`!ndbm` objects behave similar to :term:`mappings <mapping>`,
273-
except that keys and values are always stored as :class:`bytes`,
274-
and the :meth:`!items` and :meth:`!values` methods are not supported.
275-
276313
This module can be used with the "classic" NDBM interface or the
277314
:abbr:`GDBM (GNU dbm)` compatibility interface.
278315

279-
.. note:: |incompat_note|
316+
.. note::
317+
318+
The file formats created by :mod:`dbm.gnu` and :mod:`dbm.ndbm` are incompatible
319+
and can not be used interchangeably.
280320

281321
.. warning::
282322

@@ -314,8 +354,9 @@ This module can be used with the "classic" NDBM interface or the
314354
:param int mode:
315355
|mode_param_doc|
316356

317-
In addition to the dictionary-like methods, :class:`!ndbm` objects
318-
provide the following method:
357+
:class:`!ndbm` objects behave similar to :term:`mappings <mapping>`,
358+
but :meth:`!items` and :meth:`!values` methods are not supported.
359+
The following methods are also provided:
319360

320361
.. versionchanged:: 3.11
321362
Accepts :term:`path-like object` for filename.
@@ -354,8 +395,6 @@ The :mod:`dbm.dumb` module provides a persistent :class:`dict`-like
354395
interface which is written entirely in Python.
355396
Unlike other :mod:`dbm` backends, such as :mod:`dbm.gnu`, no
356397
external library is required.
357-
As with other :mod:`dbm` backends,
358-
the keys and values are always stored as :class:`bytes`.
359398

360399
The :mod:`!dbm.dumb` module defines the following:
361400

Doc/library/ftplib.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ FTP objects
104104
:param timeout:
105105
A timeout in seconds for blocking operations like :meth:`connect`
106106
(default: the global default timeout setting).
107-
:type timeout: int | None
107+
:type timeout: float | None
108108

109109
:param source_address:
110110
|param_doc_source_address|
@@ -178,7 +178,7 @@ FTP objects
178178
:param timeout:
179179
A timeout in seconds for the connection attempt
180180
(default: the global default timeout setting).
181-
:type timeout: int | None
181+
:type timeout: float | None
182182

183183
:param source_address:
184184
|param_doc_source_address|
@@ -483,7 +483,7 @@ FTP_TLS objects
483483
:param timeout:
484484
A timeout in seconds for blocking operations like :meth:`~FTP.connect`
485485
(default: the global default timeout setting).
486-
:type timeout: int | None
486+
:type timeout: float | None
487487

488488
:param source_address:
489489
|param_doc_source_address|

Doc/tutorial/interpreter.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Using the Python Interpreter
1010
Invoking the Interpreter
1111
========================
1212

13-
The Python interpreter is usually installed as :file:`/usr/local/bin/python3.13`
13+
The Python interpreter is usually installed as |usr_local_bin_python_x_dot_y_literal|
1414
on those machines where it is available; putting :file:`/usr/local/bin` in your
1515
Unix shell's search path makes it possible to start it by typing the command:
1616

@@ -24,7 +24,7 @@ Python guru or system administrator. (E.g., :file:`/usr/local/python` is a
2424
popular alternative location.)
2525

2626
On Windows machines where you have installed Python from the :ref:`Microsoft Store
27-
<windows-store>`, the :file:`python3.13` command will be available. If you have
27+
<windows-store>`, the |python_x_dot_y_literal| command will be available. If you have
2828
the :ref:`py.exe launcher <launcher>` installed, you can use the :file:`py`
2929
command. See :ref:`setting-envvars` for other ways to launch Python.
3030

Doc/tutorial/stdlib.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ operating system::
1515

1616
>>> import os
1717
>>> os.getcwd() # Return the current working directory
18-
'C:\\Python312'
18+
'C:\\Python313'
1919
>>> os.chdir('/server/accesslogs') # Change current working directory
2020
>>> os.system('mkdir today') # Run the command mkdir in the system shell
2121
0

Doc/tutorial/stdlib2.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ applications include caching objects that are expensive to create::
279279
Traceback (most recent call last):
280280
File "<stdin>", line 1, in <module>
281281
d['primary'] # entry was automatically removed
282-
File "C:/python312/lib/weakref.py", line 46, in __getitem__
282+
File "C:/python313/lib/weakref.py", line 46, in __getitem__
283283
o = self.data[key]()
284284
KeyError: 'primary'
285285

Doc/whatsnew/3.13.rst

+10
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,16 @@ dis
231231
the ``show_offsets`` parameter.
232232
(Contributed by Irit Katriel in :gh:`112137`.)
233233

234+
dbm
235+
---
236+
237+
* Add :meth:`dbm.gnu.gdbm.clear` and :meth:`dbm.ndbm.ndbm.clear` methods that remove all items
238+
from the database.
239+
(Contributed by Donghee Na in :gh:`107122`.)
240+
241+
* Add new :mod:`dbm.sqlite3` backend, and make it the default :mod:`!dbm` backend.
242+
(Contributed by Raymond Hettinger and Erlend E. Aasland in :gh:`100414`.)
243+
234244
doctest
235245
-------
236246

Include/internal/pycore_code.h

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11+
12+
// We hide some of the newer PyCodeObject fields behind macros.
13+
// This helps with backporting certain changes to 3.12.
14+
#define _PyCode_HAS_EXECUTORS(CODE) \
15+
(CODE->co_executors != NULL)
16+
#define _PyCode_HAS_INSTRUMENTATION(CODE) \
17+
(CODE->_co_instrumentation_version > 0)
18+
19+
1120
#define CODE_MAX_WATCHERS 8
1221

1322
/* PEP 659

Include/internal/pycore_crossinterp.h

+26
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ struct _xid {
8787
PyAPI_FUNC(_PyCrossInterpreterData *) _PyCrossInterpreterData_New(void);
8888
PyAPI_FUNC(void) _PyCrossInterpreterData_Free(_PyCrossInterpreterData *data);
8989

90+
#define _PyCrossInterpreterData_DATA(DATA) ((DATA)->data)
91+
#define _PyCrossInterpreterData_OBJ(DATA) ((DATA)->obj)
92+
#define _PyCrossInterpreterData_INTERPID(DATA) ((DATA)->interpid)
93+
// Users should not need getters for "new_object" or "free".
94+
9095

9196
/* defining cross-interpreter data */
9297

@@ -101,6 +106,25 @@ PyAPI_FUNC(int) _PyCrossInterpreterData_InitWithSize(
101106
PyAPI_FUNC(void) _PyCrossInterpreterData_Clear(
102107
PyInterpreterState *, _PyCrossInterpreterData *);
103108

109+
// Normally the Init* functions are sufficient. The only time
110+
// additional initialization might be needed is to set the "free" func,
111+
// though that should be infrequent.
112+
#define _PyCrossInterpreterData_SET_FREE(DATA, FUNC) \
113+
do { \
114+
(DATA)->free = (FUNC); \
115+
} while (0)
116+
// Additionally, some shareable types are essentially light wrappers
117+
// around other shareable types. The crossinterpdatafunc of the wrapper
118+
// can often be implemented by calling the wrapped object's
119+
// crossinterpdatafunc and then changing the "new_object" function.
120+
// We have _PyCrossInterpreterData_SET_NEW_OBJECT() here for that,
121+
// but might be better to have a function like
122+
// _PyCrossInterpreterData_AdaptToWrapper() instead.
123+
#define _PyCrossInterpreterData_SET_NEW_OBJECT(DATA, FUNC) \
124+
do { \
125+
(DATA)->new_object = (FUNC); \
126+
} while (0)
127+
104128

105129
/* using cross-interpreter data */
106130

@@ -170,6 +194,8 @@ extern void _PyXI_Fini(PyInterpreterState *interp);
170194
extern PyStatus _PyXI_InitTypes(PyInterpreterState *interp);
171195
extern void _PyXI_FiniTypes(PyInterpreterState *interp);
172196

197+
#define _PyInterpreterState_GetXIState(interp) (&(interp)->xi)
198+
173199

174200
/***************************/
175201
/* short-term data sharing */

Include/internal/pycore_dict.h

-6
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,6 @@ typedef struct {
6767
extern PyObject* _PyDictView_New(PyObject *, PyTypeObject *);
6868
extern PyObject* _PyDictView_Intersect(PyObject* self, PyObject *other);
6969

70-
71-
/* runtime lifecycle */
72-
73-
extern void _PyDict_Fini(PyInterpreterState *state);
74-
75-
7670
/* other API */
7771

7872
typedef struct {

0 commit comments

Comments
 (0)