Skip to content

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

Open
vstinner wants to merge 1 commit intopython:mainfrom
vstinner:pydict_setitem
Open

gh-141510: Raise TypeError in PyDict_SetItem() on frozendict#145564
vstinner wants to merge 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.

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