Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions babel/messages/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,14 +586,13 @@ def extract_python(
for tok, value, (lineno, _), _, _ in tokens:
if not call_stack and tok == NAME and value in ('def', 'class'):
in_def = True
elif tok == OP and value == '(':
if in_def:
# Avoid false positives for declarations such as:
# def gettext(arg='message'):
in_def = False
continue
if funcname:
call_stack.append(lineno)
elif in_def and tok == OP and value == '(':
# Avoid false positives for declarations such as:
# def gettext(arg='message'):
in_def = False
continue
elif funcname and tok == OP and (value == '(' or value == '['):
call_stack.append(lineno)
elif in_def and tok == OP and value == ':':
# End of a class definition without parens
in_def = False
Expand Down Expand Up @@ -683,7 +682,7 @@ def extract_python(

elif tok != NL and not message_lineno:
message_lineno = lineno
elif len(call_stack) > 1 and tok == OP and value == ')':
elif len(call_stack) > 1 and tok == OP and (value == ')' or value == ']'):
call_stack.pop()
elif funcname and not call_stack:
funcname = None
Expand Down