Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into pythongh-115605-qsbr
Browse files Browse the repository at this point in the history
  • Loading branch information
corona10 committed Feb 28, 2024
2 parents e7f3683 + 75c6c05 commit 0eb3657
Show file tree
Hide file tree
Showing 186 changed files with 9,887 additions and 1,866 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Programs/test_frozenmain.h generated
Python/Python-ast.c generated
Python/executor_cases.c.h generated
Python/generated_cases.c.h generated
Python/tier2_redundancy_eliminator_cases.c.h generated
Python/optimizer_cases.c.h generated
Python/opcode_targets.h generated
Python/stdlib_module_names.h generated
Tools/peg_generator/pegen/grammar_parser.py generated
Expand Down
6 changes: 5 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Python/ast_opt.c @isidentical
Python/bytecodes.c @markshannon @gvanrossum
Python/optimizer*.c @markshannon @gvanrossum
Python/optimizer_analysis.c @Fidget-Spinner
Python/tier2_redundancy_eliminator_bytecodes.c @Fidget-Spinner
Python/optimizer_bytecodes.c @Fidget-Spinner
Lib/test/test_patma.py @brandtbucher
Lib/test/test_type_*.py @JelleZijlstra
Lib/test/test_capi/test_misc.py @markshannon @gvanrossum
Expand Down Expand Up @@ -249,3 +249,7 @@ Lib/test/test_interpreters/ @ericsnowcurrently
# SBOM
/Misc/sbom.spdx.json @sethmlarson
/Tools/build/generate_sbom.py @sethmlarson

# Config Parser
Lib/configparser.py @jaraco
Lib/test/test_configparser.py @jaraco
4 changes: 2 additions & 2 deletions .github/workflows/jit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ on:
- '**jit**'
- 'Python/bytecodes.c'
- 'Python/optimizer*.c'
- 'Python/tier2_redundancy_eliminator_bytecodes.c'
- 'Python/optimizer_bytecodes.c'
push:
paths:
- '**jit**'
- 'Python/bytecodes.c'
- 'Python/optimizer*.c'
- 'Python/tier2_redundancy_eliminator_bytecodes.c'
- 'Python/optimizer_bytecodes.c'
workflow_dispatch:

concurrency:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/reusable-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
HOMEBREW_NO_ANALYTICS: 1
HOMEBREW_NO_AUTO_UPDATE: 1
HOMEBREW_NO_INSTALL_CLEANUP: 1
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1
PYTHONSTRICTEXTENSIONBUILD: 1
strategy:
fail-fast: false
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Lib/test/data/*
/_bootstrap_python
/Makefile
/Makefile.pre
iOS/Resources/Info.plist
Mac/Makefile
Mac/PythonLauncher/Info.plist
Mac/PythonLauncher/Makefile
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 @@ -105,7 +105,7 @@ Printing and clearing
parameters help format the warning message; they have the same meaning and
values as in :c:func:`PyUnicode_FromFormat`.
``PyErr_WriteUnraisable(obj)`` is roughtly equivalent to
``PyErr_FormatUnraisable("Exception ignored in: %R, obj)``.
``PyErr_FormatUnraisable("Exception ignored in: %R", obj)``.
If *format* is ``NULL``, only the traceback is printed.
.. versionadded:: 3.13
Expand Down
2 changes: 2 additions & 0 deletions Doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,13 @@
('c:func', 'dlopen'),
('c:func', 'exec'),
('c:func', 'fcntl'),
('c:func', 'flock'),
('c:func', 'fork'),
('c:func', 'free'),
('c:func', 'gettimeofday'),
('c:func', 'gmtime'),
('c:func', 'grantpt'),
('c:func', 'ioctl'),
('c:func', 'localeconv'),
('c:func', 'localtime'),
('c:func', 'main'),
Expand Down
1 change: 0 additions & 1 deletion Doc/library/array.rst
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,3 @@ Examples::

`NumPy <https://numpy.org/>`_
The NumPy package defines another array type.

25 changes: 14 additions & 11 deletions Doc/library/ast.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,15 @@ Node classes
For example, to create and populate an :class:`ast.UnaryOp` node, you could
use ::

node = ast.UnaryOp()
node.op = ast.USub()
node.operand = ast.Constant()
node.operand.value = 5
node.operand.lineno = 0
node.operand.col_offset = 0
node.lineno = 0
node.col_offset = 0

or the more compact ::

node = ast.UnaryOp(ast.USub(), ast.Constant(5, lineno=0, col_offset=0),
lineno=0, col_offset=0)

If a field that is optional in the grammar is omitted from the constructor,
it defaults to ``None``. If a list field is omitted, it defaults to the empty
list. If any other field is omitted, a :exc:`DeprecationWarning` is raised
and the AST node will not have this field. In Python 3.15, this condition will
raise an error.

.. versionchanged:: 3.8

Class :class:`ast.Constant` is now used for all constants.
Expand All @@ -140,6 +135,14 @@ Node classes
In the meantime, instantiating them will return an instance of
a different class.

.. deprecated-removed:: 3.13 3.15

Previous versions of Python allowed the creation of AST nodes that were missing
required fields. Similarly, AST node constructors allowed arbitrary keyword
arguments that were set as attributes of the AST node, even if they did not
match any of the fields of the AST node. This behavior is deprecated and will
be removed in Python 3.15.

.. note::
The descriptions of the specific node classes displayed here
were initially adapted from the fantastic `Green Tree
Expand Down
18 changes: 18 additions & 0 deletions Doc/library/base64.rst
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,24 @@ The modern interface provides:
.. versionadded:: 3.4


.. function:: z85encode(s)

Encode the :term:`bytes-like object` *s* using Z85 (as used in ZeroMQ)
and return the encoded :class:`bytes`. See `Z85 specification
<https://rfc.zeromq.org/spec/32/>`_ for more information.

.. versionadded:: 3.13


.. function:: z85decode(s)

Decode the Z85-encoded :term:`bytes-like object` or ASCII string *s* and
return the decoded :class:`bytes`. See `Z85 specification
<https://rfc.zeromq.org/spec/32/>`_ for more information.

.. versionadded:: 3.13


The legacy interface:

.. function:: decode(input, output)
Expand Down
4 changes: 0 additions & 4 deletions Doc/library/ctypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1117,10 +1117,6 @@ api::
>>> print(hex(version.value))
0x30c00a0

If the interpreter would have been started with :option:`-O`, the sample would
have printed ``c_long(1)``, or ``c_long(2)`` if :option:`-OO` would have been
specified.

An extended example which also demonstrates the use of pointers accesses the
:c:data:`PyImport_FrozenModules` pointer exported by Python.

Expand Down
41 changes: 26 additions & 15 deletions Doc/library/fcntl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

----------------

This module performs file control and I/O control on file descriptors. It is an
interface to the :c:func:`fcntl` and :c:func:`ioctl` Unix routines. For a
complete description of these calls, see :manpage:`fcntl(2)` and
:manpage:`ioctl(2)` Unix manual pages.
This module performs file and I/O control on file descriptors. It is an
interface to the :c:func:`fcntl` and :c:func:`ioctl` Unix routines.
See the :manpage:`fcntl(2)` and :manpage:`ioctl(2)` Unix manual pages
for full details.

.. availability:: Unix, not Emscripten, not WASI.

Expand Down Expand Up @@ -101,7 +101,7 @@ The module defines the following functions:
most likely to result in a segmentation violation or a more subtle data
corruption.

If the :c:func:`fcntl` fails, an :exc:`OSError` is raised.
If the :c:func:`fcntl` call fails, an :exc:`OSError` is raised.

.. audit-event:: fcntl.fcntl fd,cmd,arg fcntl.fcntl

Expand Down Expand Up @@ -139,7 +139,7 @@ The module defines the following functions:
buffer 1024 bytes long which is then passed to :func:`ioctl` and copied back
into the supplied buffer.

If the :c:func:`ioctl` fails, an :exc:`OSError` exception is raised.
If the :c:func:`ioctl` call fails, an :exc:`OSError` exception is raised.

An example::

Expand All @@ -164,7 +164,7 @@ The module defines the following functions:
:manpage:`flock(2)` for details. (On some systems, this function is emulated
using :c:func:`fcntl`.)

If the :c:func:`flock` fails, an :exc:`OSError` exception is raised.
If the :c:func:`flock` call fails, an :exc:`OSError` exception is raised.

.. audit-event:: fcntl.flock fd,operation fcntl.flock

Expand All @@ -176,17 +176,28 @@ The module defines the following functions:
method are accepted as well) of the file to lock or unlock, and *cmd*
is one of the following values:

* :const:`LOCK_UN` -- unlock
* :const:`LOCK_SH` -- acquire a shared lock
* :const:`LOCK_EX` -- acquire an exclusive lock
.. data:: LOCK_UN

When *cmd* is :const:`LOCK_SH` or :const:`LOCK_EX`, it can also be
bitwise ORed with :const:`LOCK_NB` to avoid blocking on lock acquisition.
If :const:`LOCK_NB` is used and the lock cannot be acquired, an
Release an existing lock.

.. data:: LOCK_SH

Acquire a shared lock.

.. data:: LOCK_EX

Acquire an exclusive lock.

.. data:: LOCK_NB

Bitwise OR with any of the other three ``LOCK_*`` constants to make
the request non-blocking.

If :const:`!LOCK_NB` is used and the lock cannot be acquired, an
:exc:`OSError` will be raised and the exception will have an *errno*
attribute set to :const:`EACCES` or :const:`EAGAIN` (depending on the
attribute set to :const:`~errno.EACCES` or :const:`~errno.EAGAIN` (depending on the
operating system; for portability, check for both values). On at least some
systems, :const:`LOCK_EX` can only be used if the file descriptor refers to a
systems, :const:`!LOCK_EX` can only be used if the file descriptor refers to a
file opened for writing.

*len* is the number of bytes to lock, *start* is the byte offset at
Expand Down
30 changes: 25 additions & 5 deletions Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,20 @@ are always available. They are listed here in alphabetical order.

.. function:: eval(expression, globals=None, locals=None)

The arguments are a string and optional globals and locals. If provided,
*globals* must be a dictionary. If provided, *locals* can be any mapping
object.
:param expression:
A Python expression.
:type expression: :class:`str` | :ref:`code object <code-objects>`

:param globals:
The global namespace (default: ``None``).
:type globals: :class:`dict` | ``None``

:param locals:
The local namespace (default: ``None``).
:type locals: :term:`mapping` | ``None``

:returns: The result of the evaluated expression.
:raises: Syntax errors are reported as exceptions.

The *expression* argument is parsed and evaluated as a Python expression
(technically speaking, a condition list) using the *globals* and *locals*
Expand All @@ -545,8 +556,7 @@ are always available. They are listed here in alphabetical order.
:term:`nested scopes <nested scope>` (non-locals) in the enclosing
environment.

The return value is the result of
the evaluated expression. Syntax errors are reported as exceptions. Example:
Example:

>>> x = 1
>>> eval('x+1')
Expand Down Expand Up @@ -1569,6 +1579,16 @@ are always available. They are listed here in alphabetical order.
If :func:`sys.displayhook` is not accessible, this function will raise
:exc:`RuntimeError`.

This class has a custom representation that can be evaluated::

class Person:
def __init__(self, name, age):
self.name = name
self.age = age

def __repr__(self):
return f"Person('{self.name}', {self.age})"


.. function:: reversed(seq)

Expand Down
74 changes: 41 additions & 33 deletions Doc/library/itertools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,14 @@ loops that truncate the stream.
else:
break

Note, the element that first fails the predicate condition is
consumed from the input iterator and there is no way to access it.
This could be an issue if an application wants to further consume the
input iterator after takewhile has been run to exhaustion. To work
around this problem, consider using `more-iterools before_and_after()
<https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.before_and_after>`_
instead.


.. function:: tee(iterable, n=2)

Expand Down Expand Up @@ -1004,32 +1012,6 @@ which incur interpreter overhead.
except exception:
pass

def before_and_after(predicate, it):
""" Variant of takewhile() that allows complete
access to the remainder of the iterator.

>>> it = iter('ABCdEfGhI')
>>> all_upper, remainder = before_and_after(str.isupper, it)
>>> ''.join(all_upper)
'ABC'
>>> ''.join(remainder) # takewhile() would lose the 'd'
'dEfGhI'

Note that the true iterator must be fully consumed
before the remainder iterator can generate valid results.
"""
it = iter(it)
transition = []

def true_iterator():
for elem in it:
if predicate(elem):
yield elem
else:
transition.append(elem)
return

return true_iterator(), chain(transition, it)


The following recipes have a more mathematical flavor:
Expand Down Expand Up @@ -1543,13 +1525,6 @@ The following recipes have a more mathematical flavor:
>>> list(odds)
[1, 3, 5, 7, 9]

>>> it = iter('ABCdEfGhI')
>>> all_upper, remainder = before_and_after(str.isupper, it)
>>> ''.join(all_upper)
'ABC'
>>> ''.join(remainder)
'dEfGhI'

>>> list(subslices('ABCD'))
['A', 'AB', 'ABC', 'ABCD', 'B', 'BC', 'BCD', 'C', 'CD', 'D']

Expand Down Expand Up @@ -1640,6 +1615,32 @@ The following recipes have a more mathematical flavor:
result.append(pool[-1-n])
return tuple(result)

def before_and_after(predicate, it):
""" Variant of takewhile() that allows complete
access to the remainder of the iterator.

>>> it = iter('ABCdEfGhI')
>>> all_upper, remainder = before_and_after(str.isupper, it)
>>> ''.join(all_upper)
'ABC'
>>> ''.join(remainder) # takewhile() would lose the 'd'
'dEfGhI'

Note that the true iterator must be fully consumed
before the remainder iterator can generate valid results.
"""
it = iter(it)
transition = []

def true_iterator():
for elem in it:
if predicate(elem):
yield elem
else:
transition.append(elem)
return

return true_iterator(), chain(transition, it)

.. doctest::
:hide:
Expand Down Expand Up @@ -1669,3 +1670,10 @@ The following recipes have a more mathematical flavor:
>>> combos = list(combinations(iterable, r))
>>> all(nth_combination(iterable, r, i) == comb for i, comb in enumerate(combos))
True

>>> it = iter('ABCdEfGhI')
>>> all_upper, remainder = before_and_after(str.isupper, it)
>>> ''.join(all_upper)
'ABC'
>>> ''.join(remainder)
'dEfGhI'
Loading

0 comments on commit 0eb3657

Please sign in to comment.