gh-146406: add clear() cross-language hint for immutable types (GH-149927)

This commit is contained in:
Matt Van Horn 2026-05-19 20:01:15 -07:00 committed by GitHub
parent 9dcf94e906
commit d948eaa366
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 0 deletions

View file

@ -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):

View file

@ -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),),

View file

@ -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`.