Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8addbbe

Browse files
committed
Catch up with main
2 parents 46063fb + 2feec0f commit 8addbbe

57 files changed

Lines changed: 4837 additions & 4068 deletions

Some content is hidden

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

Doc/library/ast.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,6 +2457,13 @@ effects on the compilation of a program:
24572457
Generates and returns an abstract syntax tree instead of returning a
24582458
compiled code object.
24592459

2460+
.. data:: PyCF_OPTIMIZED_AST
2461+
2462+
The returned AST is optimized according to the *optimize* argument
2463+
in :func:`compile` or :func:`ast.parse`.
2464+
2465+
.. versionadded:: 3.13
2466+
24602467
.. data:: PyCF_TYPE_COMMENTS
24612468

24622469
Enables support for :pep:`484` and :pep:`526` style type comments

Doc/library/csv.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ The :mod:`csv` module defines the following functions:
5555

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

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

453+
.. _reader-objects:
454+
452455
Reader Objects
453456
--------------
454457

Doc/library/fractions.rst

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ another rational number, or from a string.
106106
presentation types ``"e"``, ``"E"``, ``"f"``, ``"F"``, ``"g"``, ``"G"``
107107
and ``"%""``.
108108

109+
.. versionchanged:: 3.13
110+
Formatting of :class:`Fraction` instances without a presentation type
111+
now supports fill, alignment, sign handling, minimum width and grouping.
112+
109113
.. attribute:: numerator
110114

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

202206
.. method:: __format__(format_spec, /)
203207

204-
Provides support for float-style formatting of :class:`Fraction`
205-
instances via the :meth:`str.format` method, the :func:`format` built-in
206-
function, or :ref:`Formatted string literals <f-strings>`. The
207-
presentation types ``"e"``, ``"E"``, ``"f"``, ``"F"``, ``"g"``, ``"G"``
208-
and ``"%"`` are supported. For these presentation types, formatting for a
209-
:class:`Fraction` object ``x`` follows the rules outlined for
210-
the :class:`float` type in the :ref:`formatspec` section.
208+
Provides support for formatting of :class:`Fraction` instances via the
209+
:meth:`str.format` method, the :func:`format` built-in function, or
210+
:ref:`Formatted string literals <f-strings>`.
211+
212+
If the ``format_spec`` format specification string does not end with one
213+
of the presentation types ``'e'``, ``'E'``, ``'f'``, ``'F'``, ``'g'``,
214+
``'G'`` or ``'%'`` then formatting follows the general rules for fill,
215+
alignment, sign handling, minimum width, and grouping as described in the
216+
:ref:`format specification mini-language <formatspec>`. The "alternate
217+
form" flag ``'#'`` is supported: if present, it forces the output string
218+
to always include an explicit denominator, even when the value being
219+
formatted is an exact integer. The zero-fill flag ``'0'`` is not
220+
supported.
221+
222+
If the ``format_spec`` format specification string ends with one of
223+
the presentation types ``'e'``, ``'E'``, ``'f'``, ``'F'``, ``'g'``,
224+
``'G'`` or ``'%'`` then formatting follows the rules outlined for the
225+
:class:`float` type in the :ref:`formatspec` section.
211226

212227
Here are some examples::
213228

214229
>>> from fractions import Fraction
230+
>>> format(Fraction(103993, 33102), '_')
231+
'103_993/33_102'
232+
>>> format(Fraction(1, 7), '.^+10')
233+
'...+1/7...'
234+
>>> format(Fraction(3, 1), '')
235+
'3'
236+
>>> format(Fraction(3, 1), '#')
237+
'3/1'
215238
>>> format(Fraction(1, 7), '.40g')
216239
'0.1428571428571428571428571428571428571429'
217240
>>> format(Fraction('1234567.855'), '_.2f')

Doc/library/itertools.rst

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,14 @@ loops that truncate the stream.
164164
Added the optional *initial* parameter.
165165

166166

167-
.. function:: batched(iterable, n)
167+
.. function:: batched(iterable, n, *, strict=False)
168168

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

172+
If *strict* is true, will raise a :exc:`ValueError` if the final
173+
batch is shorter than *n*.
174+
172175
Loops over the input iterable and accumulates data into tuples up to
173176
size *n*. The input is consumed lazily, just enough to fill a batch.
174177
The result is yielded as soon as the batch is full or when the input
@@ -190,16 +193,21 @@ loops that truncate the stream.
190193

191194
Roughly equivalent to::
192195

