Skip to content

Commit

Permalink
Merge branch 'main' into pythongh-81079-glob-case-sensitive-arg-2
Browse files Browse the repository at this point in the history
  • Loading branch information
barneygale authored Mar 22, 2023
2 parents b0d836e + 713df2c commit e386a54
Show file tree
Hide file tree
Showing 182 changed files with 4,239 additions and 1,964 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ jobs:
run: make smelly
- name: Check limited ABI symbols
run: make check-limited-abi
- name: Check for unsupported C global variables
if: github.event_name == 'pull_request' # $GITHUB_EVENT_NAME
run: make check-c-globals

build_win32:
name: 'Windows (x86)'
Expand Down
6 changes: 6 additions & 0 deletions Doc/c-api/exceptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ Printing and clearing
An exception must be set when calling this function.
.. c:function: void PyErr_DisplayException(PyObject *exc)
Print the standard traceback display of ``exc`` to ``sys.stderr``, including
chained exceptions and notes.
.. versionadded:: 3.12
Raising exceptions
==================
Expand Down
33 changes: 33 additions & 0 deletions Doc/c-api/gcsupport.rst
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,36 @@ garbage collection runs.
Returns the current state, 0 for disabled and 1 for enabled.
.. versionadded:: 3.10
Querying Garbage Collector State
--------------------------------
The C-API provides the following interface for querying information about
the garbage collector.
.. c:function:: void PyUnstable_GC_VisitObjects(gcvisitobjects_t callback, void *arg)
Run supplied *callback* on all live GC-capable objects. *arg* is passed through to
all invocations of *callback*.
.. warning::
If new objects are (de)allocated by the callback it is undefined if they
will be visited.
Garbage collection is disabled during operation. Explicitly running a collection
in the callback may lead to undefined behaviour e.g. visiting the same objects
multiple times or not at all.
.. versionadded:: 3.12
.. c:type:: int (*gcvisitobjects_t)(PyObject *object, void *arg)
Type of the visitor function to be passed to :c:func:`PyUnstable_GC_VisitObjects`.
*arg* is the same as the *arg* passed to ``PyUnstable_GC_VisitObjects``.
Return ``0`` to continue iteration, return ``1`` to stop iteration. Other return
values are reserved for now so behavior on returning anything else is undefined.
.. versionadded:: 3.12
2 changes: 1 addition & 1 deletion Doc/c-api/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ Process-wide parameters
program name is ``'/usr/local/bin/python'``, the prefix is ``'/usr/local'``. The
returned string points into static storage; the caller should not modify its
value. This corresponds to the :makevar:`prefix` variable in the top-level
:file:`Makefile` and the ``--prefix`` argument to the :program:`configure`
:file:`Makefile` and the :option:`--prefix` argument to the :program:`configure`
script at build time. The value is available to Python code as ``sys.prefix``.
It is only useful on Unix. See also the next function.

Expand Down
10 changes: 5 additions & 5 deletions Doc/c-api/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,19 @@ used by extension writers. Structure member names do not have a reserved prefix.

The header files are typically installed with Python. On Unix, these are
located in the directories :file:`{prefix}/include/pythonversion/` and
:file:`{exec_prefix}/include/pythonversion/`, where :envvar:`prefix` and
:envvar:`exec_prefix` are defined by the corresponding parameters to Python's
:file:`{exec_prefix}/include/pythonversion/`, where :option:`prefix <--prefix>` and
:option:`exec_prefix <--exec-prefix>` are defined by the corresponding parameters to Python's
:program:`configure` script and *version* is
``'%d.%d' % sys.version_info[:2]``. On Windows, the headers are installed
in :file:`{prefix}/include`, where :envvar:`prefix` is the installation
in :file:`{prefix}/include`, where ``prefix`` is the installation
directory specified to the installer.

To include the headers, place both directories (if different) on your compiler's
search path for includes. Do *not* place the parent directories on the search
path and then use ``#include <pythonX.Y/Python.h>``; this will break on
multi-platform builds since the platform independent headers under
:envvar:`prefix` include the platform specific headers from
:envvar:`exec_prefix`.
:option:`prefix <--prefix>` include the platform specific headers from
:option:`exec_prefix <--exec-prefix>`.

C++ users should note that although the API is defined entirely using C, the
header files properly declare the entry points to be ``extern "C"``. As a result,
Expand Down
9 changes: 9 additions & 0 deletions Doc/c-api/object.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ Object Protocol
If *o1* and *o2* are the same object, :c:func:`PyObject_RichCompareBool`
will always return ``1`` for :const:`Py_EQ` and ``0`` for :const:`Py_NE`.
.. c:function:: PyObject* PyObject_Format(PyObject *obj, PyObject *format_spec)
Format *obj* using *format_spec*. This is equivalent to the Python
expression ``format(obj, format_spec)``.
*format_spec* may be ``NULL``. In this case the call is equivalent
to ``format(obj)``.
Returns the formatted string on success, ``NULL`` on failure.
.. c:function:: PyObject* PyObject_Repr(PyObject *o)
.. index:: builtin: repr
Expand Down
1 change: 1 addition & 0 deletions Doc/data/stable_abi.dat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Doc/library/__main__.rst
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ one mentioned below are preferred.

See :mod:`venv` for an example of a package with a minimal ``__main__.py``
in the standard library. It doesn't contain a ``if __name__ == '__main__'``
block. You can invoke it with ``python3 -m venv [directory]``.
block. You can invoke it with ``python -m venv [directory]``.

