@@ -153,10 +153,10 @@ As another example, generating HTML attributes from data:
153
153
.. code-block :: python
154
154
155
155
attributes = {" src" : " shrubbery.jpg" , " alt" : " looks nice" }
156
- template = t" <img {attributes} / >"
157
- assert html(template) == ' <img src="shrubbery.jpg" alt="looks nice" class="looks-nice" / >'
156
+ template = t" <img {attributes} >"
157
+ assert html(template) == ' <img src="shrubbery.jpg" alt="looks nice" class="looks-nice">'
158
158
159
- Unlike f-strings , the ``html `` function has access to template attributes
159
+ Compared to using an f-string , the ``html `` function has access to template attributes
160
160
containing the original information: static strings, interpolations, and values
161
161
from the original scope. Unlike existing templating approaches, t-strings build
162
162
from the well-known f-string syntax and rules. Template systems thus benefit
@@ -443,6 +443,9 @@ Python without deferred evaluation of annotations, reaches its end of life in 20
443
443
In Python 3.14, the behavior of code using ``from __future__ import annotations ``
444
444
is unchanged.
445
445
446
+ .. seealso ::
447
+ :pep: `649 `.
448
+
446
449
447
450
Improved error messages
448
451
-----------------------
@@ -584,8 +587,27 @@ Improved error messages
584
587
^^^^^^
585
588
SyntaxError: cannot use subscript as import target
586
589
587
- .. seealso ::
588
- :pep: `649 `.
590
+ * Improved error message when trying to add an instance of an unhashable type to
591
+ a :class: `dict ` or :class: `set `. (Contributed by CF Bolz-Tereick and Victor Stinner
592
+ in :gh: `132828 `.)
593
+
594
+ .. code-block :: pycon
595
+
596
+ >>> s = set()
597
+ >>> s.add({'pages': 12, 'grade': 'A'})
598
+ Traceback (most recent call last):
599
+ File "<python-input-1>", line 1, in <module>
600
+ s.add({'pages': 12, 'grade': 'A'})
601
+ ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
602
+ TypeError: cannot use 'dict' as a set element (unhashable type: 'dict')
603
+ >>> d = {}
604
+ >>> l = [1, 2, 3]
605
+ >>> d[l] = 12
606
+ Traceback (most recent call last):
607
+ File "<python-input-4>", line 1, in <module>
608
+ d[l] = 12
609
+ ~^^^
610
+ TypeError: cannot use 'list' as a dict key (unhashable type: 'list')
589
611
590
612
591
613
.. _whatsnew314-pep741 :
0 commit comments