193-
def batched(iterable, n):
196+
def batched(iterable, n, *, strict=False):
194197
# batched('ABCDEFG', 3) --> ABC DEF G
195198
if n < 1:
196199
raise ValueError('n must be at least one')
197200
it = iter(iterable)
198201
while batch := tuple(islice(it, n)):
202+
if strict and len(batch) != n:
203+
raise ValueError('batched(): incomplete batch')
199204
yield batch
200205

201206
.. versionadded:: 3.12
202207

208+
.. versionchanged:: 3.13
209+
Added the *strict* option.
210+
203211

204212
.. function:: chain(*iterables)
205213

@@ -1036,10 +1044,15 @@ The following recipes have a more mathematical flavor:
10361044
# sum_of_squares([10, 20, 30]) -> 1400
10371045
return math.sumprod(*tee(it))
10381046
1039-
def transpose(it):
1040-
"Swap the rows and columns of the input."
1047+
def reshape(matrix, cols):
1048+
"Reshape a 2-D matrix to have a given number of columns."
1049+
# reshape([(0, 1), (2, 3), (4, 5)], 3) --> (0, 1, 2), (3, 4, 5)
1050+
return batched(chain.from_iterable(matrix), cols, strict=True)
1051+
1052+
def transpose(matrix):
1053+
"Swap the rows and columns of a 2-D matrix."
10411054
# transpose([(1, 2, 3), (11, 22, 33)]) --> (1, 11) (2, 22) (3, 33)
1042-
return zip(*it, strict=True)
1055+
return zip(*matrix, strict=True)
10431056
10441057
def matmul(m1, m2):
10451058
"Multiply two matrices."
@@ -1254,6 +1267,26 @@ The following recipes have a more mathematical flavor:
12541267
>>> sum_of_squares([10, 20, 30])
12551268
1400
12561269

