mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
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.
This commit is contained in:
parent
cae9d9d20f
commit
9a456383be
3 changed files with 36 additions and 5 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue