mofile: decode context (and optimize with partition) - #1305
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1305 +/- ##
==========================================
+ Coverage 92.12% 92.14% +0.02%
==========================================
Files 27 27
Lines 4737 4737
==========================================
+ Hits 4364 4365 +1
+ Misses 373 372 -1
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.
Pull request overview
This PR fixes babel.messages.mofile.read_mo() to decode MO message contexts (msgctxt) to str using the catalog charset (consistent with how msgid/msgstr are decoded), which restores correct Catalog.get(..., context=...) behavior and supports write_mo() → read_mo() round-trips for contexted messages.
Changes:
- Decode
msgctxtfrom bytes tostrwhen reading MO files, using the catalog charset. - Simplify/optimize context splitting using
bytes.partition(b"\x04"). - Add a regression test that round-trips a contexted message through
write_mo()/read_mo()and verifies lookup by string context.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
babel/messages/mofile.py |
Decodes context (msgctxt) to str during MO parsing and refactors context splitting via partition. |
tests/messages/test_mofile.py |
Adds a regression test ensuring context is decoded and retrievable via Catalog.get(..., context=str). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Fixes #1147
Duplicates
Closes #1278
Closes #1280
Closes #1283
Closes #1295