-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-126807: pygettext: Do not attempt to extract messages from function definitions. #126808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
8994130
c8d1538
6cc0833
6e0cd50
249db28
e563331
7b37aa2
fa0772e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fix extraction warnings in :program:`pygettext.py` caused by mistaking | ||
| function definitions for function calls. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,10 @@ | ||
| #! /usr/bin/env python3 | ||
| # -*- coding: iso-8859-1 -*- | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no other file that uses this encoding, I think it's safe (and more practical) to use utf-8. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not related change, so please keep the coding cookie. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it! I'll revert :) Would you accept a separate (perhaps not backported) PR that removes the coding and the commented-out code or do you think it's not worth it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll accept it if there are pygettext tests for files with non-UTF-8 encoding. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough, I'll add it to my todo list :) |
||
| # Originally written by Barry Warsaw <[email protected]> | ||
| # | ||
| # Minimally patched to make it even more xgettext compatible | ||
| # by Peter Funk <[email protected]> | ||
| # | ||
| # 2002-11-22 Jürgen Hermann <[email protected]> | ||
| # 2002-11-22 Jürgen Hermann <[email protected]> | ||
| # Added checks that _() only contains string literals, and | ||
| # command line args are resolved to module lists, i.e. you | ||
| # can now pass a filename, a module or package name, or a | ||
|
|
@@ -207,7 +206,7 @@ def make_escapes(pass_nonascii): | |
| global escapes, escape | ||
| if pass_nonascii: | ||
| # Allow non-ascii characters to pass through so that e.g. 'msgid | ||
| # "Höhe"' would result not result in 'msgid "H\366he"'. Otherwise we | ||
| # "Höhe"' would result not result in 'msgid "H\366he"'. Otherwise we | ||
| # escape any character outside the 32..126 range. | ||
| mod = 128 | ||
| escape = escape_ascii | ||
|
|
@@ -306,6 +305,11 @@ def getFilesForName(name): | |
| return [] | ||
|
|
||
|
|
||
| def _is_def_or_class_keyword(token): | ||
| ttype, tstring, *_ = token | ||
| return ttype == tokenize.NAME and tstring in ('def', 'class') | ||
|
|
||
|
|
||
| class TokenEater: | ||
| def __init__(self, options): | ||
| self.__options = options | ||
|
|
@@ -316,13 +320,11 @@ def __init__(self, options): | |
| self.__freshmodule = 1 | ||
| self.__curfile = None | ||
| self.__enclosurecount = 0 | ||
| self.__prev_token = None | ||
|
|
||
| def __call__(self, ttype, tstring, stup, etup, line): | ||
| # dispatch | ||
| ## import token | ||
| ## print('ttype:', token.tok_name[ttype], 'tstring:', tstring, | ||
| ## file=sys.stderr) | ||
tomasr8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self.__state(ttype, tstring, stup[0]) | ||
| self.__prev_token = (ttype, tstring, stup, etup, line) | ||
|
|
||
| def __waiting(self, ttype, tstring, lineno): | ||
| opts = self.__options | ||
|
|
@@ -341,7 +343,10 @@ def __waiting(self, ttype, tstring, lineno): | |
| if ttype == tokenize.NAME and tstring in ('class', 'def'): | ||
| self.__state = self.__suiteseen | ||
| return | ||
| if ttype == tokenize.NAME and tstring in opts.keywords: | ||
| if ( | ||
| ttype == tokenize.NAME and tstring in opts.keywords | ||
| and (not self.__prev_token or not _is_def_or_class_keyword(self.__prev_token)) | ||
| ): | ||
|
||
| self.__state = self.__keywordseen | ||
| return | ||
| if ttype == tokenize.STRING: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.