Skip to content

Commit 4f15173

Browse files
authored
Merge branch 'main' into compiler_refactor
2 parents e44b087 + 9fbfa42 commit 4f15173

File tree

191 files changed

+1482
-10835
lines changed

Some content is hidden

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

191 files changed

+1482
-10835
lines changed

.github/workflows/project-updater.yml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
- { project: 2, label: "release-blocker, deferred-blocker" }
1919
- { project: 3, label: expert-subinterpreters }
2020
- { project: 29, label: expert-asyncio }
21+
- { project: 32, label: sprint }
2122

2223
steps:
2324
- uses: actions/[email protected]

Doc/README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ If you'd like to create the virtual environment in a different location,
4040
you can specify it using the ``VENVDIR`` variable.
4141

4242
You can also skip creating the virtual environment altogether, in which case
43-
the Makefile will look for instances of ``sphinxbuild`` and ``blurb``
43+
the Makefile will look for instances of ``sphinx-build`` and ``blurb``
4444
installed on your process ``PATH`` (configurable with the ``SPHINXBUILD`` and
4545
``BLURB`` variables).
4646

Doc/c-api/exceptions.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ For convenience, some of these functions will always return a
189189
.. c:function:: PyObject* PyErr_SetFromWindowsErr(int ierr)
190190
191191
This is a convenience function to raise :exc:`WindowsError`. If called with
192-
*ierr* of :c:data:`0`, the error code returned by a call to :c:func:`GetLastError`
192+
*ierr* of ``0``, the error code returned by a call to :c:func:`GetLastError`
193193
is used instead. It calls the Win32 function :c:func:`FormatMessage` to retrieve
194194
the Windows description of error code given by *ierr* or :c:func:`GetLastError`,
195195
then it constructs a tuple object whose first item is the *ierr* value and whose

Doc/c-api/init_config.rst

+18
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,24 @@ PyConfig
828828
829829
Default: ``0``.
830830
831+
.. c:member:: int int_max_str_digits
832+
833+
Configures the :ref:`integer string conversion length limitation
834+
<int_max_str_digits>`. An initial value of ``-1`` means the value will
835+
be taken from the command line or environment or otherwise default to
836+
4300 (:data:`sys.int_info.default_max_str_digits`). A value of ``0``
837+
disables the limitation. Values greater than zero but less than 640
838+
(:data:`sys.int_info.str_digits_check_threshold`) are unsupported and
839+
will produce an error.
840+
841+
Configured by the :option:`-X int_max_str_digits <-X>` command line
842+
flag or the :envvar:`PYTHONINTMAXSTRDIGITS` environment varable.
843+
844+
Default: ``-1`` in Python mode. 4300
845+
(:data:`sys.int_info.default_max_str_digits`) in isolated mode.
846+
847+
.. versionadded:: 3.12
848+
831849
.. c:member:: int isolated
832850
833851
If greater than ``0``, enable isolated mode:

Doc/conf.py

+15
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,18 @@
249249
# bpo-40204: Disable warnings on Sphinx 2 syntax of the C domain since the
250250
# documentation is built with -W (warnings treated as errors).
251251
c_warn_on_allowed_pre_v3 = False
252+
253+
# Fix '!' not working with C domain when pre_v3 is enabled
254+
import sphinx
255+
256+
if sphinx.version_info[:2] < (5, 3):
257+
from sphinx.domains.c import CXRefRole
258+
259+
original_run = CXRefRole.run
260+
261+
def new_run(self):
262+
if self.disabled:
263+
return super(CXRefRole, self).run()
264+
return original_run(self)
265+
266+
CXRefRole.run = new_run

Doc/faq/programming.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ Is it possible to write obfuscated one-liners in Python?
735735
--------------------------------------------------------
736736

737737
Yes. Usually this is done by nesting :keyword:`lambda` within
738-
:keyword:`!lambda`. See the following three examples, due to Ulf Bartelt::
738+
:keyword:`!lambda`. See the following three examples, slightly adapted from Ulf Bartelt::
739739

740740
from functools import reduce
741741

@@ -748,7 +748,7 @@ Yes. Usually this is done by nesting :keyword:`lambda` within
748748
f(x,f), range(10))))
749749

