babel icon indicating copy to clipboard operation
babel copied to clipboard

Skip byte strings in extract_python instead of crashing

Open bysiber opened this issue 9 months ago • 0 comments

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

bysiber avatar Feb 22 '26 00:02 bysiber