Skip to content

Commit 7e44c1f

Browse files
authored
Merge branch 'main' into feature/filecmp-coverage
2 parents 70fd4c8 + fdee11f commit 7e44c1f

211 files changed

Lines changed: 4558 additions & 1531 deletions

File tree

Some content is hidden

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

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,48 @@ Initializing and finalizing the interpreter
265265
first initialized).
266266
267267
268+
.. c:function:: int Py_FrozenMain(int argc, char **argv)
269+
270+
.. index:: single: freeze utility
271+
272+
The main program for a "frozen" Python program (an executable that embeds
273+
the interpreter together with the bytecode of the program's modules, as
274+
produced by the :program:`freeze` utility; see :source:`Tools/freeze`).
275+
276+
This function initializes the interpreter, imports the frozen module named
277+
``__main__``, and finalizes the interpreter.
278+
The frozen modules must have been registered in
279+
:c:var:`PyImport_FrozenModules` before calling this function;
280+
it is a fatal error if ``__main__`` is not among them.
281+
282+
*argc* and *argv* are byte strings like the arguments of a C program's
283+
``main`` function, and are passed to the interpreter with
284+
:c:func:`PyConfig_SetBytesArgv`.
285+
Unlike :c:func:`Py_Main`, the arguments are not parsed as Python command
286+
line options (:c:member:`PyConfig.parse_argv` is ``0``), so all of them
287+
are made available to the program in :data:`sys.argv`.
288+
Apart from that, the interpreter uses the
289+
:ref:`Python Configuration <init-python-config>`, so environment variables
290+
such as :envvar:`PYTHONPATH` are honored.
291+
Warnings about the path configuration
292+
(:c:member:`PyConfig.pathconfig_warnings`) are suppressed.
293+
If :envvar:`PYTHONINSPECT` is set and standard input is a terminal, an
294+
interactive prompt is run after ``__main__`` has finished, as with the
295+
:option:`-i` option.
296+
297+
Return ``0`` if ``__main__`` ran without an unhandled exception, ``1``
298+
otherwise, and ``120`` if finalizing the interpreter failed (see
299+
:c:func:`Py_FinalizeEx`).
300+
An unhandled :exc:`SystemExit` terminates the process.
301+
If the interpreter cannot be initialized, the process exits via
302+
:c:func:`Py_ExitStatusException`.
303+
304+
On Windows, this function is not exported by the Python DLL.
305+
The :program:`freeze` utility compiles :file:`Python/frozenmain.c` into the
306+
frozen program instead, together with the Windows-specific hooks that the
307+
function requires.
308+
309+
268310
.. c:function:: int Py_RunMain(void)
269311
270312
Executes the main module in a fully configured CPython runtime.

‎Doc/library/ast.rst‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ Node classes
4848
module and re-exported in :mod:`!ast`.
4949

5050
There is one class defined for each left-hand side symbol in the abstract
51-
grammar (for example, :class:`ast.stmt` or :class:`ast.expr`). In addition,
51+
grammar (for example, :class:`!ast.stmt` or :class:`!ast.expr`). In addition,
5252
there is one class defined for each constructor on the right-hand side; these
5353
classes inherit from the classes for the left-hand side trees. For example,
54-
:class:`ast.BinOp` inherits from :class:`ast.expr`. For production rules
54+
:class:`ast.BinOp` inherits from :class:`!ast.expr`. For production rules
5555
with alternatives (aka "sums"), the left-hand side class is abstract: only
5656
instances of specific constructor nodes are ever created.
5757

@@ -65,7 +65,7 @@ Node classes
6565

6666
Each instance of a concrete class has one attribute for each child node,
6767
of the type as defined in the grammar. For example, :class:`ast.BinOp`
68-
instances have an attribute :attr:`left` of type :class:`ast.expr`.
68+
instances have an attribute :attr:`!left` of type :class:`!ast.expr`.
6969

7070
If these attributes are marked as optional in the grammar (using a
7171
question mark), the value might be ``None``. If the attributes can have
@@ -104,10 +104,11 @@ Node classes
104104
one can get the source segment of a one-line expression node using
105105
``source_line[node.col_offset : node.end_col_offset]``.
106106

107-
The constructor of a class :class:`ast.T` parses its arguments as follows:
107+
The constructors of AST node classes parse their arguments as follows:
108108

109109
* If there are positional arguments, there must be as many as there are items
110-
in :attr:`T._fields`; they will be assigned as attributes of these names.
110+
in :attr:`!_fields`; they will be assigned to attributes with
111+
the corresponding names.
111112
* If there are keyword arguments, they will set the attributes of the same
112113
names to the given values.
113114

@@ -2223,8 +2224,8 @@ Async and await
22232224

22242225
.. note::
22252226
When a string is parsed by :func:`ast.parse`, operator nodes (subclasses
2226-
of :class:`ast.operator`, :class:`ast.unaryop`, :class:`ast.cmpop`,
2227-
:class:`ast.boolop` and :class:`ast.expr_context`) on the returned tree
2227+
of :class:`!ast.operator`, :class:`!ast.unaryop`, :class:`!ast.cmpop`,
2228+
:class:`!ast.boolop` and :class:`!ast.expr_context`) on the returned tree
22282229
will be singletons. Changes to one will be reflected in all other
22292230
occurrences of the same value (for example, :class:`ast.Add`).
22302231

‎Doc/library/ctypes.rst‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,17 @@ In addition, if a function argument is explicitly declared to be a pointer type
11071107
type (``c_int`` in this case) can be passed to the function. ctypes will apply
11081108
the required :func:`byref` conversion in this case automatically.
11091109

1110+
These conversions are also applied to the :attr:`!_as_parameter_` attribute of
1111+
an object passed for a pointer argument (see
1112+
:ref:`ctypes-calling-functions-with-own-custom-data-types`). So, for a
1113+
``POINTER(c_int)`` argument, an object whose :attr:`!_as_parameter_` is a
1114+
``c_int`` instance is passed by reference, and one whose :attr:`!_as_parameter_`
1115+
is a ``c_int`` array is accepted as well.
1116+
1117+
.. versionchanged:: next
1118+
Objects with an :attr:`!_as_parameter_` attribute now receive the same
1119+
implicit conversions for pointer arguments as the object they wrap.
1120+
11101121
To set a POINTER type field to ``NULL``, you can assign ``None``::
11111122

11121123
>>> bar.values = None

‎Doc/library/datetime.rst‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2699,6 +2699,10 @@ convenience.
26992699
| | number, zero-padded to 6 | 999999 | |
27002700
| | digits. | | |
27012701
+-----------+--------------------------------+------------------------+-------+
2702+
| ``%Nf`` | Fraction of a second truncated | 000, 001, ..., 999 | \(5) |
2703+
| | to *N* digits, where *N* is | (``%3f``) | |
2704+
| | from 1 to 6. | | |
2705+
+-----------+--------------------------------+------------------------+-------+
27022706
| ``%:z`` | UTC offset in the form | (empty), +00:00, | \(6) |
27032707
| | ``±HH:MM[:SS[.ffffff]]`` | -04:00, +10:30, | |
27042708
| | (empty string if the object is | +06:34:15, | |
@@ -2721,6 +2725,9 @@ differences between platforms in handling of unsupported format specifiers.
27212725
``%D``, ``%F``, ``%n``, ``%t``, and ``%:z`` were added for
27222726
:meth:`~.datetime.strptime`.
27232727

2728+
.. versionadded:: next
2729+
``%Nf`` was added.
2730+
27242731

27252732
Technical detail
27262733
^^^^^^^^^^^^^^^^
@@ -2745,6 +2752,13 @@ in the format string will be pulled from the default value.
27452752
the default year of 1900 is *not* a leap year. Always add a default leap
27462753
year to partial date strings before parsing.
27472754

2755+
.. note::
2756+
If a :meth:`~.datetime.strptime` format string contains more than
2757+
one directive for the same field, for example both ``%Y`` and ``%y``,
2758+
every directive must still match the input, but only the value of the
2759+
last one is used. For example, parsing ``200099`` with ``%Y%y`` gives
2760+
the year 1999. Repeating the same directive, like ``%Y%Y``, raises an error.
2761+
27482762
.. testsetup::
27492763

27502764
# doctest seems to turn the warning into an error which makes it
@@ -2826,7 +2840,8 @@ Notes:
28262840

28272841
(5)
28282842
When used with the :meth:`~.datetime.strptime` method, the ``%f`` directive
2829-
accepts from one to six digits and zero pads on the right. ``%f`` is
2843+
accepts from one to six digits and zero pads on the right, while ``%Nf``
2844+
accepts exactly *N* digits. ``%f`` is
28302845
an extension to the set of format characters in the C standard (but
28312846
implemented separately in datetime objects, and therefore always
28322847
available).

‎Doc/library/pathlib.rst‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,10 +586,23 @@ Pure paths provide the following methods and properties:
586586
True
587587
>>> PurePath('a/b.py').full_match('*.py')
588588
False
589-
>>> PurePath('/a/b/c.py').full_match('/a/**')
590-
True
591589
>>> PurePath('/a/b/c.py').full_match('**/*.py')
592590
True
591+
>>> PurePath('/a/b/c.py').full_match('/a/**')
592+
True
593+
594+
Patterns ending in "``/**``", as in the example above, may surprise when
595+
passed to ``full_match``. Even though "``**``" can match 0 segments,
596+
"``.../**``" requires a separator to match. Hence "``/a/**``" does not
597+
match path "``/a``". Since :class:`PurePath` drops trailing slashes, this
598+
pattern also does not match "``/a/``".
599+
600+
::
601+
602+
>>> PurePath('/a').full_match('/a/**')
603+
False
604+
>>> PurePath('/a/').full_match('/a/**')
605+
False
593606

594607
.. seealso::
595608
:ref:`pathlib-pattern-language` documentation.
@@ -1814,6 +1827,8 @@ The following wildcards are supported in patterns for
18141827

18151828
``**`` (entire segment)
18161829
Matches any number of file or directory segments, including zero.
1830+
Note that in :meth:`~PurePath.full_match`, "``a/**``" does not match
1831+
"``a``", whereas :meth:`~Path.glob` yields "``a``" for that pattern.
18171832
``*`` (entire segment)
18181833
Matches one file or directory segment.
18191834
``*`` (part of a segment)

‎Doc/library/pickle.rst‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,11 @@ The following types can be pickled:
517517
* classes accessible from the top level of a module;
518518

519519
* instances of such classes for which the result of calling :meth:`~object.__getstate__`
520-
is picklable (see section :ref:`pickle-inst` for details).
520+
is picklable (see section :ref:`pickle-inst` for details);
521+
522+
* weak references and the weak containers from the :mod:`weakref` module,
523+
provided that the weakly referenced objects are strongly referenced
524+
elsewhere in the same pickle (see :class:`weakref.ref`).
521525

522526
Attempts to pickle unpicklable objects will raise the :exc:`PicklingError`
523527
exception; when this happens, an unspecified number of bytes may have already

‎Doc/library/sys.rst‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,6 +2432,26 @@ always available. Unless explicitly noted otherwise, all variables are read-only
24322432
.. versionadded:: 3.2
24332433

24342434

2435+
.. data:: EXIT_SUCCESS
2436+
2437+
An int you can use to indicate your program ended gracefully.
2438+
2439+
.. code-block:: python
2440+
2441+
sys.exit(sys.EXIT_SUCCESS)
2442+
2443+
.. versionadded:: 3.16
2444+
2445+
.. data:: EXIT_FAILURE
2446+
2447+
An int you can use to indicate your program encountered an error.
2448+
2449+
.. code-block:: python
2450+
2451+
sys.exit(sys.EXIT_FAILURE)
2452+
2453+
.. versionadded:: 3.16
2454+
24352455
.. rubric:: Citations
24362456

24372457
.. [C99] ISO/IEC 9899:1999. "Programming languages -- C." A public draft of this standard is available at https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf\ .

0 commit comments

Comments
 (0)