Skip to content

Preserve nonconsecutive repeated comment lines - #1348

Merged
akx merged 1 commit into
python-babel:masterfrom
berkay-byte:fix-po-duplicate-comment-lines
Nov 5, 2026
Merged

akx merged 1 commit into
python-babel:masterfrom
berkay-byte:fix-po-duplicate-comment-lines

Conversation

@berkay-byte

@berkay-byte berkay-byte commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Closes #417.

Two long comments beginning with KEY: can wrap onto separate lines when written to a PO file. Reading that file removes the second KEY: because Message.__init__() deduplicates comments across the entire list.

Use itertools.groupby in Message.__init__() to collapse only consecutive identical comments. Repeated lines separated by other text keep their positions. Both extracted and translator comments follow this rule, including when messages are cloned. PO parsing continues to use the constructor normally.

Tests cover consecutive and separated repeats, empty comments, iterator inputs, cloning, obsolete PO entries, and wrapped-comment round trips. Existing catalog-merge deduplication remains unchanged.

Prepared with OpenAI Codex assistance.

Validation: 7,844 tests passed, 9 skipped, 2 expected failures on Python 3.14. Repository pre-commit checks passed for the changed files.

@akx akx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

While I don't know the rationale for the "only write unique comments" commit from nearly 20 years ago fdb3468, I think there may have been something to it.

To fix the issue in #417, namely

#. KEY:
#. foo.bar.baz...<long words more>...
#. KEY:
#. waldo.fred.plugh...<long words more>...

losing the second KEY:, I think a better patch would be to adjust Message.__init__() to keep only one copy of the same line repeated. What do you think?

@berkay-byte
berkay-byte force-pushed the fix-po-duplicate-comment-lines branch from 8bfa0a8 to 155c599 Compare September 18, 2026 14:23
@berkay-byte berkay-byte changed the title Fix repeated comment lines being lost when reading PO files Preserve nonconsecutive repeated comment lines Sep 18, 2026
@berkay-byte
berkay-byte requested a review from akx September 19, 2026 09:05
@akx
akx force-pushed the fix-po-duplicate-comment-lines branch from 155c599 to 663d8b7 Compare October 26, 2026 05:35
@akx
akx enabled auto-merge (squash) November 5, 2026 08:06
@codecov

codecov Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.51%. Comparing base (9a3ef47) to head (663d8b7).
⚠️ Report is 27 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1348   +/-   ##
=======================================
  Coverage   93.51%   93.51%           
=======================================
  Files          27       27           
  Lines        4932     4933    +1     
=======================================
+ Hits         4612     4613    +1     
  Misses        320      320           
Flag Coverage Δ
macos-14-3.10 92.60% <100.00%> (+<0.01%) ⬆️
macos-14-3.11 92.54% <100.00%> (+<0.01%) ⬆️
macos-14-3.12 92.74% <100.00%> (+<0.01%) ⬆️
macos-14-3.13 92.74% <100.00%> (+<0.01%) ⬆️
macos-14-3.14 92.72% <100.00%> (+<0.01%) ⬆️
macos-14-3.15 92.72% <100.00%> (+<0.01%) ⬆️
macos-14-3.8 92.47% <100.00%> (+<0.01%) ⬆️
macos-14-3.9 92.53% <100.00%> (+<0.01%) ⬆️
macos-14-pypy3.10 92.60% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.10 92.62% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.11 92.56% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.12 92.76% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.13 92.76% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.14 92.74% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.15 92.74% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.8 92.49% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-3.9 92.55% <100.00%> (+<0.01%) ⬆️
ubuntu-24.04-pypy3.10 92.62% <100.00%> (+<0.01%) ⬆️
windows-2022-3.10 92.61% <100.00%> (+<0.01%) ⬆️
windows-2022-3.11 92.55% <100.00%> (+<0.01%) ⬆️
windows-2022-3.12 92.75% <100.00%> (+<0.01%) ⬆️
windows-2022-3.13 92.75% <100.00%> (+<0.01%) ⬆️
windows-2022-3.14 92.73% <100.00%> (+<0.01%) ⬆️
windows-2022-3.15 92.73% <100.00%> (+<0.01%) ⬆️
windows-2022-3.8 92.58% <100.00%> (+<0.01%) ⬆️
windows-2022-3.9 92.54% <100.00%> (+<0.01%) ⬆️
windows-2022-pypy3.10 92.61% <100.00%> (+<0.01%) ⬆️

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

codspeed Bot commented Nov 5, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 88 untouched benchmarks


Comparing berkay-byte:fix-po-duplicate-comment-lines (663d8b7) with master (9a3ef47)

Open in CodSpeed

@akx
akx merged commit b33ab76 into python-babel:master Nov 5, 2026
37 of 38 checks passed
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.

Don't remove duplicated comment lines.

2 participants