Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-145119: Allow frozendict to be assigned to instance __dict__#145123

Open
mohsinm-dev wants to merge 2 commits intopython:mainfrom
mohsinm-dev:gh-145119-frozendict-instance-dict
Open

gh-145119: Allow frozendict to be assigned to instance __dict__#145123
mohsinm-dev wants to merge 2 commits intopython:mainfrom
mohsinm-dev:gh-145119-frozendict-instance-dict

Conversation

@mohsinm-dev
Copy link
Contributor

@mohsinm-devmohsinm-dev commentedFeb 22, 2026
edited by bedevere-appbot
Loading

Allowfrozendict (and its subclasses) to be assigned to an instance's__dict__, enabling immutable instances.

Changes:

  • _PyObject_SetDict: acceptfrozendict viaPyAnyDict_Check
  • _PyDict_SetItem_LockHeld: raiseTypeError on set/delete instead ofSystemError
  • object___dir___impl: convertfrozendict to a mutable dict for merging

Copy link

@chatgpt-codex-connectorchatgpt-codex-connectorbot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit:6b702cf72b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

_PyObject_SetDict(PyObject *obj, PyObject *value)
{
if (value != NULL && !PyDict_Check(value)) {
if (value != NULL && !PyAnyDict_Check(value)) {

Choose a reason for hiding this comment

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

P2 Badge Avoid frozendict dict on objects mutating their own dict

Allowing_PyObject_SetDict() to acceptPyAnyDict_Check here makesfrozendict assignable to everyPyObject_GenericSetDict user, but some of those types still perform internal writes withPyDict_SetItem/PyDict_DelItem (for exampledescriptor_get_wrapped_attribute anddescriptor_set_wrapped_attribute inObjects/funcobject.c for classmethod/staticmethod annotation caching).PyDict_SetItem still rejects frozendict withPyErr_BadInternalCall, so afterobj.__dict__ = frozendict(...), operations like reading or updating__annotations__ can now raiseSystemError instead of behaving normally or reporting an intentional immutability error.

Useful? React with 👍 / 👎.

@mohsinm-devmohsinm-devforce-pushed thegh-145119-frozendict-instance-dict branch from6b702cf to8d6ec8dCompareFebruary 22, 2026 19:22
@skirpichev
Copy link
Member

In order to keep the commit history intact,please avoid squashing or amending history and then force-pushing to the PR. Reviewers often want to look at individual commits. When the PR is merged, everything will be squashed into a single commit.

Py_SETREF(dict, temp);
}
else if (PyFrozenDict_Check(dict)) {
/* Convert frozendict to a mutable dict for merging. */
Copy link
Member

Choose a reason for hiding this comment

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

Please wait for#145517. If PyDict_Copy() is modified to always return a dict, you can reuse the PyDict_Check() branch for frozendict.

Copy link
Member

Choose a reason for hiding this comment

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

For now, you can use_PyDict_CopyAsDict() fromInclude/internal/pycore_dict.h.

Comment on lines 4004 to 4005
"__dict__ must be set to a dictionary, "
"not a '%.200s'", Py_TYPE(value)->tp_name);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"__dict__ must be set to adictionary, "
"not a'%.200s'",Py_TYPE(value)->tp_name);
"__dict__ must be set to adict or frozendict, "
"not a%T",value);

@vstinner
Copy link
Member

_PyDict_SetItem_LockHeld: raise TypeError on set/delete instead of SystemError

I extracted these changes from your PR and created a new PR based on it: PRgh-145564.

mohsinm-dev reacted with thumbs up emoji

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

Reviewers

@vstinnervstinnervstinner left review comments

@chatgpt-codex-connectorchatgpt-codex-connector[bot]chatgpt-codex-connector[bot] left review comments

@markshannonmarkshannonAwaiting requested review from markshannonmarkshannon is a code owner

@methanemethaneAwaiting requested review from methanemethane is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@mohsinm-dev@skirpichev@vstinner

[8]ページ先頭

©2009-2026 Movatter.jp