https://github.com/python/cpython/commit/d948eaa366029bc358dbe9cf32d545c3ad30c502
commit: d948eaa366029bc358dbe9cf32d545c3ad30c502
branch: main
author: Matt Van Horn <[email protected]>
committer: ZeroIntensity <[email protected]>
date: 2026-05-19T23:01:15-04:00
summary:
gh-146406: add clear() cross-language hint for immutable types (GH-149927)
files:
A Misc/NEWS.d/next/Library/2026-05-16-22-00-00.gh-issue-146406.10e0da.rst
M Lib/test/test_traceback.py
M Lib/traceback.py
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
index bb64153b91c92c..7dc3364561d8a1 100644
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -4637,6 +4637,9 @@ def test_cross_language_mutable_on_immutable(self):
(frozenset, 'remove', "Did you mean to use a 'set' object?"),
(frozenset, 'update', "Did you mean to use a 'set' object?"),
(frozendict, 'update', "Did you mean to use a 'dict' object?"),
+ (tuple, 'clear', "Did you mean to use a 'list' object?"),
+ (frozenset, 'clear', "Did you mean to use a 'set' object?"),
+ (frozendict, 'clear', "Did you mean to use a 'dict' object?"),
]
for test_type, attr, expected in cases:
with self.subTest(type=test_type.__name__, attr=attr):
diff --git a/Lib/traceback.py b/Lib/traceback.py
index 88529e1c259a29..7200d91c37df89 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -1775,6 +1775,10 @@ def print(self, *, file=None, chain=True, **kwargs):
# frozendict -- mutable method on immutable type (user expected a dict)
"update": ((frozenset, "Did you mean to use a 'set' object?", True),
(frozendict, "Did you mean to use a 'dict' object?", True)),
+ # clear() -- shared across immutable container types (user expected the
mutable counterpart)
+ "clear": ((tuple, "Did you mean to use a 'list' object?", True),
+ (frozenset, "Did you mean to use a 'set' object?", True),
+ (frozendict, "Did you mean to use a 'dict' object?", True)),
# float -- bitwise operators belong to int
"__or__": ((float, "Did you mean to use an 'int' object? Bitwise operators
are not supported by 'float'.", True),),
"__and__": ((float, "Did you mean to use an 'int' object? Bitwise
operators are not supported by 'float'.", True),),
diff --git
a/Misc/NEWS.d/next/Library/2026-05-16-22-00-00.gh-issue-146406.10e0da.rst
b/Misc/NEWS.d/next/Library/2026-05-16-22-00-00.gh-issue-146406.10e0da.rst
new file mode 100644
index 00000000000000..8f65fecd85dbf4
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-05-16-22-00-00.gh-issue-146406.10e0da.rst
@@ -0,0 +1,3 @@
+Add cross-language hints for ``.clear()`` on :class:`tuple`,
+:class:`frozenset`, and :class:`frozendict`, suggesting the mutable
+counterpart. Follow-up to :gh:`146406`.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]