Fix Catalog.is_identical() for context-specific messages - #1308
Open
yhay81 wants to merge 1 commit into
Open
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 (python-babel#831). Index _messages directly, since the keys being iterated are its own. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1307.
is_identical()iterates the internal_messageskeys but looked each one upthrough
Catalog.get(). For a context-specific message that key is a(msgid, msgctxt)tuple, andget()re-runs_key_for()on it — which cannotdistinguish that tuple from a pluralizable message's
(singular, plural)id,so it reduces the key to
msgidalone, a key no message is stored under. Thelookup returned
None, so a catalog containing anymsgctxtnever comparedequal, not even to itself.
The user-visible consequence is that
pybabel update --checkreports everycatalog using
pgettext/npgettextas out of date on every run, which makesit unusable as the CI staleness gate it was added for in #831.
The keys are
_messages' own, so this indexes_messagesdirectly.Two regression tests are added, covering a context-specific message and a
context-specific pluralizable message. Both fail on
mainand pass with thechange; the rest of the suite is unaffected (6405 passed, 1162 skipped).
🤖 Generated with Claude Code