Skip to content

gh-148242: Full restoration of the historical behavior of defaultdict, without losing thread safety#148880

Open
Changaco wants to merge 11 commits intopython:mainfrom
Changaco:defaultdict-freethreading
Open

gh-148242: Full restoration of the historical behavior of defaultdict, without losing thread safety#148880
Changaco wants to merge 11 commits intopython:mainfrom
Changaco:defaultdict-freethreading

Conversation

@Changaco
Copy link
Copy Markdown

@Changaco Changaco commented Apr 22, 2026

This is one of the possible solutions to #148242. It has the advantage of being transparent to users since it doesn't break any existing code. The downside is that it doesn't completely fix the unsafe design of the defaultdict class.

Changes to the private C API (not strictly necessary, could be dropped):

  • the static dict_unhashable_type function becomes the exposed _Py_dict_unhashable_type
  • a _PyCriticalSection_WarnIfNotHeld function is created

Minor fix of the defaultdict.__missing__ docstring.

Alternatives:


📚 Documentation preview 📚: https://cpython-previews--148880.org.readthedocs.build/

@python-cla-bot
Copy link
Copy Markdown

python-cla-bot Bot commented Apr 22, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

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.

1 participant