summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-02-26 23:23:26 (GMT)
committerGitHub <noreply@github.com>2018-02-26 23:23:26 (GMT)
commit51d95ffc2fb3337dc87277c9af25ecc9a01f991b (patch)
treee0df05550b3e5b2da05412f9d99ee6fef2c13ef0 /Tools
parent53d3f8a89971bac3d2f454ff9f923066ecc3a6d9 (diff)
downloadcpython-51d95ffc2fb3337dc87277c9af25ecc9a01f991b.zip
cpython-51d95ffc2fb3337dc87277c9af25ecc9a01f991b.tar.gz
cpython-51d95ffc2fb3337dc87277c9af25ecc9a01f991b.tar.bz2
bpo-32222: Fix pygettext skipping docstrings for funcs with arg typehints (GH-4745)
(cherry picked from commit eee72d4778a5513038edd5236cdd87ccce2bc60a) Co-authored-by: Tobotimus <Tobotimus@users.noreply.github.com>
Diffstat (limited to 'Tools')
-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