Skip to content

Commit

Permalink
Merge branch 'main' into pythongh-119726-generate-and-patch-AArch64-t…
Browse files Browse the repository at this point in the history
…rampolines
  • Loading branch information
diegorusso committed Sep 10, 2024
2 parents f2cab0c + 3597642 commit a7a04fc
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 9 deletions.
9 changes: 5 additions & 4 deletions Doc/c-api/buffer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ The following fields are not influenced by *flags* and must always be filled in
with the correct values: :c:member:`~Py_buffer.obj`, :c:member:`~Py_buffer.buf`,
:c:member:`~Py_buffer.len`, :c:member:`~Py_buffer.itemsize`, :c:member:`~Py_buffer.ndim`.


readonly, format
~~~~~~~~~~~~~~~~

Expand All @@ -253,7 +252,8 @@ readonly, format
Controls the :c:member:`~Py_buffer.readonly` field. If set, the exporter
MUST provide a writable buffer or else report failure. Otherwise, the
exporter MAY provide either a read-only or writable buffer, but the choice
MUST be consistent for all consumers.
MUST be consistent for all consumers. For example, :c:expr:`PyBUF_SIMPLE | PyBUF_WRITABLE`
can be used to request a simple writable buffer.

.. c:macro:: PyBUF_FORMAT
Expand All @@ -265,8 +265,9 @@ readonly, format
Since :c:macro:`PyBUF_SIMPLE` is defined as 0, :c:macro:`PyBUF_WRITABLE`
can be used as a stand-alone flag to request a simple writable buffer.

:c:macro:`PyBUF_FORMAT` can be \|'d to any of the flags except :c:macro:`PyBUF_SIMPLE`.
The latter already implies format ``B`` (unsigned bytes).
:c:macro:`PyBUF_FORMAT` must be \|'d to any of the flags except :c:macro:`PyBUF_SIMPLE`, because
the latter already implies format ``B`` (unsigned bytes). :c:macro:`!PyBUF_FORMAT` cannot be
used on its own.


shape, strides, suboffsets
Expand Down
3 changes: 2 additions & 1 deletion Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ operation is being performed, so the intermediate analysis object isn't useful:
.. versionchanged:: 3.14
Added the *show_positions* parameter.

.. function:: disassemble(code, lasti=-1, *, file=None, show_caches=False, adaptive=False)
.. function:: disassemble(code, lasti=-1, *, file=None, show_caches=False,\
adaptive=False, show_offsets=False, show_positions=False)
disco(code, lasti=-1, *, file=None, show_caches=False, adaptive=False,\
show_offsets=False, show_positions=False)
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/tomllib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

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

This module provides an interface for parsing TOML (Tom's Obvious Minimal
This module provides an interface for parsing TOML 1.0.0 (Tom's Obvious Minimal
Language, `https://toml.io <https://toml.io/en/>`_). This module does not
support writing TOML.

Expand Down
15 changes: 15 additions & 0 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ Summary -- Release highlights
New Features
============

Improved Error Messages
-----------------------

* When unpacking assignment fails due to incorrect number of variables, the
error message prints the received number of values in more cases than before.
(Contributed by Tushar Sadhwani in :gh:`122239`.)

.. code-block:: pycon
>>> x, y, z = 1, 2, 3, 4
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
x, y, z = 1, 2, 3, 4
^^^^^^^
ValueError: too many values to unpack (expected 3, got 4)
Other Language Changes
Expand Down
57 changes: 54 additions & 3 deletions Lib/test/test_unpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
>>> a == 4 and b == 5 and c == 6
True
Unpack dict
>>> d = {4: 'four', 5: 'five', 6: 'six'}
>>> a, b, c = d
>>> a == 4 and b == 5 and c == 6
True
Unpack implied tuple
>>> a, b, c = 7, 8, 9
Expand Down Expand Up @@ -66,14 +73,14 @@
>>> a, b = t
Traceback (most recent call last):
...
ValueError: too many values to unpack (expected 2)
ValueError: too many values to unpack (expected 2, got 3)
Unpacking tuple of wrong size
>>> a, b = l
Traceback (most recent call last):
...
ValueError: too many values to unpack (expected 2)
ValueError: too many values to unpack (expected 2, got 3)
Unpacking sequence too short
Expand Down Expand Up @@ -140,8 +147,52 @@
>>> () = [42]
Traceback (most recent call last):
...
ValueError: too many values to unpack (expected 0)
ValueError: too many values to unpack (expected 0, got 1)
Unpacking a larger iterable should raise ValuleError, but it
should not entirely consume the iterable
>>> it = iter(range(100))
>>> x, y, z = it
Traceback (most recent call last):
...
ValueError: too many values to unpack (expected 3)
>>> next(it)
4
Unpacking unbalanced dict
>>> d = {4: 'four', 5: 'five', 6: 'six', 7: 'seven'}
>>> a, b, c = d
Traceback (most recent call last):
...
ValueError: too many values to unpack (expected 3, got 4)
Ensure that custom `__len__()` is NOT called when showing the error message
>>> class LengthTooLong:
... def __len__(self):
... return 5
... def __getitem__(self, i):
... return i*2
...
>>> x, y, z = LengthTooLong()
Traceback (most recent call last):
...
ValueError: too many values to unpack (expected 3)
For evil cases like these as well, no actual count to be shown
>>> class BadLength:
... def __len__(self):
... return 1
... def __getitem__(self, i):
... return i*2
...
>>> x, y, z = BadLength()
Traceback (most recent call last):
...
ValueError: too many values to unpack (expected 3)
"""

__test__ = {'doctests' : doctests}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
When a :class:`list`, :class:`tuple` or :class:`dict`
with too many elements is unpacked, show the actual
length in the error message.
11 changes: 11 additions & 0 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -2148,6 +2148,17 @@ _PyEval_UnpackIterableStackRef(PyThreadState *tstate, _PyStackRef v_stackref,
return 1;
}
Py_DECREF(w);

if (PyList_CheckExact(v) || PyTuple_CheckExact(v)
|| PyDict_CheckExact(v)) {
ll = PyDict_CheckExact(v) ? PyDict_Size(v) : Py_SIZE(v);
if (ll > argcnt) {
_PyErr_Format(tstate, PyExc_ValueError,
"too many values to unpack (expected %d, got %zd)",
argcnt, ll);
goto Error;
}
}
_PyErr_Format(tstate, PyExc_ValueError,
"too many values to unpack (expected %d)",
argcnt);
Expand Down

0 comments on commit a7a04fc

Please sign in to comment.