Skip to content

Declare frozendict equality and inequality methods - #16795

Merged
JelleZijlstra merged 1 commit into
python:mainfrom
carljm:cjm/frozendict-comparisons
Nov 13, 2026
Merged

JelleZijlstra merged 1 commit into
python:mainfrom
carljm:cjm/frozendict-comparisons

Conversation

@carljm

@carljm carljm commented Nov 13, 2026

Copy link
Copy Markdown
Member

At runtime on Python 3.15, frozendict defines its own __eq__ and __ne__ types, which require self to be a frozendict. With this correctly reflected in typeshed, type-checkers can catch the runtime TypeErrors below, which otherwise pass silently:

plain = {"x": 1}
frozen = frozendict(plain)

assert frozendict.__eq__(frozen, plain)  # True
frozendict.__eq__(plain, frozen)         # TypeError
frozendict.__ne__(plain, frozen)         # TypeError

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra
JelleZijlstra merged commit 39bd2d6 into python:main Nov 13, 2026
88 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants