Skip to content

Fix comparisons between messages and other types - #1483

Open
wozhenbang2004 wants to merge 2 commits into
python-babel:masterfrom
wozhenbang2004:fix-message-comparisons
Open

wozhenbang2004 wants to merge 2 commits into
python-babel:masterfrom
wozhenbang2004:fix-message-comparisons

Conversation

@wozhenbang2004

Copy link
Copy Markdown

Message comparison methods currently access other.id even for unrelated objects. Comparing a message with None raises AttributeError; this also breaks catalog inspection with dill.detect.baditems, as reported in sphinx-doc/sphinx#12064.

Return NotImplemented for non-Message operands so Python can perform reflected comparisons and apply its normal equality/ordering fallbacks. Keep message-to-message comparison unchanged. Regression tests cover unrelated operands in both directions and reflected equality.

Validation on Python 3.12: 21 regression cases fail before the change and pass afterward; make test PYTEST_FLAGS='-q' with generated CLDR 49 data reports 8,241 passed, 3 skipped, 2 xfailed. All pre-commit hooks pass. The original dill.detect.baditems(read_po(...)) operation completes successfully.

Related to sphinx-doc/sphinx#12064. The open sorting optimization #1438 does not modify these comparison methods.

AI assistance: ChatGPT (GPT-6 Astra Pro) prepared this patch, tests, and description.

Return NotImplemented so Python can apply reflected comparisons and equality or ordering fallbacks.
Cover unrelated operands in both directions and Python reflected equality.

This branch has not been deployed

No deployments
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.

1 participant