Skip to content

Commit

Permalink
Catch up with main
Browse files Browse the repository at this point in the history
  • Loading branch information
brandtbucher committed Dec 16, 2023
2 parents 46063fb + 2feec0f commit 8addbbe
Show file tree
Hide file tree
Showing 57 changed files with 4,837 additions and 4,068 deletions.
7 changes: 7 additions & 0 deletions Doc/library/ast.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2457,6 +2457,13 @@ effects on the compilation of a program:
Generates and returns an abstract syntax tree instead of returning a
compiled code object.

.. data:: PyCF_OPTIMIZED_AST

The returned AST is optimized according to the *optimize* argument
in :func:`compile` or :func:`ast.parse`.

.. versionadded:: 3.13

.. data:: PyCF_TYPE_COMMENTS

Enables support for :pep:`484` and :pep:`526` style type comments
Expand Down
11 changes: 7 additions & 4 deletions Doc/library/csv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ The :mod:`csv` module defines the following functions:

.. function:: reader(csvfile, dialect='excel', **fmtparams)

Return a reader object which will iterate over lines in the given *csvfile*.
*csvfile* can be any object which supports the :term:`iterator` protocol and returns a
string each time its :meth:`!__next__` method is called --- :term:`file objects
<file object>` and list objects are both suitable. If *csvfile* is a file object,
Return a :ref:`reader object <reader-objects>` that will process
lines from the given *csvfile*. A csvfile must be an iterable of
strings, each in the reader's defined csv format.
A csvfile is most commonly a file-like object or list.
If *csvfile* is a file object,
it should be opened with ``newline=''``. [1]_ An optional
*dialect* parameter can be given which is used to define a set of parameters
specific to a particular CSV dialect. It may be an instance of a subclass of
Expand Down Expand Up @@ -449,6 +450,8 @@ Dialects support the following attributes:
When ``True``, raise exception :exc:`Error` on bad CSV input.
The default is ``False``.

.. _reader-objects:

Reader Objects
--------------

Expand Down
37 changes: 30 additions & 7 deletions Doc/library/fractions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ another rational number, or from a string.
presentation types ``"e"``, ``"E"``, ``"f"``, ``"F"``, ``"g"``, ``"G"``
and ``"%""``.

.. versionchanged:: 3.13
Formatting of :class:`Fraction` instances without a presentation type
now supports fill, alignment, sign handling, minimum width and grouping.

.. attribute:: numerator

Numerator of the Fraction in lowest term.
Expand Down Expand Up @@ -201,17 +205,36 @@ another rational number, or from a string.

.. method:: __format__(format_spec, /)

Provides support for float-style formatting of :class:`Fraction`
instances via the :meth:`str.format` method, the :func:`format` built-in
function, or :ref:`Formatted string literals <f-strings>`. The
presentation types ``"e"``, ``"E"``, ``"f"``, ``"F"``, ``"g"``, ``"G"``
and ``"%"`` are supported. For these presentation types, formatting for a
:class:`Fraction` object ``x`` follows the rules outlined for
the :class:`float` type in the :ref:`formatspec` section.
Provides support for formatting of :class:`Fraction` instances via the
:meth:`str.format` method, the :func:`format` built-in function, or
:ref:`Formatted string literals <f-strings>`.

If the ``format_spec`` format specification string does not end with one
of the presentation types ``'e'``, ``'E'``, ``'f'``, ``'F'``, ``'g'``,
``'G'`` or ``'%'`` then formatting follows the general rules for fill,
alignment, sign handling, minimum width, and grouping as described in the
:ref:`format specification mini-language <formatspec>`. The "alternate
form" flag ``'#'`` is supported: if present, it forces the output string
to always include an explicit denominator, even when the value being
formatted is an exact integer. The zero-fill flag ``'0'`` is not
supported.

If the ``format_spec`` format specification string ends with one of
the presentation types ``'e'``, ``'E'``, ``'f'``, ``'F'``, ``'g'``,
``'G'`` or ``'%'`` then formatting follows the rules outlined for the
:class:`float` type in the :ref:`formatspec` section.

Here are some examples::

>>> from fractions import Fraction
>>> format(Fraction(103993, 33102), '_')
'103_993/33_102'
>>> format(Fraction(1, 7), '.^+10')
'...+1/7...'
>>> format(Fraction(3, 1), '')
'3'
>>> format(Fraction(3, 1), '#')
'3/1'
>>> format(Fraction(1, 7), '.40g')
'0.1428571428571428571428571428571428571429'
>>> format(Fraction('1234567.855'), '_.2f')
Expand Down
43 changes: 38 additions & 5 deletions Doc/library/itertools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,14 @@ loops that truncate the stream.
Added the optional *initial* parameter.


.. function:: batched(iterable, n)
.. function:: batched(iterable, n, *, strict=False)

Batch data from the *iterable* into tuples of length *n*. The last
batch may be shorter than *n*.

If *strict* is true, will raise a :exc:`ValueError` if the final
batch is shorter than *n*.

Loops over the input iterable and accumulates data into tuples up to
size *n*. The input is consumed lazily, just enough to fill a batch.
The result is yielded as soon as the batch is full or when the input
Expand All @@ -190,16 +193,21 @@ loops that truncate the stream.

Roughly equivalent to::

def batched(iterable, n):
def batched(iterable, n, *, strict=False):
# batched('ABCDEFG', 3) --> ABC DEF G
if n < 1:
raise ValueError('n must be at least one')
it = iter(iterable)
while batch := tuple(islice(it, n)):
if strict and len(batch) != n:
raise ValueError('batched(): incomplete batch')
yield batch

.. versionadded:: 3.12

.. versionchanged:: 3.13
Added the *strict* option.


.. function:: chain(*iterables)

Expand Down Expand Up @@ -1036,10 +1044,15 @@ The following recipes have a more mathematical flavor:
# sum_of_squares([10, 20, 30]) -> 1400
return math.sumprod(*tee(it))
def transpose(it):
"Swap the rows and columns of the input."
def reshape(matrix, cols):
"Reshape a 2-D matrix to have a given number of columns."
# reshape([(0, 1), (2, 3), (4, 5)], 3) --> (0, 1, 2), (3, 4, 5)
return batched(chain.from_iterable(matrix), cols, strict=True)

def transpose(matrix):
"Swap the rows and columns of a 2-D matrix."
# transpose([(1, 2, 3), (11, 22, 33)]) --> (1, 11) (2, 22) (3, 33)
return zip(*it, strict=True)
return zip(*matrix, strict=True)
def matmul(m1, m2):
"Multiply two matrices."
Expand Down Expand Up @@ -1254,6 +1267,26 @@ The following recipes have a more mathematical flavor:
>>> sum_of_squares([10, 20, 30])
1400

