Skip to content

mofile: decode context (and optimize with partition) - #1305

Merged
akx merged 2 commits into
masterfrom
mofile-ctx-decode
Jul 30, 2026
Merged

mofile: decode context (and optimize with partition)#1305
akx merged 2 commits into
masterfrom
mofile-ctx-decode

Conversation

@akx

@akx akx commented Jul 30, 2026

Copy link
Copy Markdown
Member

Fixes #1147

Duplicates

Closes #1278
Closes #1280
Closes #1283
Closes #1295

@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

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

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     
Flag Coverage Δ
macos-14-3.10 91.19% <100.00%> (+0.02%) ⬆️
macos-14-3.11 91.13% <100.00%> (+0.02%) ⬆️
macos-14-3.12 91.34% <100.00%> (+0.02%) ⬆️
macos-14-3.13 91.34% <100.00%> (+0.02%) ⬆️
macos-14-3.14 91.32% <100.00%> (+0.02%) ⬆️
macos-14-3.15 91.32% <100.00%> (+0.02%) ⬆️
macos-14-3.8 91.06% <100.00%> (+0.02%) ⬆️
macos-14-3.9 91.12% <100.00%> (+0.02%) ⬆️
macos-14-pypy3.10 91.19% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.10 91.21% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.11 91.15% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.12 91.36% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.13 91.36% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.14 91.34% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.15 91.34% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.8 91.08% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.9 91.14% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-pypy3.10 91.21% <100.00%> (+0.02%) ⬆️
windows-2022-3.10 91.20% <100.00%> (+0.02%) ⬆️
windows-2022-3.11 91.14% <100.00%> (+0.02%) ⬆️
windows-2022-3.12 91.35% <100.00%> (+0.02%) ⬆️
windows-2022-3.13 91.35% <100.00%> (+0.02%) ⬆️
windows-2022-3.14 91.33% <100.00%> (+0.02%) ⬆️
windows-2022-3.15 91.33% <100.00%> (+0.02%) ⬆️
windows-2022-3.8 91.18% <100.00%> (+0.02%) ⬆️
windows-2022-3.9 91.13% <100.00%> (+0.02%) ⬆️
windows-2022-pypy3.10 91.20% <100.00%> (+0.02%) ⬆️

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-hq

codspeed-hq Bot commented Jul 30, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 88 untouched benchmarks


Comparing mofile-ctx-decode (d559681) with master (80f1e49)

Open in CodSpeed

@akx
akx marked this pull request as ready for review July 30, 2026 13:13
@akx
akx requested a review from Copilot July 30, 2026 13:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 msgctxt from bytes to str when 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.

@akx
akx merged commit 3a6092f into master Jul 30, 2026
42 checks passed
@akx akx added this to the Babel 2.19 milestone Jul 30, 2026
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.

read_mo does not decode msgctxt

2 participants