Fix Catalog.is_identical() for messages with msgctxt - #1329
Open
abhijeet117 wants to merge 1 commit into
Open
Conversation
is_identical() iterated the internal _messages keys, which for context-specific messages are (msgid, msgctxt) tuples, but resolved them through get(), whose _key_for() collapses a tuple id to just the msgid. The lookup therefore always missed context-specific messages and the method returned False, making pybabel update --check report any catalog containing a msgctxt as out of date on every run. Look up the internal keys directly instead of round-tripping through get().
4 tasks
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.
Summary
Catalog.is_identical() returned False for any catalog containing a context-specific message, even when compared with itself, so pybabel update --check reported such catalogs as out of date on every run. The internal (msgid, msgctxt) keys were resolved through get(), which strips the context and looks the message up by msgid only. The lookup now uses the internal keys directly.
Testing
Reproduced on master: a catalog with one pgettext-style message returned False from is_identical(cat). Added catalog tests covering self-comparison, equal catalogs, differing context, differing string and context-free cases; the context test fails without the fix. Full suite: 7828 passed with only two pre-existing timezone-name failures identical on a clean tree.
Checklist