750750
# Mandelbrot set
751-
print((lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+y,map(lambda y,
751+
print((lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+'\n'+y,map(lambda y,
752752
Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,Sy=Sy,L=lambda yc,Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,i=IM,
753753
Sx=Sx,Sy=Sy:reduce(lambda x,y:x+y,map(lambda x,xc=Ru,yc=yc,Ru=Ru,Ro=Ro,
754754
i=i,Sx=Sx,F=lambda xc,yc,x,y,k,f=lambda xc,yc,x,y,k,f:(k<=0)or (x*x+y*y

Doc/glossary.rst

+9-2
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,17 @@ Glossary
136136
:exc:`StopAsyncIteration` exception. Introduced by :pep:`492`.
137137

138138
attribute
139-
A value associated with an object which is referenced by name using
140-
dotted expressions. For example, if an object *o* has an attribute
139+
A value associated with an object which is usually referenced by name
140+
using dotted expressions.
141+
For example, if an object *o* has an attribute
141142
*a* it would be referenced as *o.a*.
142143

144+
It is possible to give an object an attribute whose name is not an
145+
identifier as defined by :ref:`identifiers`, for example using
146+
:func:`setattr`, if the object allows it.
147+
Such an attribute will not be accessible using a dotted expression,
148+
and would instead need to be retrieved with :func:`getattr`.
149+
143150
awaitable
144151
An object that can be used in an :keyword:`await` expression. Can be
145152
a :term:`coroutine` or an object with an :meth:`__await__` method.

Doc/howto/logging-cookbook.rst

+76
Original file line numberDiff line numberDiff line change
@@ -3428,6 +3428,82 @@ the above handler, you'd pass structured data using something like this::
34283428
i = 1
34293429
logger.debug('Message %d', i, extra=extra)
34303430

3431+
How to treat a logger like an output stream
3432+
-------------------------------------------
3433+
3434+
Sometimes, you need to interface to a third-party API which expects a file-like
3435+
object to write to, but you want to direct the API's output to a logger. You
3436+
can do this using a class which wraps a logger with a file-like API.
3437+
Here's a short script illustrating such a class:
3438+
3439+
.. code-block:: python
3440+
3441+
import logging
3442+
3443+
class LoggerWriter:
3444+
def __init__(self, logger, level):
3445+
self.logger = logger
3446+
self.level = level
3447+
3448+
def write(self, message):
3449+
if message != '\n': # avoid printing bare newlines, if you like
3450+
self.logger.log(self.level, message)
3451+
3452+
def flush(self):
3453+
# doesn't actually do anything, but might be expected of a file-like
3454+
# object - so optional depending on your situation
3455+
pass
3456+
3457+
def close(self):
3458+
# doesn't actually do anything, but might be expected of a file-like
3459+
# object - so optional depending on your situation. You might want
3460+
# to set a flag so that later calls to write raise an exception
3461+
pass
3462+
3463+
def main():
3464+
logging.basicConfig(level=logging.DEBUG)
3465+
logger = logging.getLogger('demo')
3466+
info_fp = LoggerWriter(logger, logging.INFO)
3467+
debug_fp = LoggerWriter(logger, logging.DEBUG)
3468+
print('An INFO message', file=info_fp)
3469+
print('A DEBUG message', file=debug_fp)
3470+
3471+
if __name__ == "__main__":
3472+
main()
3473+
3474+
When this script is run, it prints
3475+
3476+
.. code-block:: text
3477+
3478+
INFO:demo:An INFO message
3479+
DEBUG:demo:A DEBUG message
3480+
3481+
You could also use ``LoggerWriter`` to redirect ``sys.stdout`` and
3482+
``sys.stderr`` by doing something like this:
3483+
3484+
.. code-block:: python
3485+
3486+
import sys
3487+
3488+
sys.stdout = LoggerWriter(logger, logging.INFO)
3489+
sys.stderr = LoggerWriter(logger, logging.WARNING)
3490+
3491+
You should do this *after* configuring logging for your needs. In the above
3492+
example, the :func:`~logging.basicConfig` call does this (using the
3493+
``sys.stderr`` value *before* it is overwritten by a ``LoggerWriter``
3494+
instance). Then, you'd get this kind of result:
3495+
3496+
.. code-block:: pycon
3497+
3498+
>>> print('Foo')
3499+
INFO:demo:Foo
3500+
>>> print('Bar', file=sys.stderr)
3501+
WARNING:demo:Bar
3502+
>>>
3503+
3504+
Of course, these above examples show output according to the format used by
3505+
:func:`~logging.basicConfig`, but you can use a different formatter when you
3506+
configure logging.
34313507

34323508
.. patterns-to-avoid:
34333509

Doc/howto/regex.rst

+1-5
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,7 @@ containing information about the match: where it starts and ends, the substring
378378
it matched, and more.
379379

380380
You can learn about this by interactively experimenting with the :mod:`re`
381-
module. If you have :mod:`tkinter` available, you may also want to look at
382-
:source:`Tools/demo/redemo.py`, a demonstration program included with the
383-
Python distribution. It allows you to enter REs and strings, and displays
384-
whether the RE matches or fails. :file:`redemo.py` can be quite useful when
385-
trying to debug a complicated RE.
381+
module.
386382

387383
This HOWTO uses the standard Python interpreter for its examples. First, run the
388384
Python interpreter, import the :mod:`re` module, and compile a RE::

Doc/library/ast.rst

+16-8
Original file line numberDiff line numberDiff line change
@@ -1991,20 +1991,28 @@ and classes for traversing abstract syntax trees:
19911991

19921992
.. function:: literal_eval(node_or_string)
19931993

1994-
Safely evaluate an expression node or a string containing a Python literal or
1994+
Evaluate an expression node or a string containing only a Python literal or
19951995
container display. The string or node provided may only consist of the
19961996
following Python literal structures: strings, bytes, numbers, tuples, lists,
19971997
dicts, sets, booleans, ``None`` and ``Ellipsis``.
19981998

1999-
This can be used for safely evaluating strings containing Python values from
2000-
untrusted sources without the need to parse the values oneself. It is not
2001-
capable of evaluating arbitrarily complex expressions, for example involving
2002-
operators or indexing.
1999+
This can be used for evaluating strings containing Python values without the
2000+
need to parse the values oneself. It is not capable of evaluating
2001+
arbitrarily complex expressions, for example involving operators or
2002+
indexing.
2003+
2004+
This function had been documented as "safe" in the past without defining
2005+
what that meant. That was misleading. This is specifically designed not to
2006+
execute Python code, unlike the more general :func:`eval`. There is no
2007+
namespace, no name lookups, or ability to call out. But it is not free from
2008+
attack: A relatively small input can lead to memory exhaustion or to C stack
2009+
exhaustion, crashing the process. There is also the possibility for
2010+
excessive CPU consumption denial of service on some inputs. Calling it on
2011+
untrusted data is thus not recommended.
20032012

20042013
.. warning::
2005-
It is possible to crash the Python interpreter with a
2006-
sufficiently large/complex string due to stack depth limitations
2007-
in Python's AST compiler.
2014+
It is possible to crash the Python interpreter due to stack depth
2015+
limitations in Python's AST compiler.
20082016

20092017
It can raise :exc:`ValueError`, :exc:`TypeError`, :exc:`SyntaxError`,
20102018
:exc:`MemoryError` and :exc:`RecursionError` depending on the malformed

Doc/library/asyncio-eventloop.rst

+6-3
Original file line numberDiff line numberDiff line change
@@ -1632,9 +1632,12 @@ on Unix and :class:`ProactorEventLoop` on Windows.
16321632
import asyncio
16331633
import selectors
16341634

1635-
selector = selectors.SelectSelector()
1636-
loop = asyncio.SelectorEventLoop(selector)
1637-
asyncio.set_event_loop(loop)
1635+
class MyPolicy(asyncio.DefaultEventLoopPolicy):
1636+
def new_event_loop(self):
1637+
selector = selectors.SelectSelector()
1638+
return asyncio.SelectorEventLoop(selector)
1639+
1640+
asyncio.set_event_loop_policy(MyPolicy())
16381641

16391642

16401643
.. availability:: Unix, Windows.

Doc/library/asyncio-future.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ Future Object
8585

8686
Future is an :term:`awaitable` object. Coroutines can await on
8787
Future objects until they either have a result or an exception
88-
set, or until they are cancelled.
88+
set, or until they are cancelled. A Future can be awaited multiple
89+
times and the result is same.
8990

9091
Typically Futures are used to enable low-level
9192
callback-based code (e.g. in protocols implemented using asyncio

0 commit comments

Comments
 (0)