Skip to content

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

Open
Changaco wants to merge 7 commits intopython:mainfrom
Changaco:defaultdict-no-built-in-missing
Open

gh-148242: Partial restoration of the historical behavior of defaultdict, without losing thread safety#148881
Changaco wants to merge 7 commits intopython:mainfrom
Changaco:defaultdict-no-built-in-missing

Conversation

@Changaco
Copy link
Copy Markdown

@Changaco Changaco commented Apr 22, 2026

This is another possible solution to #148242. It breaks some existing code, but not quietly, and it has the advantage of refining the design of the defaultdict class a little.

Changes to the Python stdlib:

  • The defaultdict.__missing__ method is dropped, replaced by a new thread-safe defaultdict.__getitem__.
  • The private importlib.metadata._collections.FreezableDefaultDict class is dropped. It could be fixed instead, but it looks fundamentally problematic to me, and unless I missed something it isn't actually needed, so I removed it.

Change to the private C API: the static dict_unhashable_type function becomes the exposed _Py_dict_unhashable_type.

Alternatives:


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

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