]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-146406: add clear() cross-language hint for immutable types (GH-149927)
authorMatt Van Horn <mvanhorn@users.noreply.github.com>
Wed, 20 May 2026 03:01:15 +0000 (20:01 -0700)
committerGitHub <noreply@github.com>
Wed, 20 May 2026 03:01:15 +0000 (23:01 -0400)
Lib/test/test_traceback.py
Lib/traceback.py
Misc/NEWS.d/next/Library/2026-05-16-22-00-00.gh-issue-146406.10e0da.rst [new file with mode: 0644]

index bb64153b91c92cc8b9f63accaac245de3234a796..7dc3364561d8a115bcb57cec53b6c8716dd1aa2b 100644 (file)
@@ -4637,6 +4637,9 @@ class SuggestionFormattingTestBase(SuggestionFormattingTestMixin):
             (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):
index 88529e1c259a29fac643a31ac2411051114fd93d..7200d91c37df89c6456441360f98f97dd6be8d9c 100644 (file)
@@ -1775,6 +1775,10 @@ _CROSS_LANGUAGE_HINTS = frozendict({
     # 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 (file)
index 0000000..8f65fec
--- /dev/null
@@ -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`.