Skip to content

Comments

gh-145118: Add frozendict support to type()#145124

Open
StanFromIreland wants to merge 2 commits intopython:mainfrom
StanFromIreland:builtins-dicts
Open

gh-145118: Add frozendict support to type()#145124
StanFromIreland wants to merge 2 commits intopython:mainfrom
StanFromIreland:builtins-dicts

Conversation

@StanFromIreland
Copy link
Member

@StanFromIreland StanFromIreland commented Feb 22, 2026

if (dict == NULL) {
goto error;
PyObject *dict;
if (PyFrozenDict_Check(ctx->orig_dict)) {
Copy link
Contributor

@eendebakpt eendebakpt Feb 22, 2026

Choose a reason for hiding this comment

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

Note: this code path is needed because PyDict_Copy would return a frozendict, see

int frozendict = PyFrozenDict_Check(o);
(this is not explicitly documented, I will make a new issue/pr for that).

}
if (!PyAnyDict_Check(orig_dict)) {
PyErr_Format(PyExc_TypeError,
"type.__new__() argument 3 must be dict, not %T",
Copy link
Contributor

@eendebakpt eendebakpt Feb 22, 2026

Choose a reason for hiding this comment

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

Suggested change
"type.__new__() argument 3 must be dict, not %T",
"type.__new__() argument 3 must be dict or frozendict, not %T",

For consideration, not sure I would make the change myself.

(and whatever the outcome: be consistent with maketrans below)

Copy link
Member Author

Choose a reason for hiding this comment

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

Other error messages weren't updated like this, no?

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

You should write a separated PR to modify str.maketrans(). It's unrelated to the type change.

@StanFromIreland StanFromIreland changed the title gh-145118: Add frozendict support to str.maketrans() and type() gh-145118: Add frozendict support to type() Feb 22, 2026
@StanFromIreland
Copy link
Member Author

Split to #145129.

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.

3 participants