Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue33189

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:pygettext doesn't work with f-strings
Type:behaviorStage:resolved
Components:Demos and ToolsVersions:Python 3.8, Python 3.7, Python 3.6
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To: serhiy.storchakaNosy List: Riccardo Polignieri, eric.araujo, eric.smith, lemburg, miss-islington, scoder, serhiy.storchaka
Priority:normalKeywords:patch

Created on2018-03-30 20:25 byRiccardo Polignieri, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.

Pull Requests
URLStatusLinkedEdit
PR 6364mergedserhiy.storchaka,2018-04-03 15:19
PR 6533mergedmiss-islington,2018-04-19 06:24
PR 6534closedmiss-islington,2018-04-19 06:25
PR 6535mergedmiss-islington,2018-04-19 07:02
Messages (8)
msg314712 -(view)Author: Riccardo Polignieri (Riccardo Polignieri)Date: 2018-03-30 20:25
Tested (on windows) with python 3.6, but I guess it's the same in py3.7: # test.pydef hello(x):  print(_(f'hello {x}'))> py pygettext.py test.pyTraceback (most recent call last):  File "C:\Program Files\Python36\Tools\i18n\pygettext.py", line 623, in <module>    if __name__ == '__main__':  File "C:\Program Files\Python36\Tools\i18n\pygettext.py", line 597, in main    for _token in tokens:  File "C:\Program Files\Python36\Tools\i18n\pygettext.py", line 328, in __call__    ##              'tstring:', tstring  File "C:\Program Files\Python36\Tools\i18n\pygettext.py", line 382, in __openseen    elif ttype == tokenize.STRING:  File "C:\Program Files\Python36\Tools\i18n\pygettext.py", line 236, in safe_eval    # unwrap quotes, safely  File "<string>", line 1, in <module>NameError: name 'x' is not defined
msg314776 -(view)Author: Stefan Behnel (scoder)*(Python committer)Date: 2018-04-01 15:05
Is there really a use case for this?I would normally expect place holders to get replaced *after* translation, i.e. in the translated text, not before.
msg314780 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2018-04-01 16:45
I agree that pygettext should not and can not support f-strings, but the error should be better. The problem is that an f-string expression is tokenized as literal strings, but eval() can't evaluate it out of context.
msg314878 -(view)Author: Riccardo Polignieri (Riccardo Polignieri)Date: 2018-04-03 11:39
> the error should be betterYes, that's what I maeant - sorry I should have phrased better. I marked by mistake a couple of f-strings for translation and totally forgot about it for a while... it took me some time to figure out what was going on with this NameError popping out of nowhere.Curiously, xgettext handles this thing better (...or, far worse actually): it just parses the f-string as a regular one, producing something likemsgid "hello {x}"msgstr ""But then of course Python will fail *silently* at runtime, never picking up the translated version of the string...
msg315389 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2018-04-17 10:22
If there are no objections I'm going to mergePR 6364 in 24 hours.
msg315481 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2018-04-19 06:23
New changeset69524821a87251b7aee966f6e46b3810ff5aaa64 by Serhiy Storchaka in branch 'master':bpo-33189: pygettext.py now accepts only literal strings (GH-6364)https://github.com/python/cpython/commit/69524821a87251b7aee966f6e46b3810ff5aaa64
msg315482 -(view)Author: miss-islington (miss-islington)Date: 2018-04-19 06:49
New changeseta4fb580f701df5bf07ce569a4f43abfb05c92759 by Miss Islington (bot) in branch '3.7':bpo-33189: pygettext.py now accepts only literal strings (GH-6364)https://github.com/python/cpython/commit/a4fb580f701df5bf07ce569a4f43abfb05c92759
msg315483 -(view)Author: miss-islington (miss-islington)Date: 2018-04-19 07:34
New changeset6f870935c2e024cbd1cc379f85e6a66d7711dcc7 by Miss Islington (bot) in branch '3.6':bpo-33189: pygettext.py now accepts only literal strings (GH-6364)https://github.com/python/cpython/commit/6f870935c2e024cbd1cc379f85e6a66d7711dcc7
History
DateUserActionArgs
2022-04-11 14:58:59adminsetgithub: 77370
2018-04-19 07:48:45serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-04-19 07:34:30miss-islingtonsetmessages: +msg315483
2018-04-19 07:02:04miss-islingtonsetpull_requests: +pull_request6229
2018-04-19 06:49:18miss-islingtonsetnosy: +miss-islington
messages: +msg315482
2018-04-19 06:25:20miss-islingtonsetpull_requests: +pull_request6228
2018-04-19 06:24:25miss-islingtonsetpull_requests: +pull_request6227
2018-04-19 06:23:05serhiy.storchakasetmessages: +msg315481
2018-04-17 10:22:06serhiy.storchakasetassignee:serhiy.storchaka

messages: +msg315389
nosy: +lemburg
2018-04-06 16:26:11eric.araujosetnosy: +eric.araujo
2018-04-03 15:19:38serhiy.storchakasetkeywords: +patch
stage: patch review
pull_requests: +pull_request6074
2018-04-03 11:39:25Riccardo Polignierisetmessages: +msg314878
2018-04-01 16:45:43serhiy.storchakasetnosy: +eric.smith,serhiy.storchaka

messages: +msg314780
versions: + Python 3.8
2018-04-01 15:05:47scodersetnosy: +scoder
messages: +msg314776
2018-03-30 20:25:16Riccardo Poligniericreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp