Skip to content

Commit 267b660

Browse files
Merge branch 'python:main' into main
2 parents 44f67ab + 3ba7743 commit 267b660

Some content is hidden

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

61 files changed

+1134
-836
lines changed

.github/workflows/build.yml

+13-3
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,25 @@ jobs:
154154
needs: check_source
155155
if: needs.check_source.outputs.run_tests == 'true'
156156
env:
157+
HOMEBREW_NO_ANALYTICS: 1
158+
HOMEBREW_NO_AUTO_UPDATE: 1
159+
HOMEBREW_NO_INSTALL_CLEANUP: 1
157160
PYTHONSTRICTEXTENSIONBUILD: 1
158161
steps:
159162
- uses: actions/checkout@v3
160-
- name: Prepare homebrew environment variables
163+
- name: Install Homebrew dependencies
164+
run: brew install pkg-config [email protected] xz gdbm tcl-tk
165+
- name: Prepare Homebrew environment variables
161166
run: |
162-
echo "LDFLAGS=-L$(brew --prefix tcl-tk)/lib" >> $GITHUB_ENV
167+
echo "CFLAGS=-I$(brew --prefix gdbm)/include -I$(brew --prefix xz)/include" >> $GITHUB_ENV
168+
echo "LDFLAGS=-L$(brew --prefix gdbm)/lib -I$(brew --prefix xz)/lib" >> $GITHUB_ENV
163169
echo "PKG_CONFIG_PATH=$(brew --prefix [email protected])/lib/pkgconfig:$(brew --prefix tcl-tk)/lib/pkgconfig" >> $GITHUB_ENV
164170
- name: Configure CPython
165-
run: ./configure --with-pydebug --prefix=/opt/python-dev
171+
run: |
172+
./configure \
173+
--with-pydebug \
174+
--prefix=/opt/python-dev \
175+
--with-openssl="$(brew --prefix [email protected])"
166176
- name: Build CPython
167177
run: make -j4
168178
- name: Display build info

Doc/c-api/exceptions.rst

+23-22
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,9 @@ Querying the error indicator
438438
439439
.. c:function:: void PyErr_Fetch(PyObject **ptype, PyObject **pvalue, PyObject **ptraceback)
440440
441-
As of 3.12, this function is deprecated. Use :c:func:`PyErr_GetRaisedException` instead.
441+
.. deprecated:: 3.12
442+
443+
Use :c:func:`PyErr_GetRaisedException` instead.
442444
443445
Retrieve the error indicator into three variables whose addresses are passed.
444446
If the error indicator is not set, set all three variables to ``NULL``. If it is
@@ -447,8 +449,10 @@ Querying the error indicator
447449
448450
.. note::
449451
450-
This function is normally only used by code that needs to catch exceptions or
451-
by code that needs to save and restore the error indicator temporarily, e.g.::
452+
This function is normally only used by legacy code that needs to catch
453+
exceptions or save and restore the error indicator temporarily.
454+
455+
For example::
452456
453457
{
454458
PyObject *type, *value, *traceback;
@@ -459,15 +463,17 @@ Querying the error indicator
459463
PyErr_Restore(type, value, traceback);
460464
}
461465
462-
.. deprecated:: 3.12
463-
464466
465467
.. c:function:: void PyErr_Restore(PyObject *type, PyObject *value, PyObject *traceback)
466468
467-
As of 3.12, this function is deprecated. Use :c:func:`PyErr_SetRaisedException` instead.
469+
.. deprecated:: 3.12
470+
471+
Use :c:func:`PyErr_SetRaisedException` instead.
468472
469-
Set the error indicator from the three objects. If the error indicator is
470-
already set, it is cleared first. If the objects are ``NULL``, the error
473+
Set the error indicator from the three objects,
474+
*type*, *value*, and *traceback*,
475+
clearing the existing exception if one is set.
476+
If the objects are ``NULL``, the error
471477
indicator is cleared. Do not pass a ``NULL`` type and non-``NULL`` value or
472478
traceback. The exception type should be a class. Do not pass an invalid
473479
exception type or value. (Violating these rules will cause subtle problems
@@ -478,18 +484,17 @@ Querying the error indicator
478484
479485
.. note::
480486
481-
This function is normally only used by code that needs to save and restore the
482-
error indicator temporarily. Use :c:func:`PyErr_Fetch` to save the current
483-
error indicator.
484-
485-
.. deprecated:: 3.12
487+
This function is normally only used by legacy code that needs to
488+
save and restore the error indicator temporarily.
489+
Use :c:func:`PyErr_Fetch` to save the current error indicator.
486490
487491
488492
.. c:function:: void PyErr_NormalizeException(PyObject **exc, PyObject **val, PyObject **tb)
489493
490-
As of 3.12, this function is deprecated.
491-
Use :c:func:`PyErr_GetRaisedException` instead of :c:func:`PyErr_Fetch` to avoid
492-
any possible de-normalization.
494+
.. deprecated:: 3.12
495+
496+
Use :c:func:`PyErr_GetRaisedException` instead,
497+
to avoid any possible de-normalization.
493498
494499
Under certain circumstances, the values returned by :c:func:`PyErr_Fetch` below
495500
can be "unnormalized", meaning that ``*exc`` is a class object but ``*val`` is
@@ -507,8 +512,6 @@ Querying the error indicator
507512
PyException_SetTraceback(val, tb);
508513
}
509514
510-
.. deprecated:: 3.12
511-
512515
513516
.. c:function:: PyObject* PyErr_GetHandledException(void)
514517
@@ -756,14 +759,12 @@ Exception Objects
756759
757760
.. c:function:: PyObject* PyException_GetArgs(PyObject *ex)
758761
759-
Return args of the given exception as a new reference,
760-
as accessible from Python through :attr:`args`.
762+
Return :attr:`~BaseException.args` of exception *ex*.
761763
762764
763765
.. c:function:: void PyException_SetArgs(PyObject *ex, PyObject *args)
764766
765-
Set the args of the given exception,
766-
as accessible from Python through :attr:`args`.
767+
Set :attr:`~BaseException.args` of exception *ex* to *args*.
767768
768769
769770
.. _unicodeexceptions:

Doc/data/refcounts.dat

+2
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,8 @@ PyEval_EvalFrameEx:int:throwflag::
839839
PyEval_MergeCompilerFlags:int:::
840840
PyEval_MergeCompilerFlags:PyCompilerFlags*:cf::
841841

842+
PyException_GetArgs:PyObject*::+1:
843+
842844
PyException_GetCause:PyObject*::+1:
843845
PyException_GetCause:PyObject*:ex:0:
844846

Doc/library/exceptions.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ The following exceptions are used mostly as base classes for other exceptions.
123123
try:
124124
...
125125
except SomeException:
126-
tb = sys.exc_info()[2]
126+
tb = sys.exception().__traceback__
127127
raise OtherException(...).with_traceback(tb)
128128

129129
.. method:: add_note(note)

Doc/library/importlib.resources.abc.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,12 @@
8989

9090
.. class:: Traversable
9191

92-
An object with a subset of pathlib.Path methods suitable for
92+
An object with a subset of :class:`pathlib.Path` methods suitable for
9393
traversing directories and opening files.
9494

95+
For a representation of the object on the file-system, use
96+
:meth:`importlib.resources.as_file`.
97+
9598
.. versionadded:: 3.9
9699

97100
.. deprecated-removed:: 3.12 3.14

Doc/library/queue.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ The :mod:`queue` module defines the following classes and exceptions:
5757
*maxsize* is less than or equal to zero, the queue size is infinite.
5858

5959
The lowest valued entries are retrieved first (the lowest valued entry is the
60-
one returned by ``sorted(list(entries))[0]``). A typical pattern for entries
61-
is a tuple in the form: ``(priority_number, data)``.
60+
one that would be returned by ``min(entries)``). A typical pattern for
61+
entries is a tuple in the form: ``(priority_number, data)``.
6262

6363
If the *data* elements are not comparable, the data can be wrapped in a class
6464
that ignores the data item and only compares the priority number::

Doc/library/stdtypes.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ These are the Boolean operations, ordered by ascending priority:
8484
+-------------+---------------------------------+-------+
8585
| Operation | Result | Notes |
8686
+=============+=================================+=======+
87-
| ``x or y`` | if *x* is false, then *y*, else | \(1) |
88-
| | *x* | |
87+
| ``x or y`` | if *x* is true, then *x*, else | \(1) |
88+
| | *y* | |
8989
+-------------+---------------------------------+-------+
9090
| ``x and y`` | if *x* is false, then *x*, else | \(2) |
9191
| | *y* | |

Doc/library/traceback.rst

+10-11
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ interpreter.
1616

1717
.. index:: object: traceback
1818

19-
The module uses traceback objects --- this is the object type that is stored in
20-
the :data:`sys.last_traceback` variable and returned as the third item from
21-
:func:`sys.exc_info`.
19+
The module uses traceback objects --- these are objects of type :class:`types.TracebackType`,
20+
which are assigned to the ``__traceback__`` field of :class:`BaseException` instances.
2221

2322
.. seealso::
2423

@@ -81,7 +80,7 @@ The module defines the following functions:
8180

8281
.. function:: print_exc(limit=None, file=None, chain=True)
8382

84-
This is a shorthand for ``print_exception(*sys.exc_info(), limit, file,
83+
This is a shorthand for ``print_exception(sys.exception(), limit, file,
8584
chain)``.
8685

8786

@@ -444,24 +443,24 @@ exception and traceback:
444443
try:
445444
lumberjack()
446445
except IndexError:
447-
exc_type, exc_value, exc_traceback = sys.exc_info()
446+
exc = sys.exception()
448447
print("*** print_tb:")
449-
traceback.print_tb(exc_traceback, limit=1, file=sys.stdout)
448+
traceback.print_tb(exc.__traceback__, limit=1, file=sys.stdout)
450449
print("*** print_exception:")
451-
traceback.print_exception(exc_value, limit=2, file=sys.stdout)
450+
traceback.print_exception(exc, limit=2, file=sys.stdout)
452451
print("*** print_exc:")
453452
traceback.print_exc(limit=2, file=sys.stdout)
454453
print("*** format_exc, first and last line:")
455454
formatted_lines = traceback.format_exc().splitlines()
456455
print(formatted_lines[0])
457456
print(formatted_lines[-1])
458457
print("*** format_exception:")
459-
print(repr(traceback.format_exception(exc_value)))
458+
print(repr(traceback.format_exception(exc)))
460459
print("*** extract_tb:")
461-
print(repr(traceback.extract_tb(exc_traceback)))
460+
print(repr(traceback.extract_tb(exc.__traceback__)))
462461
print("*** format_tb:")
463-
print(repr(traceback.format_tb(exc_traceback)))
464-
print("*** tb_lineno:", exc_traceback.tb_lineno)
462+
print(repr(traceback.format_tb(exc.__traceback__)))
463+
print("*** tb_lineno:", exc.__traceback__.tb_lineno)
465464

466465
The output for the example would look similar to this:
467466

Doc/library/types.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ Standard names are defined for the following types:
320320

321321
.. class:: TracebackType(tb_next, tb_frame, tb_lasti, tb_lineno)
322322

323-
The type of traceback objects such as found in ``sys.exc_info()[2]``.
323+
The type of traceback objects such as found in ``sys.exception().__traceback__``.
324324

325325
See :ref:`the language reference <traceback-objects>` for details of the
326326
available attributes and operations, and guidance on creating tracebacks

Doc/library/wsgiref.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ input, output, and error streams.
674674
This method is a WSGI application to generate an error page for the user. It is
675675
only invoked if an error occurs before headers are sent to the client.
676676

677-
This method can access the current error information using ``sys.exc_info()``,
677+
This method can access the current error using ``sys.exception()``,
678678
and should pass that information to *start_response* when calling it (as
679679
described in the "Error Handling" section of :pep:`3333`).
680680

Doc/library/zipfile.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ The module defines the following items:
5555
.. class:: Path
5656
:noindex:
5757

58-
A pathlib-compatible wrapper for zip files. See section
59-
:ref:`path-objects` for details.
58+
Class that implements a subset of the interface provided by
59+
:class:`pathlib.Path`, including the full
60+
:class:`importlib.resources.abc.Traversable` interface.
6061

6162
.. versionadded:: 3.8
6263

Doc/reference/compound_stmts.rst

+15-18
Original file line numberDiff line numberDiff line change
@@ -301,31 +301,28 @@ keeping all locals in that frame alive until the next garbage collection occurs.
301301
object: traceback
302302

303303
Before an :keyword:`!except` clause's suite is executed,
304-
details about the exception are
305-
stored in the :mod:`sys` module and can be accessed via :func:`sys.exc_info`.
306-
:func:`sys.exc_info` returns a 3-tuple consisting of the exception class, the
307-
exception instance and a traceback object (see section :ref:`types`) identifying
308-
the point in the program where the exception occurred. The details about the
309-
exception accessed via :func:`sys.exc_info` are restored to their previous values
310-
when leaving an exception handler::
311-
312-
>>> print(sys.exc_info())
313-
(None, None, None)
304+
the exception is stored in the :mod:`sys` module, where it can be accessed
305+
from within the body of the :keyword:`!except` clause by calling
306+
:func:`sys.exception`. When leaving an exception handler, the exception
307+
stored in the :mod:`sys` module is reset to its previous value::
308+
309+
>>> print(sys.exception())
310+
None
314311
>>> try:
315312
... raise TypeError
316313
... except:
317-
... print(sys.exc_info())
314+
... print(repr(sys.exception()))
318315
... try:
319316
... raise ValueError
320317
... except:
321-
... print(sys.exc_info())
322-
... print(sys.exc_info())
318+
... print(repr(sys.exception()))
319+
... print(repr(sys.exception()))
323320
...
324-
(<class 'TypeError'>, TypeError(), <traceback object at 0x10efad080>)
325-
(<class 'ValueError'>, ValueError(), <traceback object at 0x10efad040>)
326-
(<class 'TypeError'>, TypeError(), <traceback object at 0x10efad080>)
327-
>>> print(sys.exc_info())
328-
(None, None, None)
321+
TypeError()
322+
ValueError()
323+
TypeError()
324+
>>> print(sys.exception())
325+
None
329326

330327

331328
.. index::

Doc/reference/datamodel.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,7 @@ Internal types
11221122
single: exc_info (in module sys)
11231123
single: last_traceback (in module sys)
11241124
single: sys.exc_info
1125+
single: sys.exception
11251126
single: sys.last_traceback
11261127

11271128
Traceback objects represent a stack trace of an exception. A traceback object

Include/cpython/code.h

+21-7
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,35 @@ extern "C" {
1919
typedef union {
2020
uint16_t cache;
2121
struct {
22-
uint8_t opcode;
23-
uint8_t oparg;
24-
};
22+
uint8_t code;
23+
uint8_t arg;
24+
} op;
2525
} _Py_CODEUNIT;
2626

27-
#define _Py_OPCODE(word) ((word).opcode)
28-
#define _Py_OPARG(word) ((word).oparg)
27+
28+
/* These macros only remain defined for compatibility. */
29+
#define _Py_OPCODE(word) ((word).op.code)
30+
#define _Py_OPARG(word) ((word).op.arg)
31+
32+
static inline _Py_CODEUNIT
33+
_py_make_codeunit(uint8_t opcode, uint8_t oparg)
34+
{
35+
// No designated initialisers because of C++ compat
36+
_Py_CODEUNIT word;
37+
word.op.code = opcode;
38+
word.op.arg = oparg;
39+
return word;
40+
}
2941

3042
static inline void
3143
_py_set_opcode(_Py_CODEUNIT *word, uint8_t opcode)
3244
{
33-
word->opcode = opcode;
45+
word->op.code = opcode;
3446
}
3547

36-
#define _Py_SET_OPCODE(word, opcode) _py_set_opocde(&(word), opcode)
48+
#define _Py_MAKE_CODEUNIT(opcode, oparg) _py_make_codeunit((opcode), (oparg))
49+
#define _Py_SET_OPCODE(word, opcode) _py_set_opcode(&(word), (opcode))
50+
3751

3852
typedef struct {
3953
PyObject *_co_code;

Lib/fileinput.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ def isstdin(self):
399399

400400

401401
def hook_compressed(filename, mode, *, encoding=None, errors=None):
402-
if encoding is None: # EncodingWarning is emitted in FileInput() already.
402+
if encoding is None and "b" not in mode: # EncodingWarning is emitted in FileInput() already.
403403
encoding = "locale"
404404
ext = os.path.splitext(filename)[1]
405405
if ext == '.gz':

0 commit comments

Comments
 (0)