8000 Merge branch 'main' into fix-square · python/cpython@e886d29 · GitHub
[go: up one dir, main page]

Skip to content

Commit e886d29

Browse files
authored
Merge branch 'main' into fix-square
2 parents 6c35f40 + 498598e commit e886d29

File tree

107 files changed

+3483
-1548
lines changed

Some content is hidden

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

107 files changed

+3483
-1548
lines changed

.azure-pipelines/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
displayName: Pre-build checks
99

1010
pool:
11-
vmImage: ubuntu-20.04
11+
vmImage: ubuntu-22.04
1212

1313
steps:
1414
- template: ./prebuild-checks.yml
@@ -20,7 +20,7 @@ jobs:
2020
condition: and(succeeded(), eq(dependencies.Prebuild.outputs['docs.run'], 'true'))
2121

2222
pool:
23-
vmImage: ubuntu-20.04
23+
vmImage: ubuntu-22.04
2424

2525
steps:
2626
- template: ./docs-steps.yml
@@ -52,7 +52,7 @@ jobs:
5252
condition: and(succeeded(), eq(dependencies.Prebuild.outputs['tests.run'], 'true'))
5353

5454
pool:
55-
vmImage: ubuntu-20.04
55+
vmImage: ubuntu-22.04
5656

5757
variables:
5858
testRunTitle: '$(build.sourceBranchName)-linux'
@@ -78,7 +78,7 @@ jobs:
7878
)
7979
8080
pool:
81-
vmImage: ubuntu-20.04
81+
vmImage: ubuntu-22.04
8282

8383
variables:
8484
testRunTitle: '$(Build.SourceBranchName)-linux-coverage'

.azure-pipelines/pr.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
displayName: Pre-build checks
99

1010
pool:
11-
vmImage: ubuntu-20.04
11+
vmImage: ubuntu-22.04
1212

1313
steps:
1414
- template: ./prebuild-checks.yml
@@ -20,7 +20,7 @@ jobs:
2020
condition: and(succeeded(), eq(dependencies.Prebuild.outputs['docs.run'], 'true'))
2121

2222
pool:
23-
vmImage: ubuntu-20.04
23+
vmImage: ubuntu-22.04
2424

2525
steps:
2626
- template: ./docs-steps.yml
@@ -52,7 +52,7 @@ jobs:
5252
condition: and(succeeded(), eq(dependencies.Prebuild.outputs['tests.run'], 'true'))
5353

5454
pool:
55-
vmImage: ubuntu-20.04
55+
vmImage: ubuntu-22.04
5656

5757
variables:
5858
testRunTitle: '$(system.pullRequest.TargetBranch)-linux'
@@ -78,7 +78,7 @@ jobs:
7878
)
7979
8080
pool:
81-
vmImage: ubuntu-20.04
81+
vmImage: ubuntu-22.04
8282

8383
variables:
8484
testRunTitle: '$(Build.SourceBranchName)-linux-coverage'

.github/CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
# GitHub
88
.github/** @ezio-melotti
99

10+
# Build system
11+
configure* @erlend-aasland @corona10
12+
1013
# asyncio
1114
**/*asyncio* @1st1 @asvetlov @gvanrossum @kumaraditya303
1215

Doc/c-api/long.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
9494
ignored. If there are no digits or *str* is not NULL-terminated following the
9595
digits and trailing whitespace, :exc:`ValueError` will be raised.
9696
97+
.. seealso:: Python methods :meth:`int.to_bytes` and :meth:`int.from_bytes`
98+
to convert a :c:type:`PyLongObject` to/from an array of bytes in base
99+
``256``. You can call those from C using :c:func:`PyObject_CallMethod`.
100+
97101
98102
.. c:function:: PyObject* PyLong_FromUnicodeObject(PyObject *u, int base)
99103

Doc/howto/logging-cookbook.rst

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,26 +1982,47 @@ Using a rotator and namer to customize log rotation processing
19821982
--------------------------------------------------------------
19831983

19841984
An example of how you can define a namer and rotator is given in the following
1985-
snippet, which shows zlib-based compression of the log file::
1985+
runnable script, which shows gzip compression of the log file::
1986+
1987+
import gzip
1988+
import logging
1989+
import logging.handlers
1990+
import os
1991+
import shutil
19861992

19871993
def namer(name):
19881994
return name + ".gz"
19891995

19901996
def rotator(source, dest):
1991-
with open(source, "rb") as sf:
1992-
data = sf.read()
1993-
compressed = zlib.compress(data, 9)
1994-
with open(dest, "wb") as df:
1995-
df.write(compressed)
1997+
with open(source, 'rb') as f_in:
1998+
with gzip.open(dest, 'wb') as f_out:
1999+
shutil.copyfileobj(f_in, f_out)
19962000
os.remove(source)
19972001

1998-
rh = logging.handlers.RotatingFileHandler(...)
2002+
2003+
rh = logging.handlers.RotatingFileHandler('rotated.log', maxBytes=128, backupCount=5)
19992004
rh.rotator = rotator
20002005
rh.namer = namer
20012006

2002-
These are not "true" .gz files, as they are bare compressed data, with no
2003-
"container" such as you’d find in an actual gzip file. This snippet is just
2004-
for illustration purposes.
2007+
root = logging.getLogger()
2008+
root.setLevel(logging.INFO)
2009+
root.addHandler(rh)
2010+
f = logging.Formatter('%(asctime)s %(message)s')
2011+
rh.setFormatter(f)
2012+
for i in range(1000):
2013+
root.info(f'Message no. {i + 1}')
2014+
2015+
After running this, you will see six new files, five of which are compressed:
2016+
2017+
.. code-block:: shell-session
2018+
2019+
$ ls rotated.log*
2020+
rotated.log rotated.log.2.gz rotated.log.4.gz
2021+
rotated.log.1.gz rotated.log.3.gz rotated.log.5.gz
2022+
$ zcat rotated.log.1.gz
2023+
2023-01-20 02:28:17,767 Message no. 996
2024+
2023-01-20 02:28:17,767 Message no. 997
2025+
2023-01-20 02:28:17,767 Message no. 998
20052026
20062027
A more elaborate multiprocessing example
20072028
----------------------------------------

Doc/library/asyncio.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ Additionally, there are **low-level** APIs for
5656
* :ref:`bridge <asyncio-futures>` callback-based libraries and code
5757
with async/await syntax.
5858

59+
You can experiment with an ``asyncio`` concurrent context in the REPL:
60+
61+
.. code-block:: pycon
62+
63+
$ python -m asyncio
64+
asyncio REPL ...
65+
Use "await" directly instead of "asyncio.run()".
66+
Type "help", "copyright", "credits" or "license" for more information.
67+
>>> import asyncio
68+
>>> await asyncio.sleep(10, result='hello')
69+
'hello'
70+
5971
.. include:: ../includes/wasm-notavail.rst
6072

6173
.. We use the "rubric" directive here to avoid creating

Doc/library/ctypes.rst

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,14 @@ integer, string, bytes, a :mod:`ctypes` instance, or an object with an
466466
Return types
467467
^^^^^^^^^^^^
468468

469+
.. testsetup::
470+
471+
from ctypes import CDLL, c_char, c_char_p
472+
from ctypes.util import find_library
473+
libc = CDLL(find_library('c'))
474+
strchr = libc.strchr
475+
476+
469477
By default functions are assumed to return the C :c:expr:`int` type. Other
470478
return types can be specified by setting the :attr:`restype` attribute of the
471479
function object.
@@ -502,18 +510,19 @@ If you want to avoid the ``ord("x")`` calls above, you can set the
502510
:attr:`argtypes` attribute, and the second argument will be converted from a
503511
single character Python bytes object into a C char::
504512

513+
.. doctest::
514+
505515
>>> strchr.restype = c_char_p
506516
>>> strchr.argtypes = [c_char_p, c_char]
507517
>>> strchr(b"abcdef", b"d")
508-
'def'
518+
b'def'
509519
>>> strchr(b"abcdef", b"def")
510520
Traceback (most recent call last):
511-
File "<stdin>", line 1, in <module>
512-
ArgumentError: argument 2: TypeError: one character string expected
521+
ctypes.ArgumentError: argument 2: TypeError: one character bytes, bytearray or integer expected
513522
>>> print(strchr(b"abcdef", b"x"))
514523
None
515524
>>> strchr(b"abcdef", b"d")
516-
'def'
525+
b'def'
517526
>>>
518527

