| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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.
There was a problem hiding this comment.
LGTM, tiny addition request!
Sorry, something went wrong.
| if isinstance(body.value, bytes): | ||
| return None # byte strings are not translatable |
There was a problem hiding this comment.
Like for the f-string case below, let's add a note for our future selves that we could warn in this case.
| if isinstance(body.value, bytes): | |
| return None # byte strings are not translatable | |
| if isinstance(body.value, bytes): | |
| # TODO: we could raise an error or warning when this occurs | |
| return None # byte strings are not translatable |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
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