Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into cpython-eval-breaker
Browse files Browse the repository at this point in the history
  • Loading branch information
swtaarrs committed Feb 15, 2024
2 parents 0e1055f + 18343c0 commit 2139ed4
Show file tree
Hide file tree
Showing 86 changed files with 1,474 additions and 1,588 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Python/flowgraph.c @markshannon @iritkatriel
Python/ast_opt.c @isidentical
Python/bytecodes.c @markshannon @gvanrossum
Python/optimizer*.c @markshannon @gvanrossum
Python/optimizer_analysis.c @Fidget-Spinner
Python/tier2_redundancy_eliminator_bytecodes.c @Fidget-Spinner
Lib/test/test_patma.py @brandtbucher
Lib/test/test_type_*.py @JelleZijlstra
Lib/test/test_capi/test_misc.py @markshannon @gvanrossum
Expand Down
2 changes: 2 additions & 0 deletions Doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@

rst_epilog = f"""
.. |python_version_literal| replace:: ``Python {version}``
.. |python_x_dot_y_literal| replace:: ``python{version}``
.. |usr_local_bin_python_x_dot_y_literal| replace:: ``/usr/local/bin/python{version}``
"""

# There are two options for replacing |today|: either, you set today to some
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/datetime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1811,7 +1811,7 @@ Other constructor:
be truncated).
4. Fractional hours and minutes are not supported.

Examples::
Examples:

.. doctest::

Expand Down
85 changes: 62 additions & 23 deletions Doc/library/dbm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@

--------------

:mod:`dbm` is a generic interface to variants of the DBM database ---
:mod:`dbm.gnu` or :mod:`dbm.ndbm`. If none of these modules is installed, the
:mod:`dbm` is a generic interface to variants of the DBM database:

* :mod:`dbm.sqlite3`
* :mod:`dbm.gnu`
* :mod:`dbm.ndbm`

If none of these modules are installed, the
slow-but-simple implementation in module :mod:`dbm.dumb` will be used. There
is a `third party interface <https://www.jcea.es/programacion/pybsddb.htm>`_ to
the Oracle Berkeley DB.
Expand All @@ -25,8 +30,8 @@ the Oracle Berkeley DB.
.. function:: whichdb(filename)

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

Return one of the following values:

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

.. |incompat_note| replace::
The file formats created by :mod:`dbm.gnu` and :mod:`dbm.ndbm` are incompatible
and can not be used interchangeably.

.. function:: open(file, flag='r', mode=0o666)

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

The individual submodules are described in the following sections.

:mod:`dbm.sqlite3` --- SQLite backend for dbm
---------------------------------------------

.. module:: dbm.sqlite3
:platform: All
:synopsis: SQLite backend for dbm

.. versionadded:: 3.13

**Source code:** :source:`Lib/dbm/sqlite3.py`

--------------

This module uses the standard library :mod:`sqlite3` module to provide an
SQLite backend for the :mod:`dbm` module.
The files created by :mod:`dbm.sqlite3` can thus be opened by :mod:`sqlite3`,
or any other SQLite browser, including the SQLite CLI.

.. function:: open(filename, /, flag="r", mode=0o666)

Open an SQLite database.
The returned object behaves like a :term:`mapping`,
implements a :meth:`!close` method,
and supports a "closing" context manager via the :keyword:`with` keyword.

:param filename:
The path to the database to be opened.
:type filename: :term:`path-like object`

:param str flag:

* ``'r'`` (default): |flag_r|
* ``'w'``: |flag_w|
* ``'c'``: |flag_c|
* ``'n'``: |flag_n|

:param mode:
The Unix file access mode of the file (default: octal ``0o666``),
used only when the database has to be created.


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

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

.. note:: |incompat_note|
The file formats created by :mod:`dbm.gnu` and :mod:`dbm.ndbm` are incompatible
and can not be used interchangeably.

.. exception:: error

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

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

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

.. method:: gdbm.firstkey()

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

The :mod:`dbm.ndbm` module provides an interface to the
:abbr:`NDBM (New Database Manager)` library.
:class:`!ndbm` objects behave similar to :term:`mappings <mapping>`,
except that keys and values are always stored as :class:`bytes`,
and the :meth:`!items` and :meth:`!values` methods are not supported.

This module can be used with the "classic" NDBM interface or the
:abbr:`GDBM (GNU dbm)` compatibility interface.

.. note:: |incompat_note|
.. note::

The file formats created by :mod:`dbm.gnu` and :mod:`dbm.ndbm` are incompatible
and can not be used interchangeably.

.. warning::

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

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

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

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

Expand Down
18 changes: 18 additions & 0 deletions Doc/library/exceptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,24 @@ The following exceptions are the exceptions that are usually raised.
handling in C, most floating point operations are not checked.


.. exception:: PythonFinalizationError

This exception is derived from :exc:`RuntimeError`. It is raised when
an operation is blocked during interpreter shutdown also known as
:term:`Python finalization <interpreter shutdown>`.

Examples of operations which can be blocked with a
:exc:`PythonFinalizationError` during the Python finalization:

* Creating a new Python thread.
* :func:`os.fork`.

See also the :func:`sys.is_finalizing` function.

.. versionadded:: 3.13
Previously, a plain :exc:`RuntimeError` was raised.


.. exception:: RecursionError

This exception is derived from :exc:`RuntimeError`. It is raised when the
Expand Down
6 changes: 3 additions & 3 deletions Doc/library/ftplib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ FTP objects
:param timeout:
A timeout in seconds for blocking operations like :meth:`connect`
(default: the global default timeout setting).
:type timeout: int | None
:type timeout: float | None

:param source_address:
|param_doc_source_address|
Expand Down Expand Up @@ -178,7 +178,7 @@ FTP objects
:param timeout:
A timeout in seconds for the connection attempt
(default: the global default timeout setting).
:type timeout: int | None
:type timeout: float | None

:param source_address:
|param_doc_source_address|
Expand Down Expand Up @@ -483,7 +483,7 @@ FTP_TLS objects
:param timeout:
A timeout in seconds for blocking operations like :meth:`~FTP.connect`
(default: the global default timeout setting).
:type timeout: int | None
:type timeout: float | None

:param source_address:
|param_doc_source_address|
Expand Down
2 changes: 2 additions & 0 deletions Doc/library/sys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,8 @@ always available.
Return :const:`True` if the main Python interpreter is
:term:`shutting down <interpreter shutdown>`. Return :const:`False` otherwise.

See also the :exc:`PythonFinalizationError` exception.

.. versionadded:: 3.5

.. data:: last_exc
Expand Down
4 changes: 2 additions & 2 deletions Doc/tutorial/interpreter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Using the Python Interpreter
Invoking the Interpreter
========================

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion Doc/tutorial/stdlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ operating system::

>>> import os
>>> os.getcwd() # Return the current working directory
'C:\\Python312'
'C:\\Python313'
>>> os.chdir('/server/accesslogs') # Change current working directory
>>> os.system('mkdir today') # Run the command mkdir in the system shell
0
Expand Down
2 changes: 1 addition & 1 deletion Doc/tutorial/stdlib2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ applications include caching objects that are expensive to create::
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
d['primary'] # entry was automatically removed
File "C:/python312/lib/weakref.py", line 46, in __getitem__
File "C:/python313/lib/weakref.py", line 46, in __getitem__
o = self.data[key]()
KeyError: 'primary'

Expand Down
25 changes: 25 additions & 0 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@ Other Language Changes
(Contributed by Levi Sabah, Zackery Spytz and Hugo van Kemenade in
:gh:`73965`.)

* Add :exc:`PythonFinalizationError` exception. This exception derived from
:exc:`RuntimeError` is raised when an operation is blocked during
the :term:`Python finalization <interpreter shutdown>`.

The following functions now raise PythonFinalizationError, instead of
:exc:`RuntimeError`:

* :func:`_thread.start_new_thread`.
* :class:`subprocess.Popen`.
* :func:`os.fork`.
* :func:`os.forkpty`.

(Contributed by Victor Stinner in :gh:`114570`.)


New Modules
===========

Expand Down Expand Up @@ -231,6 +246,16 @@ dis
the ``show_offsets`` parameter.
(Contributed by Irit Katriel in :gh:`112137`.)

dbm
---

* Add :meth:`dbm.gnu.gdbm.clear` and :meth:`dbm.ndbm.ndbm.clear` methods that remove all items
from the database.
(Contributed by Donghee Na in :gh:`107122`.)

* Add new :mod:`dbm.sqlite3` backend, and make it the default :mod:`!dbm` backend.
(Contributed by Raymond Hettinger and Erlend E. Aasland in :gh:`100414`.)

doctest
-------

Expand Down
2 changes: 2 additions & 0 deletions Include/cpython/pyerrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,6 @@ PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalErrorFunc(

PyAPI_FUNC(void) PyErr_FormatUnraisable(const char *, ...);

PyAPI_DATA(PyObject *) PyExc_PythonFinalizationError;

#define Py_FatalError(message) _Py_FatalErrorFunc(__func__, (message))
8 changes: 7 additions & 1 deletion Include/internal/mimalloc/mimalloc/prim.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,13 @@ extern bool _mi_process_is_initialized; // has mi_process_init been

static inline mi_threadid_t _mi_prim_thread_id(void) mi_attr_noexcept;

#if defined(_WIN32)
#ifdef MI_PRIM_THREAD_ID

static inline mi_threadid_t _mi_prim_thread_id(void) mi_attr_noexcept {
return MI_PRIM_THREAD_ID();
}

#elif defined(_WIN32)

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
Expand Down
6 changes: 0 additions & 6 deletions Include/internal/pycore_dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ typedef struct {
extern PyObject* _PyDictView_New(PyObject *, PyTypeObject *);
extern PyObject* _PyDictView_Intersect(PyObject* self, PyObject *other);


/* runtime lifecycle */

extern void _PyDict_Fini(PyInterpreterState *state);


/* other API */

typedef struct {
Expand Down
Loading

0 comments on commit 2139ed4

Please sign in to comment.