See :mod:`runpy` for more details on the :option:`-m` flag to the
interpreter executable.
Expand Down
7 changes: 4 additions & 3 deletions Doc/library/asyncio-task.rst
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,10 @@ Waiting Primitives
.. versionchanged:: 3.11
Passing coroutine objects to ``wait()`` directly is forbidden.

.. versionchanged:: 3.12
Added support for generators yielding tasks.


.. function:: as_completed(aws, *, timeout=None)

Run :ref:`awaitable objects <asyncio-awaitables>` in the *aws*
Expand All @@ -814,9 +818,6 @@ Waiting Primitives
Raises :exc:`TimeoutError` if the timeout occurs before
all Futures are done.

.. versionchanged:: 3.10
Removed the *loop* parameter.

Example::

for coro in as_completed(aws):
Expand Down
22 changes: 10 additions & 12 deletions Doc/library/email.utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,17 @@ module:

.. function:: localtime(dt=None)

Return local time as an aware datetime object. If called without
arguments, return current time. Otherwise *dt* argument should be a
:class:`~datetime.datetime` instance, and it is converted to the local time
zone according to the system time zone database. If *dt* is naive (that
is, ``dt.tzinfo`` is ``None``), it is assumed to be in local time. In this
case, a positive or zero value for *isdst* causes ``localtime`` to presume
initially that summer time (for example, Daylight Saving Time) is or is not
(respectively) in effect for the specified time. A negative value for
*isdst* causes the ``localtime`` to attempt to divine whether summer time
is in effect for the specified time.

.. versionadded:: 3.3
Return local time as an aware datetime object. If called without
arguments, return current time. Otherwise *dt* argument should be a
:class:`~datetime.datetime` instance, and it is converted to the local time
zone according to the system time zone database. If *dt* is naive (that
is, ``dt.tzinfo`` is ``None``), it is assumed to be in local time. The
*isdst* parameter is ignored.

.. versionadded:: 3.3

.. deprecated-removed:: 3.12 3.14
The *isdst* parameter.

.. function:: make_msgid(idstring=None, domain=None)

Expand Down
2 changes: 1 addition & 1 deletion Doc/library/importlib.metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ something into it:

.. code-block:: shell-session
$ python3 -m venv example
$ python -m venv example
$ source example/bin/activate
(example) $ python -m pip install wheel
Expand Down
55 changes: 49 additions & 6 deletions Doc/library/itertools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ loops that truncate the stream.
if n < 1:
raise ValueError('n must be at least one')
it = iter(iterable)
while (batch := tuple(islice(it, n))):
while batch := tuple(islice(it, n)):
yield batch

.. versionadded:: 3.12
Expand Down Expand Up @@ -872,11 +872,23 @@ which incur interpreter overhead.
(x - 5) (x + 4) (x - 3) expands to: x³ -4x² -17x + 60
"""
# polynomial_from_roots([5, -4, 3]) --> [1, -4, -17, 60]
roots = list(map(operator.neg, roots))
return [
sum(map(math.prod, combinations(roots, k)))
for k in range(len(roots) + 1)
]
expansion = [1]
for r in roots:
expansion = convolve(expansion, (1, -r))
return list(expansion)

def polynomial_eval(coefficients, x):
"""Evaluate a polynomial at a specific value.

Computes with better numeric stability than Horner's method.
"""
# Evaluate x³ -4x² -17x + 60 at x = 2.5
# polynomial_eval([1, -4, -17, 60], x=2.5) --> 8.125
n = len(coefficients)
if n == 0:
return x * 0 # coerce zero to the type of x
powers = map(pow, repeat(x), reversed(range(n)))
return math.sumprod(coefficients, powers)

def iter_index(iterable, value, start=0):
"Return indices where a value occurs in a sequence or iterable."
Expand Down Expand Up @@ -1245,6 +1257,37 @@ which incur interpreter overhead.
>>> list(convolve(data, [1, -2, 1]))
[20, 0, -36, 24, -20, 20, -20, -4, 16]

>>> from fractions import Fraction
>>> from decimal import Decimal
>>> polynomial_eval([1, -4, -17, 60], x=2)
18
>>> x = 2; x**3 - 4*x**2 -17*x + 60
18
>>> polynomial_eval([1, -4, -17, 60], x=2.5)
8.125
>>> x = 2.5; x**3 - 4*x**2 -17*x + 60
8.125
>>> polynomial_eval([1, -4, -17, 60], x=Fraction(2, 3))
Fraction(1274, 27)
>>> x = Fraction(2, 3); x**3 - 4*x**2 -17*x + 60
Fraction(1274, 27)
>>> polynomial_eval([1, -4, -17, 60], x=Decimal('1.75'))
Decimal('23.359375')
>>> x = Decimal('1.75'); x**3 - 4*x**2 -17*x + 60
Decimal('23.359375')
>>> polynomial_eval([], 2)
0
>>> polynomial_eval([], 2.5)
0.0
>>> polynomial_eval([], Fraction(2, 3))
Fraction(0, 1)
>>> polynomial_eval([], Decimal('1.75'))
Decimal('0.00')
>>> polynomial_eval([11], 7) == 11
True
>>> polynomial_eval([11, 2], 7) == 11 * 7 + 2
True

>>> polynomial_from_roots([5, -4, 3])
[1, -4, -17, 60]
>>> factored = lambda x: (x - 5) * (x + 4) * (x - 3)
Expand Down
Loading

0 comments on commit e386a54

Please sign in to comment.