Skip to content

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

Merged
ZeroIntensity merged 1 commit into
python:mainfrom
mvanhorn:osc/clear-cross-language-hints
May 20, 2026
Merged

ZeroIntensity merged 1 commit into
python:mainfrom
mvanhorn:osc/clear-cross-language-hints

Conversation

@mvanhorn

@mvanhorn mvanhorn commented May 16, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #146407. Calling .clear() on a tuple, frozenset, or frozendict now suggests the mutable counterpart, mirroring the existing append/extend/insert/remove/discard/update entries for the same immutable types.

Requested by @vstinner after @henryiii flagged that .clear() was the first method they tried on these types in the new hint table from #146407 and got no useful suggestion.

>>> (1, 2, 3).clear()
AttributeError: 'tuple' object has no attribute 'clear'. Did you mean to use a 'list' object?
>>> frozenset({1, 2, 3}).clear()
AttributeError: 'frozenset' object has no attribute 'clear'. Did you mean to use a 'set' object?

Verified locally: ./python.exe -m test test_traceback 434/434 passing.

Follow-up to PR python#146407. Calling .clear() on a tuple, frozenset, or
frozendict now suggests the mutable counterpart (list / set / dict),
mirroring the existing append/extend/insert/remove/discard/update
entries for the same immutable types.

Triggered by @henryiii noticing that .clear() was the first method
they tried on these types and got no useful suggestion, and
@vstinner agreeing it was worth adding.

Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>

@vstinner vstinner left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@ZeroIntensity @picnixz: Do you want to double check the change?

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ZeroIntensity
ZeroIntensity merged commit d948eaa into python:main May 20, 2026
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants