FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-146406: add clear() cross-language hint for immutable types by mvanhorn · Pull Request #149927 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
3 changes: 3 additions & 0 deletions Lib/test/test_traceback.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 4 additions & 0 deletions Lib/traceback.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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),),
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -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`.
Loading

Back | FazBrowse Home | New Git URL