Repository navigation
Skip byte strings in extract_python instead of crashing - #1259
Merged
Merged
Conversation
When a byte string like _(b'foo') is encountered during message extraction, _parse_python_string would return the bytes object which then caused a TypeError in ''.join(buf). Byte strings are not valid translation strings anyway, so return None to skip them. Added a test to confirm byte strings are silently skipped while normal strings are still extracted correctly.
akx
force-pushed
the
fix-extract-byte-string-crash
branch
from
October 30, 2026 10:36
44a2e7f to
9e804d5
Compare
akx
enabled auto-merge (squash)
October 30, 2026 10:52
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1259 +/- ##
=======================================
Coverage 93.55% 93.55%
=======================================
Files 27 27
Lines 4931 4933 +2
=======================================
+ Hits 4613 4615 +2
Misses 318 318
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:
|
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.
When
pybabel extractencounters a byte string like_(b'foo'),_parse_python_stringreturns abytesobject which then causes''.join(buf)to crash withTypeError: sequence item 0: expected str instance, bytes found.Since byte strings are not valid translation strings (gettext uses normal strings internally), this just skips them by returning
Nonefrom_parse_python_stringwhen it encounters bytes.Added a test that confirms byte strings are silently skipped while normal strings in the same file are still extracted correctly.
Fixes #1190