Skip to content

Fix comparisons between messages and other types - #1483

Merged
akx merged 2 commits into
python-babel:masterfrom
wozhenbang2004:fix-message-comparisons
Nov 24, 2026
Merged

akx merged 2 commits into
python-babel:masterfrom
wozhenbang2004:fix-message-comparisons

Conversation

@wozhenbang2004

Copy link
Copy Markdown
Contributor

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.

@akx akx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks.

@akx
akx enabled auto-merge (squash) November 24, 2026 15:32
@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.68%. Comparing base (aeca9fa) to head (bdd6d58).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1483   +/-   ##
=======================================
  Coverage   93.67%   93.68%           
=======================================
  Files          27       27           
  Lines        4983     4989    +6     
=======================================
+ Hits         4668     4674    +6     
  Misses        315      315           
Flag Coverage Δ
macos-26-3.10 ?
macos-26-3.11 92.70% <100.00%> (+<0.01%) ⬆️
macos-26-3.12 ?
macos-26-3.13 92.96% <100.00%> (+<0.01%) ⬆️
macos-26-3.14 ?
macos-26-3.15 92.94% <100.00%> (+<0.01%) ⬆️
macos-26-3.9 92.69% <100.00%> (+<0.01%) ⬆️
macos-26-pypy3.11 ?
macos-26-pypy3.12 92.96% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.10 92.78% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.11 92.72% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.12 92.98% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.13 92.98% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.14 92.96% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.15 92.96% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.9 92.71% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-pypy3.11 92.72% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-pypy3.12 92.98% <100.00%> (+<0.01%) ⬆️
windows-2025-3.10 92.77% <100.00%> (+<0.01%) ⬆️
windows-2025-3.11 92.71% <100.00%> (+<0.01%) ⬆️
windows-2025-3.12 92.97% <100.00%> (+<0.01%) ⬆️
windows-2025-3.13 92.97% <100.00%> (+<0.01%) ⬆️
windows-2025-3.14 92.95% <100.00%> (+<0.01%) ⬆️
windows-2025-3.15 92.95% <100.00%> (+<0.01%) ⬆️
windows-2025-3.9 92.71% <100.00%> (+<0.01%) ⬆️
windows-2025-pypy3.11 92.71% <100.00%> (+<0.01%) ⬆️
windows-2025-pypy3.12 92.97% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed

codspeed Bot commented Nov 24, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 88 untouched benchmarks


Comparing wozhenbang2004:fix-message-comparisons (bdd6d58) with master (aeca9fa)

Open in CodSpeed

@akx
akx merged commit 06f227c into python-babel:master Nov 24, 2026
32 of 36 checks passed
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.

2 participants