Skip to content

Commit 3c1c647

Browse files
committed
Merge remote-tracking branch 'upstream/main' into expose_codegen
2 parents a2a1c17 + c43714f commit 3c1c647

File tree

88 files changed

+1187
-2132
lines changed

Some content is hidden

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

88 files changed

+1187
-2132
lines changed

Doc/c-api/call.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ This is a pointer to a function with the following signature:
9393
and they must be unique.
9494
If there are no keyword arguments, then *kwnames* can instead be *NULL*.
9595

96-
.. c:macro:: PY_VECTORCALL_ARGUMENTS_OFFSET
96+
.. data:: PY_VECTORCALL_ARGUMENTS_OFFSET
9797

9898
If this flag is set in a vectorcall *nargsf* argument, the callee is allowed
9999
to temporarily change ``args[-1]``. In other words, *args* points to

Doc/c-api/typeobj.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,17 @@ and :c:type:`PyType_Type` effectively act as defaults.)
12451245
**Inheritance:**
12461246

12471247
This flag is not inherited.
1248+
However, subclasses will not be instantiable unless they provide a
1249+
non-NULL :c:member:`~PyTypeObject.tp_new` (which is only possible
1250+
via the C API).
1251+
1252+
.. note::
1253+
1254+
To disallow instantiating a class directly but allow instantiating
1255+
its subclasses (e.g. for an :term:`abstract base class`),
1256+
do not use this flag.
1257+
Instead, make :c:member:`~PyTypeObject.tp_new` only succeed for
1258+
subclasses.
12481259

12491260
.. versionadded:: 3.10
12501261

Doc/faq/windows.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ How can I embed Python into a Windows application?
167167

168168
Embedding the Python interpreter in a Windows app can be summarized as follows:
169169

170-
1. Do _not_ build Python into your .exe file directly. On Windows, Python must
170+
1. Do **not** build Python into your .exe file directly. On Windows, Python must
171171
be a DLL to handle importing modules that are themselves DLL's. (This is the
172172
first key undocumented fact.) Instead, link to :file:`python{NN}.dll`; it is
173173
typically installed in ``C:\Windows\System``. *NN* is the Python version, a
@@ -191,7 +191,7 @@ Embedding the Python interpreter in a Windows app can be summarized as follows:
191191
2. If you use SWIG, it is easy to create a Python "extension module" that will
192192
make the app's data and methods available to Python. SWIG will handle just
193193
about all the grungy details for you. The result is C code that you link
194-
*into* your .exe file (!) You do _not_ have to create a DLL file, and this
194+
*into* your .exe file (!) You do **not** have to create a DLL file, and this
195195
also simplifies linking.
196196

197197
3. SWIG will create an init function (a C function) whose name depends on the
@@ -218,10 +218,10 @@ Embedding the Python interpreter in a Windows app can be summarized as follows:
218218
5. There are two problems with Python's C API which will become apparent if you
219219
use a compiler other than MSVC, the compiler used to build pythonNN.dll.
220220

221-
Problem 1: The so-called "Very High Level" functions that take FILE *
221+
Problem 1: The so-called "Very High Level" functions that take ``FILE *``
222222
arguments will not work in a multi-compiler environment because each
223-
compiler's notion of a struct FILE will be different. From an implementation
224-
standpoint these are very _low_ level functions.
223+
compiler's notion of a ``struct FILE`` will be different. From an implementation
224+
standpoint these are very low level functions.
225225

226226
Problem 2: SWIG generates the following code when generating wrappers to void
227227
functions:

Doc/library/ctypes.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ from within *IDLE* or *PythonWin*::
359359
>>> printf(b"%f bottles of beer\n", 42.5)
360360
Traceback (most recent call last):
361361
File "<stdin>", line 1, in <module>
362-
ArgumentError: argument 2: exceptions.TypeError: Don't know how to convert parameter 2
362+
ArgumentError: argument 2: TypeError: Don't know how to convert parameter 2
363363
>>>
364364

365365
As has been mentioned before, all Python types except integers, strings, and
@@ -422,7 +422,7 @@ prototype for a C function), and tries to convert the arguments to valid types::
422422
>>> printf(b"%d %d %d", 1, 2, 3)
423423
Traceback (most recent call last):
424424
File "<stdin>", line 1, in <module>
425-
ArgumentError: argument 2: exceptions.TypeError: wrong type
425+
ArgumentError: argument 2: TypeError: wrong type
426426
>>> printf(b"%s %d %f\n", b"X", 2, 3)
427427
X 2 3.000000
428428
13
@@ -487,7 +487,7 @@ single character Python bytes object into a C char::
487487
>>> strchr(b"abcdef", b"def")
488488
Traceback (most recent call last):
489489
File "<stdin>", line 1, in <module>
490-
ArgumentError: argument 2: exceptions.TypeError: one character string expected
490+
ArgumentError: argument 2: TypeError: one character string expected
491491
>>> print(strchr(b"abcdef", b"x"))
492492
None
493493
>>> strchr(b"abcdef", b"d")

Doc/library/enum.rst

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ Data Types
242242

243243
Member values can be anything: :class:`int`, :class:`str`, etc.. If
244244
the exact value is unimportant you may use :class:`auto` instances and an
245-
appropriate value will be chosen for you. Care must be taken if you mix
246-
:class:`auto` with other values.
245+
appropriate value will be chosen for you. See :class:`auto` for the
246+
details.
247247

248248
.. attribute:: Enum._ignore_
249249

@@ -778,7 +778,16 @@ Utilities and Decorators
778778
For *Enum* and *IntEnum* that appropriate value will be the last value plus
779779
one; for *Flag* and *IntFlag* it will be the first power-of-two greater
780780
than the last value; for *StrEnum* it will be the lower-cased version of the
781-
member's name.
781+
member's name. Care must be taken if mixing *auto()* with manually specified
782+
values.
783+
784+
*auto* instances are only resolved when at the top level of an assignment:
785+
786+
* ``FIRST = auto()`` will work (auto() is replaced with ``1``);
787+
* ``SECOND = auto(), -2`` will work (auto is replaced with ``2``, so ``2, -2`` is
788+
used to create the ``SECOND`` enum member;
789+
* ``THREE = [auto(), -3]`` will *not* work (``<auto instance>, -3`` is used to
790+
create the ``THREE`` enum member)
782791

783792
``_generate_next_value_`` can be overridden to customize the values used by
784793
*auto*.

Doc/library/functions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@ are always available. They are listed here in alphabetical order.
14191419
supported.
14201420

14211421

1422-
.. function:: print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
1422+
.. function:: print(*objects, sep=' ', end='\n', file=None, flush=False)
14231423

14241424
Print *objects* to the text stream *file*, separated by *sep* and followed
14251425
by *end*. *sep*, *end*, *file*, and *flush*, if present, must be given as keyword

Doc/library/socket.rst

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,11 @@ created. Socket addresses are represented as follows:
189189
``(ifname, proto[, pkttype[, hatype[, addr]]])`` where:
190190

191191
- *ifname* - String specifying the device name.
192-
- *proto* - An in network-byte-order integer specifying the Ethernet
193-
protocol number.
192+
- *proto* - The Ethernet protocol number.
193+
May be :data:`ETH_P_ALL` to capture all protocols,
194+
one of the :ref:`ETHERTYPE_* constants <socket-ethernet-types>`
195+
or any other Ethernet protocol number.
196+
Value must be in network-byte-order.
194197
- *pkttype* - Optional integer specifying the packet type:
195198

196199
- ``PACKET_HOST`` (the default) - Packet addressed to the local host.
@@ -508,6 +511,19 @@ Constants
508511
.. availability:: Linux >= 2.2.
509512

510513

514+
.. data:: ETH_P_ALL
515+
516+
:data:`!ETH_P_ALL` can be used in the :class:`~socket.socket`
517+
constructor as *proto* for the :const:`AF_PACKET` family in order to
518+
capture every packet, regardless of protocol.
519+
520+
For more information, see the :manpage:`packet(7)` manpage.
521+
522+
.. availability:: Linux.
523+
524+
.. versionadded:: 3.12
525+
526+
511527
.. data:: AF_RDS
512528
PF_RDS
513529
SOL_RDS
@@ -638,6 +654,22 @@ Constants
638654

639655
.. versionadded:: 3.12
640656

657+
.. _socket-ethernet-types:
658+
659+
.. data:: ETHERTYPE_ARP
660+
ETHERTYPE_IP
661+
ETHERTYPE_IPV6
662+
ETHERTYPE_VLAN
663+
664+
`IEEE 802.3 protocol number
665+
<https://www.iana.org/assignments/ieee-802-numbers/ieee-802-numbers.txt>`_.
666+
constants.
667+
668+
.. availability:: Linux, FreeBSD, macOS.
669+
670+
.. versionadded:: 3.12
671+
672+
641673
Functions
642674
^^^^^^^^^
643675

Doc/library/sqlite3.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1834,8 +1834,13 @@ The deprecated default adapters and converters consist of:
18341834
Command-line interface
18351835
^^^^^^^^^^^^^^^^^^^^^^
18361836

1837-
The :mod:`!sqlite3` module can be invoked as a script
1837+
The :mod:`!sqlite3` module can be invoked as a script,
1838+
using the interpreter's :option:`-m` switch,
18381839
in order to provide a simple SQLite shell.
1840+
The argument signature is as follows::
1841+
1842+
python -m sqlite3 [-h] [-v] [filename] [sql]
1843+
18391844
Type ``.quit`` or CTRL-D to exit the shell.
18401845

18411846
.. program:: python -m sqlite3 [-h] [-v] [filename] [sql]

Doc/reference/grammar.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ and `PEG <https://en.wikipedia.org/wiki/Parsing_expression_grammar>`_.
1212
In particular, ``&`` followed by a symbol, token or parenthesized
1313
group indicates a positive lookahead (i.e., is required to match but
1414
not consumed), while ``!`` indicates a negative lookahead (i.e., is
15-
required _not_ to match). We use the ``|`` separator to mean PEG's
15+
required *not* to match). We use the ``|`` separator to mean PEG's
1616
"ordered choice" (written as ``/`` in traditional PEG grammars). See
1717
:pep:`617` for more details on the grammar's syntax.
1818

Doc/reference/simple_stmts.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ statement, of a variable or attribute annotation and an optional assignment stat
330330
annotated_assignment_stmt: `augtarget` ":" `expression`
331331
: ["=" (`starred_expression` | `yield_expression`)]
332332

333-
The difference from normal :ref:`assignment` is that only single target is allowed.
333+
The difference from normal :ref:`assignment` is that only a single target is allowed.
334334

335335
For simple names as assignment targets, if in class or module scope,
336336
the annotations are evaluated and stored in a special class or module
@@ -365,8 +365,8 @@ target, then the interpreter evaluates the target except for the last
365365
IDEs.
366366

367367
.. versionchanged:: 3.8
368-
Now annotated assignments allow same expressions in the right hand side as
369-
the regular assignments. Previously, some expressions (like un-parenthesized
368+
Now annotated assignments allow the same expressions in the right hand side as
369+
regular assignments. Previously, some expressions (like un-parenthesized
370370
tuple expressions) caused a syntax error.
371371

372372

@@ -756,7 +756,7 @@ commas) the two steps are carried out separately for each clause, just
756756
as though the clauses had been separated out into individual import
757757
statements.
758758

759-
The details of the first step, finding and loading modules are described in
759+
The details of the first step, finding and loading modules, are described in
760760
greater detail in the section on the :ref:`import system <importsystem>`,
761761
which also describes the various types of packages and modules that can
762762
be imported, as well as all the hooks that can be used to customize

Doc/tutorial/errors.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ Raising and Handling Multiple Unrelated Exceptions
496496
==================================================
497497

498498
There are situations where it is necessary to report several exceptions that
499-
have occurred. This it often the case in concurrency frameworks, when several
499+
have occurred. This is often the case in concurrency frameworks, when several
500500
tasks may have failed in parallel, but there are also other use cases where
501501
it is desirable to continue execution and collect multiple errors rather than
502502
raise the first exception.

Doc/whatsnew/3.12.rst

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,36 @@ Important deprecations, removals or restrictions:
7575
Improved Error Messages
7676
=======================
7777

78+
* Modules from the standard library are now potentially suggested as part of
79+
the error messages displayed by the interpreter when a :exc:`NameError` is
80+
raised to the top level. Contributed by Pablo Galindo in :gh:`98254`.
81+
82+
>>> sys.version_info
83+
Traceback (most recent call last):
84+
File "<stdin>", line 1, in <module>
85+
NameError: name 'sys' is not defined. Did you forget to import 'sys'?
86+
87+
* Improve the error suggestion for :exc:`NameError` exceptions for instances.
88+
Now if a :exc:`NameError` is raised in a method and the instance has an
89+
attribute that's exactly equal to the name in the exception, the suggestion
90+
will include ``self.<NAME>`` instead of the closest match in the method
91+
scope. Contributed by Pablo Galindo in :gh:`99139`.
92+
93+
>>> class A:
94+
... def __init__(self):
95+
... self.blech = 1
96+
...
97+
... def foo(self):
98+
... somethin = blech
99+
100+
>>> A().foo()
101+
Traceback (most recent call last):
102+
File "<stdin>", line 1
103+
somethin = blech
104+
^^^^^
105+
NameError: name 'blech' is not defined. Did you mean: 'self.blech'?
106+
107+
78108
* Improve the :exc:`SyntaxError` error message when the user types ``import x
79109
from y`` instead of ``from y import x``. Contributed by Pablo Galindo in :gh:`98931`.
80110

@@ -85,6 +115,16 @@ Improved Error Messages
85115
^^^^^^^^^^^^^^^^^^^^^^^
86116
SyntaxError: Did you mean to use 'from ... import ...' instead?
87117

118+
* :exc:`ImportError` exceptions raised from failed ``from <module> import
119+
<name>`` statements now include suggestions for the value of ``<name>`` based on the
120+
available names in ``<module>``. Contributed by Pablo Galindo in :gh:`91058`.
121+
122+
>>> from collections import chainmap
123+
Traceback (most recent call last):
124+
File "<stdin>", line 1, in <module>
125+
ImportError: cannot import name 'chainmap' from 'collections'. Did you mean: 'ChainMap'?
126+
127+
88128
New Features
89129
============
90130

@@ -656,6 +696,18 @@ New Features
656696
``__dict__`` and weakrefs with less bookkeeping,
657697
using less memory and with faster access.
658698

699+
* API for performing calls using
700+
:ref:`the vectorcall protocol <vectorcall>` was added to the
701+
:ref:`Limited API <stable>`:
702+
703+
* :c:func:`PyObject_Vectorcall`
704+
* :c:func:`PyObject_VectorcallMethod`
705+
* :const:`PY_VECTORCALL_ARGUMENTS_OFFSET`
706+
707+
This means that both the incoming and outgoing ends of the vector call
708+
protocol are now available in the :ref:`Limited API <stable>`. (Contributed
709+
by Wenzel Jakob in :gh:`98586`.)
710+
659711
* Added two new public functions,
660712
:c:func:`PyEval_SetProfileAllThreads` and
661713
:c:func:`PyEval_SetTraceAllThreads`, that allow to set tracing and profiling

Grammar/python.gram

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,8 +1254,8 @@ invalid_try_stmt:
12541254
| a='try' ':' NEWLINE !INDENT {
12551255
RAISE_INDENTATION_ERROR("expected an indented block after 'try' statement on line %d", a->lineno) }
12561256
| 'try' ':' block !('except' | 'finally') { RAISE_SYNTAX_ERROR("expected 'except' or 'finally' block") }
1257-
| 'try' ':' block* ((except_block+ except_star_block) | (except_star_block+ except_block)) block* {
1258-
RAISE_SYNTAX_ERROR("cannot have both 'except' and 'except*' on the same 'try'") }
1257+
| a='try' ':' block* ((except_block+ except_star_block) | (except_star_block+ except_block)) block* {
1258+
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot have both 'except' and 'except*' on the same 'try'") }
12591259
invalid_except_stmt:
12601260
| 'except' '*'? a=expression ',' expressions ['as' NAME ] ':' {
12611261
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "multiple exception types must be parenthesized") }

Include/internal/pycore_code.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ extern void _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs,
230230
_Py_CODEUNIT *instr, int oparg);
231231
extern void _Py_Specialize_UnpackSequence(PyObject *seq, _Py_CODEUNIT *instr,
232232
int oparg);
233-
extern void _Py_Specialize_ForIter(PyObject *iter, _Py_CODEUNIT *instr);
233+
extern void _Py_Specialize_ForIter(PyObject *iter, _Py_CODEUNIT *instr, int oparg);
234234

235235
/* Finalizer function for static codeobjects used in deepfreeze.py */
236236
extern void _PyStaticCode_Fini(PyCodeObject *co);

Include/internal/pycore_frame.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ typedef struct _PyInterpreterFrame {
6161
// over, or (in the case of a newly-created frame) a totally invalid value:
6262
_Py_CODEUNIT *prev_instr;
6363
int stacktop; /* Offset of TOS from localsplus */
64+
uint16_t yield_offset;
6465
bool is_entry; // Whether this is the "root" frame for the current _PyCFrame.
6566
char owner;
6667
/* Locals and stack */
@@ -110,6 +111,7 @@ _PyFrame_InitializeSpecials(
110111
frame->frame_obj = NULL;
111112
frame->prev_instr = _PyCode_CODE(code) - 1;
112113
frame->is_entry = false;
114+
frame->yield_offset = 0;
113115
frame->owner = FRAME_OWNED_BY_THREAD;
114116
}
115117

0 commit comments

Comments
 (0)