Skip to content

Commit

Permalink
Merge branch 'main' into compiler_refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
iritkatriel authored Oct 4, 2022
2 parents e44b087 + 9fbfa42 commit 4f15173
Show file tree
Hide file tree
Showing 191 changed files with 1,482 additions and 10,835 deletions.
1 change: 1 addition & 0 deletions .github/workflows/project-updater.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
- { project: 2, label: "release-blocker, deferred-blocker" }
- { project: 3, label: expert-subinterpreters }
- { project: 29, label: expert-asyncio }
- { project: 32, label: sprint }

steps:
- uses: actions/add-to-project@v0.1.0
Expand Down
2 changes: 1 addition & 1 deletion Doc/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ If you'd like to create the virtual environment in a different location,
you can specify it using the ``VENVDIR`` variable.

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

Expand Down
2 changes: 1 addition & 1 deletion Doc/c-api/exceptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ For convenience, some of these functions will always return a
.. c:function:: PyObject* PyErr_SetFromWindowsErr(int ierr)
This is a convenience function to raise :exc:`WindowsError`. If called with
*ierr* of :c:data:`0`, the error code returned by a call to :c:func:`GetLastError`
*ierr* of ``0``, the error code returned by a call to :c:func:`GetLastError`
is used instead. It calls the Win32 function :c:func:`FormatMessage` to retrieve
the Windows description of error code given by *ierr* or :c:func:`GetLastError`,
then it constructs a tuple object whose first item is the *ierr* value and whose
Expand Down
18 changes: 18 additions & 0 deletions Doc/c-api/init_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,24 @@ PyConfig
Default: ``0``.
.. c:member:: int int_max_str_digits
Configures the :ref:`integer string conversion length limitation
<int_max_str_digits>`. An initial value of ``-1`` means the value will
be taken from the command line or environment or otherwise default to
4300 (:data:`sys.int_info.default_max_str_digits`). A value of ``0``
disables the limitation. Values greater than zero but less than 640
(:data:`sys.int_info.str_digits_check_threshold`) are unsupported and
will produce an error.
Configured by the :option:`-X int_max_str_digits <-X>` command line
flag or the :envvar:`PYTHONINTMAXSTRDIGITS` environment varable.
Default: ``-1`` in Python mode. 4300
(:data:`sys.int_info.default_max_str_digits`) in isolated mode.
.. versionadded:: 3.12
.. c:member:: int isolated
If greater than ``0``, enable isolated mode:
Expand Down
15 changes: 15 additions & 0 deletions Doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,18 @@
# bpo-40204: Disable warnings on Sphinx 2 syntax of the C domain since the
# documentation is built with -W (warnings treated as errors).
c_warn_on_allowed_pre_v3 = False

# Fix '!' not working with C domain when pre_v3 is enabled
import sphinx

if sphinx.version_info[:2] < (5, 3):
from sphinx.domains.c import CXRefRole

original_run = CXRefRole.run

def new_run(self):
if self.disabled:
return super(CXRefRole, self).run()
return original_run(self)

CXRefRole.run = new_run
4 changes: 2 additions & 2 deletions Doc/faq/programming.rst
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ Is it possible to write obfuscated one-liners in Python?
--------------------------------------------------------

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

from functools import reduce

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

# Mandelbrot set
print((lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+y,map(lambda y,
print((lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+'\n'+y,map(lambda y,
Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,Sy=Sy,L=lambda yc,Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,i=IM,
Sx=Sx,Sy=Sy:reduce(lambda x,y:x+y,map(lambda x,xc=Ru,yc=yc,Ru=Ru,Ro=Ro,
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
Expand Down
11 changes: 9 additions & 2 deletions Doc/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,17 @@ Glossary
:exc:`StopAsyncIteration` exception. Introduced by :pep:`492`.

attribute
A value associated with an object which is referenced by name using
dotted expressions. For example, if an object *o* has an attribute
A value associated with an object which is usually referenced by name
using dotted expressions.
For example, if an object *o* has an attribute
*a* it would be referenced as *o.a*.

It is possible to give an object an attribute whose name is not an
identifier as defined by :ref:`identifiers`, for example using
:func:`setattr`, if the object allows it.
Such an attribute will not be accessible using a dotted expression,
and would instead need to be retrieved with :func:`getattr`.

awaitable
An object that can be used in an :keyword:`await` expression. Can be
a :term:`coroutine` or an object with an :meth:`__await__` method.
Expand Down
76 changes: 76 additions & 0 deletions Doc/howto/logging-cookbook.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3428,6 +3428,82 @@ the above handler, you'd pass structured data using something like this::
i = 1
logger.debug('Message %d', i, extra=extra)

How to treat a logger like an output stream
-------------------------------------------

Sometimes, you need to interface to a third-party API which expects a file-like
object to write to, but you want to direct the API's output to a logger. You
can do this using a class which wraps a logger with a file-like API.
Here's a short script illustrating such a class:

.. code-block:: python
import logging
class LoggerWriter:
def __init__(self, logger, level):
self.logger = logger
self.level = level
def write(self, message):
if message != '\n': # avoid printing bare newlines, if you like
self.logger.log(self.level, message)
def flush(self):
# doesn't actually do anything, but might be expected of a file-like
# object - so optional depending on your situation
pass
def close(self):
# doesn't actually do anything, but might be expected of a file-like
# object - so optional depending on your situation. You might want
# to set a flag so that later calls to write raise an exception
pass
def main():
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('demo')
info_fp = LoggerWriter(logger, logging.INFO)
debug_fp = LoggerWriter(logger, logging.DEBUG)
print('An INFO message', file=info_fp)
print('A DEBUG message', file=debug_fp)
if __name__ == "__main__":
main()
When this script is run, it prints

.. code-block:: text
INFO:demo:An INFO message
DEBUG:demo:A DEBUG message
You could also use ``LoggerWriter`` to redirect ``sys.stdout`` and
``sys.stderr`` by doing something like this:

.. code-block:: python
import sys
sys.stdout = LoggerWriter(logger, logging.INFO)
sys.stderr = LoggerWriter(logger, logging.WARNING)
You should do this *after* configuring logging for your needs. In the above
example, the :func:`~logging.basicConfig` call does this (using the
``sys.stderr`` value *before* it is overwritten by a ``LoggerWriter``
instance). Then, you'd get this kind of result:

.. code-block:: pycon
>>> print('Foo')
INFO:demo:Foo
>>> print('Bar', file=sys.stderr)
WARNING:demo:Bar
>>>
Of course, these above examples show output according to the format used by
:func:`~logging.basicConfig`, but you can use a different formatter when you
configure logging.

.. patterns-to-avoid:
Expand Down
6 changes: 1 addition & 5 deletions Doc/howto/regex.rst
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,7 @@ containing information about the match: where it starts and ends, the substring
it matched, and more.

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

This HOWTO uses the standard Python interpreter for its examples. First, run the
Python interpreter, import the :mod:`re` module, and compile a RE::
Expand Down
24 changes: 16 additions & 8 deletions Doc/library/ast.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1991,20 +1991,28 @@ and classes for traversing abstract syntax trees:

.. function:: literal_eval(node_or_string)

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

This can be used for safely evaluating strings containing Python values from
untrusted sources without the need to parse the values oneself. It is not
capable of evaluating arbitrarily complex expressions, for example involving
operators or indexing.
This can be used for evaluating strings containing Python values without the
need to parse the values oneself. It is not capable of evaluating
arbitrarily complex expressions, for example involving operators or
indexing.

This function had been documented as "safe" in the past without defining
what that meant. That was misleading. This is specifically designed not to
execute Python code, unlike the more general :func:`eval`. There is no
namespace, no name lookups, or ability to call out. But it is not free from
attack: A relatively small input can lead to memory exhaustion or to C stack
exhaustion, crashing the process. There is also the possibility for
excessive CPU consumption denial of service on some inputs. Calling it on
untrusted data is thus not recommended.

.. warning::
It is possible to crash the Python interpreter with a
sufficiently large/complex string due to stack depth limitations
in Python's AST compiler.
It is possible to crash the Python interpreter due to stack depth
limitations in Python's AST compiler.

It can raise :exc:`ValueError`, :exc:`TypeError`, :exc:`SyntaxError`,
:exc:`MemoryError` and :exc:`RecursionError` depending on the malformed
Expand Down
9 changes: 6 additions & 3 deletions Doc/library/asyncio-eventloop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1632,9 +1632,12 @@ on Unix and :class:`ProactorEventLoop` on Windows.
import asyncio
import selectors

selector = selectors.SelectSelector()
loop = asyncio.SelectorEventLoop(selector)
asyncio.set_event_loop(loop)
class MyPolicy(asyncio.DefaultEventLoopPolicy):
def new_event_loop(self):
selector = selectors.SelectSelector()
return asyncio.SelectorEventLoop(selector)

asyncio.set_event_loop_policy(MyPolicy())


.. availability:: Unix, Windows.
Expand Down
3 changes: 2 additions & 1 deletion Doc/library/asyncio-future.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ Future Object

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

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

0 comments on commit 4f15173

Please sign in to comment.