519528
You can also use a callable Python object (a function or a class for example) as

Doc/library/dis.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,10 @@ iterations of the loop.
700700
Yields ``STACK.pop()`` from a :term:`generator`.
701701

702702
.. versionchanged:: 3.11
703-
oparg set to be the stack depth, for efficient handling on frames.
703+
oparg set to be the stack depth.
704+
705+
.. versionchanged:: 3.12
706+
oparg set to be the exception block depth, F438 for efficient closing of generators.
704707

705708

706709
.. opcode:: SETUP_ANNOTATIONS

Doc/library/enum.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ are not normal Python classes. See
5252

5353
.. note:: Nomenclature
5454

55-
- The class :class:`Color` is an *enumeration* (or *enum*)
56-
- The attributes :attr:`Color.RED`, :attr:`Color.GREEN`, etc., are
55+
- The class :class:`!Color` is an *enumeration* (or *enum*)
56+
- The attributes :attr:`!Color.RED`, :attr:`!Color.GREEN`, etc., are
5757
*enumeration members* (or *members*) and are functionally constants.
5858
- The enum members have *names* and *values* (the name of
59-
:attr:`Color.RED` is ``RED``, the value of :attr:`Color.BLUE` is
59+
:attr:`!Color.RED` is ``RED``, the value of :attr:`!Color.BLUE` is
6060
``3``, etc.)
6161

6262
---------------
@@ -165,8 +165,8 @@ Data Types
165165
to subclass *EnumType* -- see :ref:`Subclassing EnumType <enumtype-examples>`
166166
for details.
167167

168-
*EnumType* is responsible for setting the correct :meth:`__repr__`,
169-
:meth:`__str__`, :meth:`__format__`, and :meth:`__reduce__` methods on the
168+
*EnumType* is responsible for setting the correct :meth:`!__repr__`,
169+
:meth:`!__str__`, :meth:`!__format__`, and :meth:`!__reduce__` methods on the
170170
final *enum*, as well as creating the enum members, properly handling
171171
duplicates, providing iteration over the enum class, etc.
172172

@@ -424,9 +424,9 @@ Data Types
424424
Using :class:`auto` with :class:`IntEnum` results in integers of increasing
425425
value, starting with ``1``.
426426

427-
.. versionchanged:: 3.11 :meth:`__str__` is now :func:`int.__str__` to
427+
.. versionchanged:: 3.11 :meth:`~object.__str__` is now :meth:`!int.__str__` to
428428 better support the *replacement of existing constants* use-case.
429-
:meth:`__format__` was already :func:`int.__format__` for that same reason.
429+
:meth:`~object.__format__` was already :meth:`!int.__format__` for that same reason.
430430

431431

432432
.. class:: StrEnum
@@ -761,11 +761,11 @@ Data Types
761761
Supported ``__dunder__`` names
762762
""""""""""""""""""""""""""""""
763763

764-
:attr:`__members__` is a read-only ordered mapping of ``member_name``:``member``
764+
:attr:`~EnumType.__members__` is a read-only ordered mapping of ``member_name``:``member``
765765
items. It is only available on the class.
766766

767-
:meth:`__new__`, if specified, must create and return the enum members; it is
768-
also a very good idea to set the member's :attr:`_value_` appropriately. Once
767+
:meth:`~object.__new__`, if specified, must create and return the enum members; it is
768+
also a very good idea to set the member's :attr:`!_value_` appropriately. Once
769769
all the members are created it is no longer used.
770770

771771

@@ -804,7 +804,7 @@ Utilities and Decorators
804804
.. class:: auto
805805

806806
*auto* can be used in place of a value. If used, the *Enum* machinery will
807-
call an *Enum*'s :meth:`_generate_next_value_` to get an appropriate value.
807+
call an *Enum*'s :meth:`~Enum._generate_next_value_` to get an appropriate value.
808808
For *Enum* and *IntEnum* that appropriate value will be the last value plus
809809
one; for *Flag* and *IntFlag* it will be the first power-of-two greater
810810
than the highest value; for *StrEnum* it will be the lower-cased version of
@@ -847,7 +847,7 @@ Utilities and Decorators
847847
.. decorator:: unique
848848

849849
A :keyword:`class` decorator specifically for enumerations. It searches an
850-
enumeration's :attr:`__members__`, gathering any aliases it finds; if any are
850+
enumeration's :attr:`~EnumType.__members__`, gathering any aliases it finds; if any are
851851
found :exc:`ValueError` is raised with the details::
852852

853853
>>> from enum import Enum, unique

Doc/library/fractions.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ another rational number, or from a string.
101101
.. versionchanged:: 3.12
102102
Space is allowed around the slash for string inputs: ``Fraction('2 / 3')``.
103103

104+
.. versionchanged:: 3.12
105+
:class:`Fraction` instances now support float-style formatting, with
106+
presentation types ``"e"``, ``"E"``, ``"f"``, ``"F"``, ``"g"``, ``"G"``
107+
and ``"%""``.
108+
104109
.. attribute:: numerator
105110

106111
Numerator of the Fraction in lowest term.
@@ -193,6 +198,29 @@ another rational number, or from a string.
193198
``ndigits`` is negative), again rounding half toward even. This
194199
method can also be accessed through the :func:`round` function.
195200

201+
.. method:: __format__(format_spec, /)
202+
203+
Provides support for float-style formatting of :class:`Fraction`
204+
instances via the :meth:`str.format` method, the :func:`format` built-in
205+
function, or :ref:`Formatted string literals <f-strings>`. The
206+
presentation types ``"e"``, ``"E"``, ``"f"``, ``"F"``, ``"g"``, ``"G"``
207+
and ``"%"`` are supported. For these presentation types, formatting for a
208+
:class:`Fraction` object ``x`` follows the rules outlined for
209+
the :class:`float` type in the :ref:`formatspec` section.
210+
211+
Here are some examples::
212+
213+
>>> from fractions import Fraction
214+
>>> format(Fraction(1, 7), '.40g')
215+
'0.1428571428571428571428571428571428571429'
216+
>>> format(Fraction('1234567.855'), '_.2f')
217+
'1_234_567.86'
218+
>>> f"{Fraction(355, 113):*>20.6e}"
219+
'********3.141593e+00'
220+
>>> old_price, new_price = 499, 672
221+
>>> "{:.2%} price increase".format(Fraction(new_price, old_price) - 1)
222+
'34.67% price increase'
223+
196224

197225
.. seealso::
198226

Doc/library/io.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,8 +1021,8 @@ Text I/O
10211021

10221022
.. versionadded:: 3.7
10231023

1024-
.. method:: reconfigure(*[, encoding][, errors][, newline][, \
1025-
line_buffering][, write_through])
1024+
.. method:: reconfigure(*, encoding=None, errors=None, newline=None, \
1025+
line_buffering=None, write_through=None)
10261026

10271027
Reconfigure this text stream using new settings for *encoding*,
10281028
*errors*, *newline*, *line_buffering* and *write_through*.

Doc/library/optparse.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ Other actions
404404
Some other actions supported by :mod:`optparse` are:
405405

406406
``"store_const"``
407-
store a constant value
407+
store a constant value, pre-set via :attr:`Option.const`
408408

409409
``"append"``
410410
append this option's argument to a list
@@ -925,7 +925,7 @@ The canonical way to create an :class:`Option` instance is with the
925925
store this option's argument (default)
926926

927927
``"store_const"``
928-
store a constant value
928+
store a constant value, pre-set via :attr:`Option.const`
929929

930930
``"store_true"``
931931
store ``True``
@@ -937,7 +937,7 @@ The canonical way to create an :class:`Option` instance is with the
937937
append this option's argument to a list
938938

939939
``"append_const"``
940-
append a constant value to a list
940+
append a constant value to a list, pre-set via :attr:`Option.const`
< 44C1 code>941941

942942
``"count"``
943943
increment a counter by one

0 commit comments

Comments
 (0)
0