Skip to content

Comments

Skip byte strings in extract_python instead of crashing#1259

Open
bysiber wants to merge 1 commit intopython-babel:masterfrom
bysiber:fix-extract-byte-string-crash
Open

Skip byte strings in extract_python instead of crashing#1259
bysiber wants to merge 1 commit intopython-babel:masterfrom
bysiber:fix-extract-byte-string-crash

Conversation

@bysiber
Copy link

@bysiber bysiber commented Feb 22, 2026

When pybabel extract encounters a byte string like _(b'foo'), _parse_python_string returns a bytes object which then causes ''.join(buf) to crash with TypeError: 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 None from _parse_python_string when 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

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pybabel extract crashes when it encounters a byte string

1 participant