Skip to content

Commit ae701e3

Browse files
committed
Merge branch 'origin/main' into pythongh-128384-warnings-contextvar
2 parents 5a1115b + f819900 commit ae701e3

33 files changed

+800
-203
lines changed

Doc/c-api/monitoring.rst

+12
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,15 @@ would typically correspond to a python function.
196196
.. c:function:: int PyMonitoring_ExitScope(void)
197197
198198
Exit the last scope that was entered with :c:func:`!PyMonitoring_EnterScope`.
199+
200+
201+
.. c:function:: int PY_MONITORING_IS_INSTRUMENTED_EVENT(uint8_t ev)
202+
203+
Return true if the event corresponding to the event ID *ev* is
204+
a :ref:`local event <monitoring-event-local>`.
205+
206+
.. versionadded:: 3.13
207+
208+
.. deprecated:: next
209+
210+
This function is :term:`soft deprecated`.

Doc/library/bdb.rst

+50-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ The :mod:`bdb` module also defines two classes:
118118

119119
Count of the number of times a :class:`Breakpoint` has been hit.
120120

121-
.. class:: Bdb(skip=None)
121+
.. class:: Bdb(skip=None, backend='settrace')
122122

123123
The :class:`Bdb` class acts as a generic Python debugger base class.
124124

@@ -132,9 +132,22 @@ The :mod:`bdb` module also defines two classes:
132132
frame is considered to originate in a certain module is determined
133133
by the ``__name__`` in the frame globals.
134134

135+
The *backend* argument specifies the backend to use for :class:`Bdb`. It
136+
can be either ``'settrace'`` or ``'monitoring'``. ``'settrace'`` uses
137+
:func:`sys.settrace` which has the best backward compatibility. The
138+
``'monitoring'`` backend uses the new :mod:`sys.monitoring` that was
139+
introduced in Python 3.12, which can be much more efficient because it
140+
can disable unused events. We are trying to keep the exact interfaces
141+
for both backends, but there are some differences. The debugger developers
142+
are encouraged to use the ``'monitoring'`` backend to achieve better
143+
performance.
144+
135145
.. versionchanged:: 3.1
136146
Added the *skip* parameter.
137147

148+
.. versionchanged:: 3.14
149+
Added the *backend* parameter.
150+
138151
The following methods of :class:`Bdb` normally don't need to be overridden.
139152

140153
.. method:: canonic(filename)
@@ -146,6 +159,20 @@ The :mod:`bdb` module also defines two classes:
146159
<os.path.abspath>`. A *filename* with angle brackets, such as ``"<stdin>"``
147160
generated in interactive mode, is returned unchanged.
148161

162+
.. method:: start_trace(self)
163+
164+
Start tracing. For ``'settrace'`` backend, this method is equivalent to
165+
``sys.settrace(self.trace_dispatch)``
166+
167+
.. versionadded:: 3.14
168+
169+
.. method:: stop_trace(self)
170+
171+
Stop tracing. For ``'settrace'`` backend, this method is equivalent to
172+
``sys.settrace(None)``
173+
174+
.. versionadded:: 3.14
175+
149176
.. method:: reset()
150177

151178
Set the :attr:`!botframe`, :attr:`!stopframe`, :attr:`!returnframe` and
@@ -364,6 +391,28 @@ The :mod:`bdb` module also defines two classes:
364391
Return all breakpoints that are set.
365392

366393

394+
Derived classes and clients can call the following methods to disable and
395+
restart events to achieve better performance. These methods only work
396+
when using the ``'monitoring'`` backend.
397+
398+
.. method:: disable_current_event()
399+
400+
Disable the current event until the next time :func:`restart_events` is
401+
called. This is helpful when the debugger is not interested in the current
402+
line.
403+
404+
.. versionadded:: 3.14
405+
406+
.. method:: restart_events()
407+
408+
Restart all the disabled events. This function is automatically called in
409+
``dispatch_*`` methods after ``user_*`` methods are called. If the
410+
``dispatch_*`` methods are not overridden, the disabled events will be
411+
restarted after each user interaction.
412+
413+
.. versionadded:: 3.14
414+
415+
367416
Derived classes and clients can call the following methods to get a data
368417
structure representing a stack trace.
369418

Doc/library/math.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,8 @@ Floating point manipulation functions
350350

351351
*abs_tol* is the absolute tolerance; it defaults to ``0.0`` and it must be
352352
nonnegative. When comparing ``x`` to ``0.0``, ``isclose(x, 0)`` is computed
353-
as ``abs(x) <= rel_tol * abs(x)``, which is ``False`` for any ``x`` and
354-
rel_tol less than ``1.0``. So add an appropriate positive abs_tol argument
353+
as ``abs(x) <= rel_tol * abs(x)``, which is ``False`` for any nonzero ``x`` and
354+
*rel_tol* less than ``1.0``. So add an appropriate positive *abs_tol* argument
355355
to the call.
356356

357357
The IEEE 754 special values of ``NaN``, ``inf``, and ``-inf`` will be

Doc/library/pdb.rst

+27-1
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,32 @@ slightly different way:
203203
Enter post-mortem debugging of the exception found in
204204
:data:`sys.last_exc`.
205205

206+
.. function:: set_default_backend(backend)
207+
208+
There are two supported backends for pdb: ``'settrace'`` and ``'monitoring'``.
209+
See :class:`bdb.Bdb` for details. The user can set the default backend to
210+
use if none is specified when instantiating :class:`Pdb`. If no backend is
211+
specified, the default is ``'settrace'``.
212+
213+
.. note::
214+
215+
:func:`breakpoint` and :func:`set_trace` will not be affected by this
216+
function. They always use ``'monitoring'`` backend.
217+
218+
.. versionadded:: 3.14
219+
220+
.. function:: get_default_backend()
221+
222+
Returns the default backend for pdb.
223+
224+
.. versionadded:: 3.14
206225

207226
The ``run*`` functions and :func:`set_trace` are aliases for instantiating the
208227
:class:`Pdb` class and calling the method of the same name. If you want to
209228
access further features, you have to do this yourself:
210229

211230
.. class:: Pdb(completekey='tab', stdin=None, stdout=None, skip=None, \
212-
nosigint=False, readrc=True, mode=None)
231+
nosigint=False, readrc=True, mode=None, backend=None)
213232

214233
:class:`Pdb` is the debugger class.
215234

@@ -235,6 +254,10 @@ access further features, you have to do this yourself:
235254
or ``None`` (for backwards compatible behaviour, as before the *mode*
236255
argument was added).
237256

257+
The *backend* argument specifies the backend to use for the debugger. If ``None``
258+
is passed, the default backend will be used. See :func:`set_default_backend`.
259+
Otherwise the supported backends are ``'settrace'`` and ``'monitoring'``.
260+
238261
Example call to enable tracing with *skip*::
239262

240263
import pdb; pdb.Pdb(skip=['django.*']).set_trace()
@@ -254,6 +277,9 @@ access further features, you have to do this yourself:
254277
.. versionadded:: 3.14
255278
Added the *mode* argument.
256279

280+
.. versionadded:: 3.14
281+
Added the *backend* argument.
282+
257283
.. versionchanged:: 3.14
258284
Inline breakpoints like :func:`breakpoint` or :func:`pdb.set_trace` will
259285
always stop the program at calling frame, ignoring the *skip* pattern (if any).

Doc/library/sqlite3.rst

+21-18
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,6 @@ Module functions
290290
:const:`PARSE_DECLTYPES` and :const:`PARSE_COLNAMES`
291291
to enable this.
292292
Column names takes precedence over declared types if both flags are set.
293-
Types cannot be detected for generated fields (for example ``max(data)``),
294-
even when the *detect_types* parameter is set; :class:`str` will be
295-
returned instead.
296293
By default (``0``), type detection is disabled.
297294

298295
:param isolation_level:
@@ -436,21 +433,6 @@ Module constants
436433
old style (pre-Python 3.12) transaction control behaviour.
437434
See :ref:`sqlite3-transaction-control-isolation-level` for more information.
438435

439-
.. data:: PARSE_COLNAMES
440-
441-
Pass this flag value to the *detect_types* parameter of
442-
:func:`connect` to look up a converter function by
443-
using the type name, parsed from the query column name,
444-
as the converter dictionary key.
445-
The type name must be wrapped in square brackets (``[]``).
446-
447-
.. code-block:: sql
448-
449-
SELECT p as "p [point]" FROM test; ! will look up converter "point"
450-
451-
This flag may be combined with :const:`PARSE_DECLTYPES` using the ``|``
452-
(bitwise or) operator.
453-
454436
.. data:: PARSE_DECLTYPES
455437

456438
Pass this flag value to the *detect_types* parameter of
@@ -472,6 +454,27 @@ Module constants
472454
This flag may be combined with :const:`PARSE_COLNAMES` using the ``|``
473455
(bitwise or) operator.
474456

457+
.. note::
458+
459+
Generated fields (for example ``MAX(p)``) are returned as :class:`str`.
460+
Use :const:`!PARSE_COLNAMES` to enforce types for such queries.
461+
462+
.. data:: PARSE_COLNAMES
463+
464+
Pass this flag value to the *detect_types* parameter of
465+
:func:`connect` to look up a converter function by
466+
using the type name, parsed from the query column name,
467+
as the converter dictionary key.
468+
The query column name must be wrapped in double quotes (``"``)
469+
and the type name must be wrapped in square brackets (``[]``).
470+
471+
.. code-block:: sql
472+
473+
SELECT MAX(p) as "p [point]" FROM test; ! will look up converter "point"
474+
475+
This flag may be combined with :const:`PARSE_DECLTYPES` using the ``|``
476+
(bitwise or) operator.
477+
475478
.. data:: SQLITE_OK
476479
SQLITE_DENY
477480
SQLITE_IGNORE

Doc/library/sys.monitoring.rst

+2
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ events, use the expression ``PY_RETURN | PY_START``.
173173

174174
Events are divided into three groups:
175175

176+
.. _monitoring-event-local:
177+
176178
Local events
177179
''''''''''''
178180

Doc/library/urllib.request.rst

+13-5
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,10 @@ It is also possible to achieve the same result without using the
12491249

12501250
>>> import urllib.request
12511251
>>> f = urllib.request.urlopen('http://www.python.org/')
1252-
>>> print(f.read(100).decode('utf-8'))
1252+
>>> try:
1253+
... print(f.read(100).decode('utf-8'))
1254+
... finally:
1255+
... f.close()
12531256
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
12541257
"http://www.w3.org/TR/xhtml1/DTD/xhtm
12551258

@@ -1294,7 +1297,8 @@ Use of Basic HTTP Authentication::
12941297
opener = urllib.request.build_opener(auth_handler)
12951298
# ...and install it globally so it can be used with urlopen.
12961299
urllib.request.install_opener(opener)
1297-
urllib.request.urlopen('http://www.example.com/login.html')
1300+
with urllib.request.urlopen('http://www.example.com/login.html') as f:
1301+
print(f.read().decode('utf-8'))
12981302

12991303
:func:`build_opener` provides many handlers by default, including a
13001304
:class:`ProxyHandler`. By default, :class:`ProxyHandler` uses the environment
@@ -1312,7 +1316,8 @@ programmatically supplied proxy URLs, and adds proxy authorization support with
13121316

13131317
opener = urllib.request.build_opener(proxy_handler, proxy_auth_handler)
13141318
# This time, rather than install the OpenerDirector, we use it directly:
1315-
opener.open('http://www.example.com/login.html')
1319+
with opener.open('http://www.example.com/login.html') as f:
1320+
print(f.read().decode('utf-8'))
13161321

13171322
Adding HTTP headers:
13181323

@@ -1323,15 +1328,18 @@ Use the *headers* argument to the :class:`Request` constructor, or::
13231328
req.add_header('Referer', 'http://www.python.org/')
13241329
# Customize the default User-Agent header value:
13251330
req.add_header('User-Agent', 'urllib-example/0.1 (Contact: . . .)')
1326-
r = urllib.request.urlopen(req)
1331+
with urllib.request.urlopen(req) as f:
1332+
print(f.read().decode('utf-8'))
1333+
13271334

13281335
:class:`OpenerDirector` automatically adds a :mailheader:`User-Agent` header to
13291336
every :class:`Request`. To change this::
13301337

13311338
import urllib.request
13321339
opener = urllib.request.build_opener()
13331340
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
1334-
opener.open('http://www.example.com/')
1341+
with opener.open('http://www.example.com/') as f:
1342+
print(f.read().decode('utf-8'))
13351343

13361344
Also, remember that a few standard headers (:mailheader:`Content-Length`,
13371345
:mailheader:`Content-Type` and :mailheader:`Host`)

Doc/whatsnew/3.14.rst

+12
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,11 @@ ast
423423
that the root node type is appropriate.
424424
(Contributed by Irit Katriel in :gh:`130139`.)
425425

426+
bdb
427+
---
428+
429+
* The :mod:`bdb` module now supports the :mod:`sys.monitoring` backend.
430+
(Contributed by Tian Gao in :gh:`124533`.)
426431

427432
calendar
428433
--------
@@ -843,6 +848,13 @@ pdb
843848
* ``$_asynctask`` is added to access the current asyncio task if applicable.
844849
(Contributed by Tian Gao in :gh:`124367`.)
845850

851+
* :mod:`pdb` now supports two backends: :func:`sys.settrace` and
852+
:mod:`sys.monitoring`. Using :mod:`pdb` CLI or :func:`breakpoint` will
853+
always use the :mod:`sys.monitoring` backend. Explicitly instantiating
854+
:class:`pdb.Pdb` and its derived classes will use the :func:`sys.settrace`
855+
backend by default, which is configurable.
856+
(Contributed by Tian Gao in :gh:`124533`.)
857+
846858

847859
pickle
848860
------

InternalDocs/jit.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ It then calls the function `_PyOptimizer_Optimize()` in
2222
[`Python/optimizer.c`](../Python/optimizer.c), passing it the current
2323
[frame](frames.md) and instruction pointer. `_PyOptimizer_Optimize()`
2424
constructs an object of type
25-
[`_PyExecutorObject`](Include/internal/pycore_optimizer.h) which implements
25+
[`_PyExecutorObject`](../Include/internal/pycore_optimizer.h) which implements
2626
an optimized version of the instruction trace beginning at this jump.
2727

2828
The optimizer determines where the trace ends, and the executor is set up

0 commit comments

Comments
 (0)