1270+
>>> list(reshape([(0, 1), (2, 3), (4, 5)], 3))
1271+
[(0, 1, 2), (3, 4, 5)]
1272+
>>> M = [(0, 1, 2, 3), (4, 5, 6, 7), (8, 9, 10, 11)]
1273+
>>> list(reshape(M, 1))
1274+
[(0,), (1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (11,)]
1275+
>>> list(reshape(M, 2))
1276+
[(0, 1), (2, 3), (4, 5), (6, 7), (8, 9), (10, 11)]
1277+
>>> list(reshape(M, 3))
1278+
[(0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11)]
1279+
>>> list(reshape(M, 4))
1280+
[(0, 1, 2, 3), (4, 5, 6, 7), (8, 9, 10, 11)]
1281+
>>> list(reshape(M, 5))
1282+
Traceback (most recent call last):
1283+
...
1284+
ValueError: batched(): incomplete batch
1285+
>>> list(reshape(M, 6))
1286+
[(0, 1, 2, 3, 4, 5), (6, 7, 8, 9, 10, 11)]
1287+
>>> list(reshape(M, 12))
1288+
[(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)]
1289+
12571290
>>> list(transpose([(1, 2, 3), (11, 22, 33)]))
12581291
[(1, 11), (2, 22), (3, 33)]
12591292

Doc/library/os.rst

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4570,7 +4570,8 @@ written in Python, such as a mail server's external command delivery program.
45704570
Most users should use :func:`subprocess.run` instead of :func:`posix_spawn`.
45714571

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

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

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

4604+
.. data:: POSIX_SPAWN_CLOSEFROM
4605+
4606+
(``os.POSIX_SPAWN_CLOSEFROM``, *fd*)
4607+
4608+
Performs ``os.closerange(fd, INF)``.
4609+
46034610
These tuples correspond to the C library
46044611
:c:func:`!posix_spawn_file_actions_addopen`,
4605-
:c:func:`!posix_spawn_file_actions_addclose`, and
4606-
:c:func:`!posix_spawn_file_actions_adddup2` API calls used to prepare
4612+
:c:func:`!posix_spawn_file_actions_addclose`,
4613+
:c:func:`!posix_spawn_file_actions_adddup2`, and
4614+
:c:func:`!posix_spawn_file_actions_addclosefrom_np` API calls used to prepare
46074615
for the :c:func:`!posix_spawn` call itself.
46084616

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

46464654
.. versionadded:: 3.8
46474655

4656+
.. versionchanged:: 3.13
4657+
*env* parameter accepts ``None``.
4658+
4659+
.. versionchanged:: 3.13
4660+
``os.POSIX_SPAWN_CLOSEFROM`` is available on platforms where
4661+
:c:func:`!posix_spawn_file_actions_addclosefrom_np` exists.
4662+
46484663
.. availability:: Unix, not Emscripten, not WASI.
46494664

46504665
.. function:: posix_spawnp(path, argv, env, *, file_actions=None, \

Doc/library/tarfile.rst

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Some facts and figures:
116116
``'filemode|[compression]'``. :func:`tarfile.open` will return a :class:`TarFile`
117117
object that processes its data as a stream of blocks. No random seeking will
118118
be done on the file. If given, *fileobj* may be any object that has a
119-
:meth:`read` or :meth:`write` method (depending on the *mode*). *bufsize*
119+
:meth:`~io.TextIOBase.read` or :meth:`~io.TextIOBase.write` method (depending on the *mode*). *bufsize*
120120
specifies the blocksize and defaults to ``20 * 512`` bytes. Use this variant
121121
in combination with e.g. ``sys.stdin``, a socket :term:`file object` or a tape
122122
device. However, such a :class:`TarFile` object is limited in that it does
@@ -255,6 +255,51 @@ The following constants are available at the module level:
255255
The default character encoding: ``'utf-8'`` on Windows, the value returned by
256256
:func:`sys.getfilesystemencoding` otherwise.
257257

258+
.. data:: REGTYPE
259+
AREGTYPE
260+
261+
A regular file :attr:`~TarInfo.type`.
262+
263+
.. data:: LNKTYPE
264+
265+
A link (inside tarfile) :attr:`~TarInfo.type`.
266+
267+
.. data:: SYMTYPE
268+
269+
A symbolic link :attr:`~TarInfo.type`.
270+
271+
.. data:: CHRTYPE
272+
273+
A character special device :attr:`~TarInfo.type`.
274+
275+
.. data:: BLKTYPE
276+
277+
A block special device :attr:`~TarInfo.type`.
278+
279+
.. data:: DIRTYPE
280+
281+
A directory :attr:`~TarInfo.type`.
282+
283+
.. data:: FIFOTYPE
284+
285+
A FIFO special device :attr:`~TarInfo.type`.
286+
287+
.. data:: CONTTYPE
288+
289+
A contiguous file :attr:`~TarInfo.type`.
290+
291+
.. data:: GNUTYPE_LONGNAME
292+
293+
A GNU tar longname :attr:`~TarInfo.type`.
294+
295+
.. data:: GNUTYPE_LONGLINK
296+
297+
A GNU tar longlink :attr:`~TarInfo.type`.
298+
299+
.. data:: GNUTYPE_SPARSE
300+
301+
A GNU tar sparse file :attr:`~TarInfo.type`.
302+
258303

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

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

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

361406
*errorlevel* controls how extraction errors are handled,
362-
see :attr:`the corresponding attribute <~TarFile.errorlevel>`.
407+
see :attr:`the corresponding attribute <TarFile.errorlevel>`.
363408

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

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

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

798-
.. method:: TarInfo.replace(name=..., mtime=..., mode=..., linkname=...,
799-
uid=..., gid=..., uname=..., gname=...,
843+
.. method:: TarInfo.replace(name=..., mtime=..., mode=..., linkname=..., \
844+
uid=..., gid=..., uname=..., gname=..., \
800845
deep=True)
801846

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

817862
.. method:: TarInfo.isfile()
818863

819-
Return :const:`True` if the :class:`Tarinfo` object is a regular file.
864+
Return :const:`True` if the :class:`TarInfo` object is a regular file.
820865

821866

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

9571002
Return the modified ``TarInfo`` member.
9581003

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

9791024
- Set the owner read and write permissions
980-
(:const:`~stat.S_IRUSR`|:const:`~stat.S_IWUSR`).
1025+
(:const:`~stat.S_IRUSR` | :const:`~stat.S_IWUSR`).
9811026
- Remove the group & other executable permission
982-
(:const:`~stat.S_IXGRP`|:const:`~stat.S_IXOTH`)
1027+
(:const:`~stat.S_IXGRP` | :const:`~stat.S_IXOTH`)
9831028
if the owner doesn’t have it (:const:`~stat.S_IXUSR`).
9841029

9851030
- For other files (directories), set ``mode`` to ``None``, so

Doc/library/unittest.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,8 @@ the `load_tests protocol`_.
346346
``python -m unittest discover -s root/namespace -t root``).
347347

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

Doc/reference/grammar.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _full-grammar-specification:
2+
13
Full Grammar specification
24
==========================
35

Doc/tools/.nitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ Doc/library/ssl.rst
8686
Doc/library/stdtypes.rst
8787
Doc/library/string.rst
8888
Doc/library/subprocess.rst
89-
Doc/library/tarfile.rst
9089
Doc/library/termios.rst
9190
Doc/library/test.rst
9291
Doc/library/tkinter.rst

0 commit comments

Comments
 (0)