Repository navigation
Fix Catalog.is_identical for context-specific messages - #1428
Conversation
is_identical() iterates the internal _messages keys, but looked each one up through Catalog.get(). For a context-specific message that key is a (msgid, msgctxt) tuple, and get() re-runs _key_for() on it, which takes a tuple for a pluralizable message's id and reduces it to msgid alone -- a key no message is stored under. The lookup returned None, so any catalog containing a msgctxt never compared equal, not even to itself. The visible consequence is that pybabel update --check reports every catalog using pgettext/npgettext as out of date on every run, which makes it unusable as the CI staleness gate it was added for (#831). Index _messages directly, since the keys being iterated are its own. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Co-Authored-By: Aarni Koskela <akx@iki.fi>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1428 +/- ##
=======================================
Coverage 93.65% 93.65%
=======================================
Files 27 27
Lines 4962 4964 +2
=======================================
+ Hits 4647 4649 +2
Misses 315 315
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟢 Approval recommended
The catalog identity lookup correction is accompanied by regression coverage for contextual singular and pluralizable messages, addressing the reported false staleness behavior.
No open issues 🎉
What changed in this PR
Fixes Catalog.is_identical() for context-specific and pluralizable messages by using stored internal keys directly, preventing false staleness reports from pybabel update --check.
Changes:
- Corrects contextual message lookup during catalog identity comparisons.
- Adds regression coverage for contextual singular and pluralizable messages.
| File | Description |
|---|---|
tests/messages/test_catalog.py |
Adds regression coverage for context-specific catalog comparisons. |
babel/messages/catalog.py |
Corrects message lookup during catalog identity comparisons. |
Review effort: Lite
is_identical() iterates the internal _messages keys, but looked each one up through Catalog.get(). For a context-specific message that key is a (msgid, msgctxt) tuple, and get() re-runs _key_for() on it, which takes a tuple for a pluralizable message's id and reduces it to msgid alone -- a key no message is stored under. The lookup returned None, so any catalog containing a msgctxt never compared equal, not even to itself.
The visible consequence is that pybabel update --check reports every catalog using pgettext/npgettext as out of date on every run, which makes it unusable as the CI staleness gate it was added for (#831).
Index _messages directly, since the keys being iterated are its own.
Fixes #1307
Closes #1308 (supersedes it)