Skip to content

Commit 90cbdaf

Browse files
authored
Merge branch 'main' into gh-11599-docs
2 parents 1b0d395 + 49234c0 commit 90cbdaf

File tree

265 files changed

+7859
-3961
lines changed

Some content is hidden

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

265 files changed

+7859
-3961
lines changed

Doc/glossary.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,10 @@ Glossary
800800
thread removes *key* from *mapping* after the test, but before the lookup.
801801
This issue can be solved with locks or by using the EAFP approach.
802802

803+
lexical analyzer
804+
805+
Formal name for the *tokenizer*; see :term:`token`.
806+
803807
list
804808
A built-in Python :term:`sequence`. Despite its name it is more akin
805809
to an array in other languages than to a linked list since access to
@@ -1291,6 +1295,17 @@ Glossary
12911295
See also :term:`binary file` for a file object able to read and write
12921296
:term:`bytes-like objects <bytes-like object>`.
12931297

1298+
token
1299+
1300+
A small unit of source code, generated by the
1301+
:ref:`lexical analyzer <lexical>` (also called the *tokenizer*).
1302+
Names, numbers, strings, operators,
1303+
newlines and similar are represented by tokens.
1304+
1305+
The :mod:`tokenize` module exposes Python's lexical analyzer.
1306+
The :mod:`token` module contains information on the various types
1307+
of tokens.
1308+
12941309
triple-quoted string
12951310
A string which is bound by three instances of either a quotation mark
12961311
(") or an apostrophe ('). While they don't provide any functionality

Doc/library/bdb.rst

Lines changed: 50 additions & 1 deletion
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/cmdline.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The following modules have a command-line interface.
1212
* :ref:`compileall <compileall-cli>`
1313
* :mod:`cProfile`: see :ref:`profile <profile-cli>`
1414
* :ref:`dis <dis-cli>`
15-
* :mod:`doctest`
15+
* :ref:`doctest <doctest-cli>`
1616
* :mod:`!encodings.rot_13`
1717
* :mod:`ensurepip`
1818
* :mod:`filecmp`

Doc/library/dis.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ details of bytecode instructions as :class:`Instruction` instances:
535535
:class:`dis.Positions` object holding the
536536
start and end locations that are covered by this instruction.
537537

538-
.. data::cache_info
538+
.. data:: cache_info
539539

540540
Information about the cache entries of this instruction, as
541541
triplets of the form ``(name, size, data)``, where the ``name``

Doc/library/doctest.rst

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,8 @@ prohibit it by passing ``verbose=False``. In either of those cases,
177177
``sys.argv`` is not examined by :func:`testmod` (so passing ``-v`` or not
178178
has no effect).
179179

180-
There is also a command line shortcut for running :func:`testmod`. You can
181-
instruct the Python interpreter to run the doctest module directly from the
182-
standard library and pass the module name(s) on the command line::
183-
184-
python -m doctest -v example.py
185-
186-
This will import :file:`example.py` as a standalone module and run
187-
:func:`testmod` on it. Note that this may not work correctly if the file is
188-
part of a package and imports other submodules from that package.
180+
There is also a command line shortcut for running :func:`testmod`, see section
181+
:ref:`doctest-cli`.
189182

190183
For more information on :func:`testmod`, see section :ref:`doctest-basic-api`.
191184

@@ -248,16 +241,53 @@ Like :func:`testmod`, :func:`testfile`'s verbosity can be set with the
248241
``-v`` command-line switch or with the optional keyword argument
249242
*verbose*.
250243

251-
There is also a command line shortcut for running :func:`testfile`. You can
252-
instruct the Python interpreter to run the doctest module directly from the
253-
standard library and pass the file name(s) on the command line::
244+
There is also a command line shortcut for running :func:`testfile`, see section
245+
:ref:`doctest-cli`.
254246

255-
python -m doctest -v example.txt
247+
For more information on :func:`testfile`, see section :ref:`doctest-basic-api`.
256248

257-
Because the file name does not end with :file:`.py`, :mod:`doctest` infers that
258-
it must be run with :func:`testfile`, not :func:`testmod`.
259249

260-
For more information on :func:`testfile`, see section :ref:`doctest-basic-api`.
250+
.. _doctest-cli:
251+
252+
Command-line Usage
253+
------------------
254+
255+
The :mod:`doctest` module can be invoked as a script from the command line:
256+
257+
.. code-block:: bash
258+
259+
python -m doctest [-v] [-o OPTION] [-f] file [file ...]
260+
261+
.. program:: doctest
262+
263+
.. option:: -v, --verbose
264+
265+
Detailed report of all examples tried is printed to standard output,
266+
along with assorted summaries at the end::
267+
268+
python -m doctest -v example.py
269+
270+
This will import :file:`example.py` as a standalone module and run
271+
:func:`testmod` on it. Note that this may not work correctly if the
272+
file is part of a package and imports other submodules from that package.
273+
274+
If the file name does not end with :file:`.py`, :mod:`!doctest` infers
275+
that it must be run with :func:`testfile` instead::
276+
277+
python -m doctest -v example.txt
278+
279+
.. option:: -o, --option <option>
280+
281+
Option flags control various aspects of doctest's behavior, see section
282+
:ref:`doctest-options`.
283+
284+
.. versionadded:: 3.4
285+
286+
.. option:: -f, --fail-fast
287+
288+
This is shorthand for ``-o FAIL_FAST``.
289+
290+
.. versionadded:: 3.4
261291

262292

263293
.. _doctest-how-it-works:
@@ -540,9 +570,6 @@ Symbolic names for the flags are supplied as module constants, which can be
540570
The names can also be used in :ref:`doctest directives <doctest-directives>`,
541571
and may be passed to the doctest command line interface via the ``-o`` option.
542572

543-
.. versionadded:: 3.4
544-
The ``-o`` command line option.
545-
546573
The first group of options define test semantics, controlling aspects of how
547574
doctest decides whether actual output matches an example's expected output:
548575

@@ -682,11 +709,6 @@ The second group of options controls how test failures are reported:
682709
1. This flag may be useful during debugging, since examples after the first
683710
failure won't even produce debugging output.
684711

685-
The doctest command line accepts the option ``-f`` as a shorthand for ``-o
686-
FAIL_FAST``.
687-
688-
.. versionadded:: 3.4
689-
690712

691713
.. data:: REPORTING_FLAGS
692714

Doc/library/http.server.rst

Lines changed: 68 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -418,49 +418,6 @@ the current directory::
418418
such as using different index file names by overriding the class attribute
419419
:attr:`index_pages`.
420420

421-
.. _http-server-cli:
422-
423-
:mod:`http.server` can also be invoked directly using the :option:`-m`
424-
switch of the interpreter. Similar to
425-
the previous example, this serves files relative to the current directory::
426-
427-
python -m http.server
428-
429-
The server listens to port 8000 by default. The default can be overridden
430-
by passing the desired port number as an argument::
431-
432-
python -m http.server 9000
433-
434-
By default, the server binds itself to all interfaces. The option ``-b/--bind``
435-
specifies a specific address to which it should bind. Both IPv4 and IPv6
436-
addresses are supported. For example, the following command causes the server
437-
to bind to localhost only::
438-
439-
python -m http.server --bind 127.0.0.1
440-
441-
.. versionchanged:: 3.4
442-
Added the ``--bind`` option.
443-
444-
.. versionchanged:: 3.8
445-
Support IPv6 in the ``--bind`` option.
446-
447-
By default, the server uses the current directory. The option ``-d/--directory``
448-
specifies a directory to which it should serve the files. For example,
449-
the following command uses a specific directory::
450-
451-
python -m http.server --directory /tmp/
452-
453-
.. versionchanged:: 3.7
454-
Added the ``--directory`` option.
455-
456-
By default, the server is conformant to HTTP/1.0. The option ``-p/--protocol``
457-
specifies the HTTP version to which the server is conformant. For example, the
458-
following command runs an HTTP/1.1 conformant server::
459-
460-
python -m http.server --protocol HTTP/1.1
461-
462-
.. versionchanged:: 3.11
463-
Added the ``--protocol`` option.
464421

465422
.. class:: CGIHTTPRequestHandler(request, client_address, server)
466423

@@ -510,25 +467,85 @@ following command runs an HTTP/1.1 conformant server::
510467
Retaining it could lead to further :ref:`security considerations
511468
<http.server-security>`.
512469

513-
:class:`CGIHTTPRequestHandler` can be enabled in the command line by passing
514-
the ``--cgi`` option::
515470

516-
python -m http.server --cgi
471+
.. _http-server-cli:
472+
473+
Command-line interface
474+
----------------------
475+
476+
:mod:`http.server` can also be invoked directly using the :option:`-m`
477+
switch of the interpreter. The following example illustrates how to serve
478+
files relative to the current directory::
479+
480+
python -m http.server [OPTIONS] [port]
481+
482+
The following options are accepted:
483+
484+
.. program:: http.server
517485

518-
.. deprecated-removed:: 3.13 3.15
486+
.. option:: port
519487

520-
:mod:`http.server` command line ``--cgi`` support is being removed
521-
because :class:`CGIHTTPRequestHandler` is being removed.
488+
The server listens to port 8000 by default. The default can be overridden
489+
by passing the desired port number as an argument::
490+
491+
python -m http.server 9000
492+
493+
.. option:: -b, --bind <address>
494+
495+
Specifies a specific address to which it should bind. Both IPv4 and IPv6
496+
addresses are supported. By default, the server binds itself to all
497+
interfaces. For example, the following command causes the server to bind
498+
to localhost only::
499+
500+
python -m http.server --bind 127.0.0.1
501+
502+
.. versionadded:: 3.4
503+
504+
.. versionchanged:: 3.8
505+
Support IPv6 in the ``--bind`` option.
506+
507+
.. option:: -d, --directory <dir>
508+
509+
Specifies a directory to which it should serve the files. By default,
510+
the server uses the current directory. For example, the following command
511+
uses a specific directory::
512+
513+
python -m http.server --directory /tmp/
514+
515+
.. versionadded:: 3.7
516+
517+
.. option:: -p, --protocol <version>
518+
519+
Specifies the HTTP version to which the server is conformant. By default,
520+
the server is conformant to HTTP/1.0. For example, the following command
521+
runs an HTTP/1.1 conformant server::
522+
523+
python -m http.server --protocol HTTP/1.1
524+
525+
.. versionadded:: 3.11
526+
527+
.. option:: --cgi
528+
529+
:class:`CGIHTTPRequestHandler` can be enabled in the command line by passing
530+
the ``--cgi`` option::
531+
532+
python -m http.server --cgi
533+
534+
.. deprecated-removed:: 3.13 3.15
535+
536+
:mod:`http.server` command line ``--cgi`` support is being removed
537+
because :class:`CGIHTTPRequestHandler` is being removed.
522538

523539
.. warning::
524540

525-
:class:`CGIHTTPRequestHandler` and the ``--cgi`` command line option
541+
:class:`CGIHTTPRequestHandler` and the ``--cgi`` command-line option
526542
are not intended for use by untrusted clients and may be vulnerable
527543
to exploitation. Always use within a secure environment.
528544

545+
529546
.. _http.server-security:
530547

531-
Security Considerations
548+
Security considerations
532549
-----------------------
533550

534551
.. index:: pair: http.server; security

Doc/library/math.rst

Lines changed: 2 additions & 2 deletions
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

0 commit comments

Comments
 (0)