summaryrefslogtreecommitdiffstats
path: root/Tools/i18n/pygettext.py
diff options
context:
space:
mode:
authorTobotimus <Tobotimus@users.noreply.github.com>2018-02-26 22:48:14 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2018-02-26 22:48:14 (GMT)
commiteee72d4778a5513038edd5236cdd87ccce2bc60a (patch)
tree73ec8b103993e7e3c5331575f901ebdfbd6f67bc /Tools/i18n/pygettext.py
parent3a087beddd9f0955eb9080a6fd1499ff89ca74bf (diff)
downloadcpython-eee72d4778a5513038edd5236cdd87ccce2bc60a.zip
cpython-eee72d4778a5513038edd5236cdd87ccce2bc60a.tar.gz
cpython-eee72d4778a5513038edd5236cdd87ccce2bc60a.tar.bz2
bpo-32222: Fix pygettext skipping docstrings for funcs with arg typehints (GH-4745)
Diffstat (limited to 'Tools/i18n/pygettext.py')
-rwxr-xr-xTools/i18n/pygettext.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/Tools/i18n/pygettext.py b/Tools/i18n/pygettext.py
index 8ef5ff8..0f0395a 100755
--- a/Tools/i18n/pygettext.py
+++ b/Tools/i18n/pygettext.py
@@ -320,6 +320,7 @@ class TokenEater:
self.__lineno = -1
self.__freshmodule = 1
self.__curfile = None
+ self.__enclosurecount = 0
def __call__(self, ttype, tstring, stup, etup, line):
# dispatch
@@ -340,7 +341,7 @@ class TokenEater:
elif ttype not in (tokenize.COMMENT, tokenize.NL):
self.__freshmodule = 0
return
- # class docstring?
+ # class or func/method docstring?
if ttype == tokenize.NAME and tstring in ('class', 'def'):
self.__state = self.__suiteseen
return
@@ -348,9 +349,15 @@ class TokenEater:
self.__state = self.__keywordseen
def __suiteseen(self, ttype, tstring, lineno):
- # ignore anything until we see the colon
- if ttype == tokenize.OP and tstring == ':':
- self.__state = self.__suitedocstring
+ # skip over any enclosure pairs until we see the colon
+ if ttype == tokenize.OP:
+ if tstring == ':' and self.__enclosurecount == 0:
+ # we see a colon and we're not in an enclosure: end of def
+ self.__state = self.__suitedocstring
+ elif tstring in '([{':
+ self.__enclosurecount += 1
+ elif tstring in ')]}':
+ self.__enclosurecount -= 1
def __suitedocstring(self, ttype, tstring, lineno):
# ignore any intervening noise