diff options
author | Tomas R. <tomas.roun8@gmail.com> | 2024-11-14 22:17:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-14 22:17:42 (GMT) |
commit | 9a456383bed52010b90bd491277ea855626a7bba (patch) | |
tree | f91dbcd12969b9c9b9c4ae2ded757bcfd49abf9a /Tools | |
parent | cae9d9d20f61cdbde0765efa340b6b596c31b67f (diff) | |
download | cpython-9a456383bed52010b90bd491277ea855626a7bba.zip cpython-9a456383bed52010b90bd491277ea855626a7bba.tar.gz cpython-9a456383bed52010b90bd491277ea855626a7bba.tar.bz2 |
gh-126807: pygettext: Do not attempt to extract messages from function definitions. (GH-126808)
Fixes a bug where pygettext would attempt
to extract a message from a code like this:
def _(x): pass
This is because pygettext only looks at one
token at a time and '_(x)' looks like a
function call.
However, since 'x' is not a string literal,
it would erroneously issue a warning.
Diffstat (limited to 'Tools')
-rwxr-xr-x | Tools/i18n/pygettext.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Tools/i18n/pygettext.py b/Tools/i18n/pygettext.py index 3a0b27b..0d16e8f 100755 --- a/Tools/i18n/pygettext.py +++ b/Tools/i18n/pygettext.py @@ -341,6 +341,9 @@ class TokenEater: if ttype == tokenize.NAME and tstring in ('class', 'def'): self.__state = self.__suiteseen return + if ttype == tokenize.NAME and tstring in ('class', 'def'): + self.__state = self.__ignorenext + return if ttype == tokenize.NAME and tstring in opts.keywords: self.__state = self.__keywordseen return @@ -448,6 +451,9 @@ class TokenEater: }, file=sys.stderr) self.__state = self.__waiting + def __ignorenext(self, ttype, tstring, lineno): + self.__state = self.__waiting + def __addentry(self, msg, lineno=None, isdocstring=0): if lineno is None: lineno = self.__lineno |