Skip to content

Commit 995cfb8

Browse files
committed
Consider square brackets when building call_stack
1 parent 6ba6701 commit 995cfb8

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

‎babel/messages/extract.py‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -586,14 +586,13 @@ def extract_python(
586586
for tok, value, (lineno, _), _, _ in tokens:
587587
if not call_stack and tok == NAME and value in ('def', 'class'):
588588
in_def = True
589-
elif tok == OP and value == '(':
590-
if in_def:
591-
# Avoid false positives for declarations such as:
592-
# def gettext(arg='message'):
593-
in_def = False
594-
continue
595-
if funcname:
596-
call_stack.append(lineno)
589+
elif in_def and tok == OP and value == '(':
590+
# Avoid false positives for declarations such as:
591+
# def gettext(arg='message'):
592+
in_def = False
593+
continue
594+
elif funcname and tok == OP and (value == '(' or value == '['):
595+
call_stack.append(lineno)
597596
elif in_def and tok == OP and value == ':':
598597
# End of a class definition without parens
599598
in_def = False
@@ -683,7 +682,7 @@ def extract_python(
683682

684683
elif tok != NL and not message_lineno:
685684
message_lineno = lineno
686-
elif len(call_stack) > 1 and tok == OP and value == ')':
685+
elif len(call_stack) > 1 and tok == OP and (value == ')' or value == ']'):
687686
call_stack.pop()
688687
elif funcname and not call_stack:
689688
funcname = None

0 commit comments

Comments
 (0)