Skip to content

gh-141510: Raise TypeError in PyDict_SetItem() on frozendict#145564

Merged
vstinner merged 1 commit intopython:mainfrom
vstinner:pydict_setitem
Mar 11, 2026
Merged

gh-141510: Raise TypeError in PyDict_SetItem() on frozendict#145564
vstinner merged 1 commit intopython:mainfrom
vstinner:pydict_setitem

Conversation

@vstinner
Copy link
Member

@vstinner vstinner commented Mar 5, 2026

If the following functions get an unexpected frozendict, raise a TypeError with an useful error message:

  • PyDict_DelItem()
  • PyDict_DelItemString()
  • PyDict_Merge()
  • PyDict_MergeFromSeq2()
  • PyDict_Pop()
  • PyDict_PopString()
  • PyDict_SetDefault()
  • PyDict_SetDefaultRef()
  • PyDict_SetItem()
  • PyDict_SetItemString()
  • _PyDict_SetItem_KnownHash()
  • PyDict_Update()

If the following functions get an unexpected frozendict, raise a
TypeError with an useful error message:

* PyDict_DelItem()
* PyDict_DelItemString()
* PyDict_Merge()
* PyDict_MergeFromSeq2()
* PyDict_Pop()
* PyDict_PopString()
* PyDict_SetDefault()
* PyDict_SetDefaultRef()
* PyDict_SetItem()
* PyDict_SetItemString()
* _PyDict_SetItem_KnownHash()
* PyDict_Update()

Co-Authored-by: mohsinm-dev <mohsin.mdev@gmail.com>
@vstinner
Copy link
Member Author

vstinner commented Mar 5, 2026

This change raises a nice TypeError exception with an useful error message when a frozendict is passed to a PyDict function which tries to modify it (ex: PyDict_SetItem).

The initial version of the code is based on PR gh-145123.

Copy link
Member

@corona10 corona10 left a comment

Choose a reason for hiding this comment

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

Generally looks good to me, but let me take a look til this weekend.

@corona10 corona10 self-assigned this Mar 9, 2026
Copy link
Member

@corona10 corona10 left a comment

Choose a reason for hiding this comment

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

lgtm

@vstinner vstinner merged commit 713be70 into python:main Mar 11, 2026
56 checks passed
@vstinner vstinner deleted the pydict_setitem branch March 11, 2026 16:05
@vstinner
Copy link
Member Author

Merged. Thanks for the review @corona10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants