FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix Python extractor treating subscript strings as messages by Cherith1222 · Pull Request #1396 · python-babel/babel · GitHub

Repository navigation

Fix Python extractor treating subscript strings as messages - #1396

Open
Cherith1222 wants to merge 2 commits into
python-babel:masterfrom
Cherith1222:fix/1335-subscript-strings
Open

Cherith1222 wants to merge 2 commits into
python-babel:masterfrom
Cherith1222:fix/1335-subscript-strings

Conversation

Copy link
Copy Markdown

Why

pgettext(context, dictionary["key"]) records "key". Both arguments are variables, so the extractor should record no message.

What changed

extract_python counts [] and {} inside a translation call. String tokens and commas inside that depth are not message arguments. A nested call such as _(dictionary[_("inner")]) is still extracted. Adjacent literals (_("hello" "world")) still concatenate.

Scope

Python extractor only. JavaScript extraction is unchanged.

Tradeoffs

A string written inside a list or dict literal is no longer treated as the gettext argument. Those strings are data.

Blast Radius

Plain string arguments, implicit concatenation, and nested gettext calls keep the previous results. The new test covers the issue example, a subscript beside a real message, a dict, a list, a nested call, a normal pgettext, and implicit concatenation.

Verification

python -m pytest --noconftest tests/messages/test_extract_python.py — 34 passed.
python -m pytest --noconftest tests/messages/test_extract.py — 11 passed.
ruff check on the two edited files passed.
Did not run make import-cldr or the full tox matrix.

Fixes #1335

Drafted with Cursor.

This branch has not been deployed

No deployments
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python extractor treats dict arguments as literal strings

1 participant


Back | FazBrowse Home | New Git URL