>>> list(reshape([(0, 1), (2, 3), (4, 5)], 3))
[(0, 1, 2), (3, 4, 5)]
>>> M = [(0, 1, 2, 3), (4, 5, 6, 7), (8, 9, 10, 11)]
>>> list(reshape(M, 1))
[(0,), (1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (11,)]
>>> list(reshape(M, 2))
[(0, 1), (2, 3), (4, 5), (6, 7), (8, 9), (10, 11)]
>>> list(reshape(M, 3))
[(0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11)]
>>> list(reshape(M, 4))
[(0, 1, 2, 3), (4, 5, 6, 7), (8, 9, 10, 11)]
>>> list(reshape(M, 5))
Traceback (most recent call last):
...
ValueError: batched(): incomplete batch
>>> list(reshape(M, 6))
[(0, 1, 2, 3, 4, 5), (6, 7, 8, 9, 10, 11)]
>>> list(reshape(M, 12))
[(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)]

>>> list(transpose([(1, 2, 3), (11, 22, 33)]))
[(1, 11), (2, 22), (3, 33)]

Expand Down
21 changes: 18 additions & 3 deletions Doc/library/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4570,7 +4570,8 @@ written in Python, such as a mail server's external command delivery program.
Most users should use :func:`subprocess.run` instead of :func:`posix_spawn`.

The positional-only arguments *path*, *args*, and *env* are similar to
:func:`execve`.
:func:`execve`. *env* is allowed to be ``None``, in which case current
process' environment is used.

The *path* parameter is the path to the executable file. The *path* should
contain a directory. Use :func:`posix_spawnp` to pass an executable file
Expand Down Expand Up @@ -4600,10 +4601,17 @@ written in Python, such as a mail server's external command delivery program.

Performs ``os.dup2(fd, new_fd)``.

.. data:: POSIX_SPAWN_CLOSEFROM

(``os.POSIX_SPAWN_CLOSEFROM``, *fd*)

Performs ``os.closerange(fd, INF)``.

These tuples correspond to the C library
:c:func:`!posix_spawn_file_actions_addopen`,
:c:func:`!posix_spawn_file_actions_addclose`, and
:c:func:`!posix_spawn_file_actions_adddup2` API calls used to prepare
:c:func:`!posix_spawn_file_actions_addclose`,
:c:func:`!posix_spawn_file_actions_adddup2`, and
:c:func:`!posix_spawn_file_actions_addclosefrom_np` API calls used to prepare
for the :c:func:`!posix_spawn` call itself.

The *setpgroup* argument will set the process group of the child to the value
Expand Down Expand Up @@ -4645,6 +4653,13 @@ written in Python, such as a mail server's external command delivery program.

.. versionadded:: 3.8

.. versionchanged:: 3.13
*env* parameter accepts ``None``.

.. versionchanged:: 3.13
``os.POSIX_SPAWN_CLOSEFROM`` is available on platforms where
:c:func:`!posix_spawn_file_actions_addclosefrom_np` exists.

.. availability:: Unix, not Emscripten, not WASI.

.. function:: posix_spawnp(path, argv, env, *, file_actions=None, \
Expand Down
67 changes: 56 additions & 11 deletions Doc/library/tarfile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Some facts and figures:
``'filemode|[compression]'``. :func:`tarfile.open` will return a :class:`TarFile`
object that processes its data as a stream of blocks. No random seeking will
be done on the file. If given, *fileobj* may be any object that has a
:meth:`read` or :meth:`write` method (depending on the *mode*). *bufsize*
:meth:`~io.TextIOBase.read` or :meth:`~io.TextIOBase.write` method (depending on the *mode*). *bufsize*
specifies the blocksize and defaults to ``20 * 512`` bytes. Use this variant
in combination with e.g. ``sys.stdin``, a socket :term:`file object` or a tape
device. However, such a :class:`TarFile` object is limited in that it does
Expand Down Expand Up @@ -255,6 +255,51 @@ The following constants are available at the module level:
The default character encoding: ``'utf-8'`` on Windows, the value returned by
:func:`sys.getfilesystemencoding` otherwise.

.. data:: REGTYPE
AREGTYPE

A regular file :attr:`~TarInfo.type`.

.. data:: LNKTYPE

A link (inside tarfile) :attr:`~TarInfo.type`.

.. data:: SYMTYPE

A symbolic link :attr:`~TarInfo.type`.

.. data:: CHRTYPE

A character special device :attr:`~TarInfo.type`.

.. data:: BLKTYPE

A block special device :attr:`~TarInfo.type`.

.. data:: DIRTYPE

A directory :attr:`~TarInfo.type`.

.. data:: FIFOTYPE

A FIFO special device :attr:`~TarInfo.type`.

.. data:: CONTTYPE

A contiguous file :attr:`~TarInfo.type`.

.. data:: GNUTYPE_LONGNAME

A GNU tar longname :attr:`~TarInfo.type`.

.. data:: GNUTYPE_LONGLINK

A GNU tar longlink :attr:`~TarInfo.type`.

.. data:: GNUTYPE_SPARSE

A GNU tar sparse file :attr:`~TarInfo.type`.


Each of the following constants defines a tar archive format that the
:mod:`tarfile` module is able to create. See section :ref:`tar-formats` for
Expand Down Expand Up @@ -325,7 +370,7 @@ be finalized; only the internally used file object will be closed. See the

*name* is the pathname of the archive. *name* may be a :term:`path-like object`.
It can be omitted if *fileobj* is given.
In this case, the file object's :attr:`name` attribute is used if it exists.
In this case, the file object's :attr:`!name` attribute is used if it exists.

*mode* is either ``'r'`` to read from an existing archive, ``'a'`` to append
data to an existing file, ``'w'`` to create a new file overwriting an existing
Expand Down Expand Up @@ -359,7 +404,7 @@ be finalized; only the internally used file object will be closed. See the
messages). The messages are written to ``sys.stderr``.

*errorlevel* controls how extraction errors are handled,
see :attr:`the corresponding attribute <~TarFile.errorlevel>`.
see :attr:`the corresponding attribute <TarFile.errorlevel>`.

The *encoding* and *errors* arguments define the character encoding to be
used for reading or writing the archive and how conversion errors are going
Expand Down Expand Up @@ -645,8 +690,8 @@ It does *not* contain the file's data itself.
:meth:`~TarFile.getmember`, :meth:`~TarFile.getmembers` and
:meth:`~TarFile.gettarinfo`.

Modifying the objects returned by :meth:`~!TarFile.getmember` or
:meth:`~!TarFile.getmembers` will affect all subsequent
Modifying the objects returned by :meth:`~TarFile.getmember` or
:meth:`~TarFile.getmembers` will affect all subsequent
operations on the archive.
For cases where this is unwanted, you can use :mod:`copy.copy() <copy>` or
call the :meth:`~TarInfo.replace` method to create a modified copy in one step.
Expand Down Expand Up @@ -795,8 +840,8 @@ A ``TarInfo`` object has the following public data attributes:

A dictionary containing key-value pairs of an associated pax extended header.

.. method:: TarInfo.replace(name=..., mtime=..., mode=..., linkname=...,
uid=..., gid=..., uname=..., gname=...,
.. method:: TarInfo.replace(name=..., mtime=..., mode=..., linkname=..., \
uid=..., gid=..., uname=..., gname=..., \
deep=True)

.. versionadded:: 3.12
Expand All @@ -816,7 +861,7 @@ A :class:`TarInfo` object also provides some convenient query methods:

.. method:: TarInfo.isfile()

Return :const:`True` if the :class:`Tarinfo` object is a regular file.
Return :const:`True` if the :class:`TarInfo` object is a regular file.


.. method:: TarInfo.isreg()
Expand Down Expand Up @@ -952,7 +997,7 @@ reused in custom filters:
path (after following symlinks) would end up outside the destination.
This raises :class:`~tarfile.OutsideDestinationError`.
- Clear high mode bits (setuid, setgid, sticky) and group/other write bits
(:const:`~stat.S_IWGRP`|:const:`~stat.S_IWOTH`).
(:const:`~stat.S_IWGRP` | :const:`~stat.S_IWOTH`).

Return the modified ``TarInfo`` member.

Expand All @@ -977,9 +1022,9 @@ reused in custom filters:
- For regular files, including hard links:

- Set the owner read and write permissions
(:const:`~stat.S_IRUSR`|:const:`~stat.S_IWUSR`).
(:const:`~stat.S_IRUSR` | :const:`~stat.S_IWUSR`).
- Remove the group & other executable permission
(:const:`~stat.S_IXGRP`|:const:`~stat.S_IXOTH`)
(:const:`~stat.S_IXGRP` | :const:`~stat.S_IXOTH`)
if the owner doesn’t have it (:const:`~stat.S_IXUSR`).

- For other files (directories), set ``mode`` to ``None``, so
Expand Down
4 changes: 2 additions & 2 deletions Doc/library/unittest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ the `load_tests protocol`_.
``python -m unittest discover -s root/namespace -t root``).

.. versionchanged:: 3.11
Python 3.11 dropped the :term:`namespace packages <namespace package>`
support. It has been broken since Python 3.7. Start directory and
:mod:`unittest` dropped the :term:`namespace packages <namespace package>`
support in Python 3.11. It has been broken since Python 3.7. Start directory and
subdirectories containing tests must be regular package that have
``__init__.py`` file.

Expand Down
2 changes: 2 additions & 0 deletions Doc/reference/grammar.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _full-grammar-specification:

Full Grammar specification
==========================

Expand Down
1 change: 0 additions & 1 deletion Doc/tools/.nitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ Doc/library/ssl.rst
Doc/library/stdtypes.rst
Doc/library/string.rst
Doc/library/subprocess.rst
Doc/library/tarfile.rst
Doc/library/termios.rst
Doc/library/test.rst
Doc/library/tkinter.rst
Expand Down
Loading

0 comments on commit 8addbbe

Please sign in to comment.