mirror of
https://github.com/davidhalter/parso.git
synced 2026-05-19 23:10:16 +08:00
Use yield from where possible
This commit is contained in:
@@ -173,13 +173,11 @@ def _iter_definition_exprs_from_lists(exprlist):
|
|||||||
if child.children[0] == '(':
|
if child.children[0] == '(':
|
||||||
testlist_comp = child.children[1]
|
testlist_comp = child.children[1]
|
||||||
if testlist_comp.type == 'testlist_comp':
|
if testlist_comp.type == 'testlist_comp':
|
||||||
for expr in _iter_definition_exprs_from_lists(testlist_comp):
|
yield from _iter_definition_exprs_from_lists(testlist_comp)
|
||||||
yield expr
|
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
# It's a paren that doesn't do anything, like 1 + (1)
|
# It's a paren that doesn't do anything, like 1 + (1)
|
||||||
for c in check_expr(testlist_comp):
|
yield from check_expr(testlist_comp)
|
||||||
yield c
|
|
||||||
return
|
return
|
||||||
elif child.children[0] == '[':
|
elif child.children[0] == '[':
|
||||||
yield testlist_comp
|
yield testlist_comp
|
||||||
@@ -188,11 +186,9 @@ def _iter_definition_exprs_from_lists(exprlist):
|
|||||||
|
|
||||||
if exprlist.type in _STAR_EXPR_PARENTS:
|
if exprlist.type in _STAR_EXPR_PARENTS:
|
||||||
for child in exprlist.children[::2]:
|
for child in exprlist.children[::2]:
|
||||||
for c in check_expr(child): # Python 2 sucks
|
yield from check_expr(child)
|
||||||
yield c
|
|
||||||
else:
|
else:
|
||||||
for c in check_expr(exprlist): # Python 2 sucks
|
yield from check_expr(exprlist)
|
||||||
yield c
|
|
||||||
|
|
||||||
|
|
||||||
def _get_expr_stmt_definition_exprs(expr_stmt):
|
def _get_expr_stmt_definition_exprs(expr_stmt):
|
||||||
|
|||||||
@@ -528,14 +528,12 @@ def tokenize_lines(lines, version_info, start_pos=(1, 0), indents=None, is_first
|
|||||||
if indent_start > indents[-1]:
|
if indent_start > indents[-1]:
|
||||||
yield PythonToken(INDENT, '', spos, '')
|
yield PythonToken(INDENT, '', spos, '')
|
||||||
indents.append(indent_start)
|
indents.append(indent_start)
|
||||||
for t in dedent_if_necessary(indent_start):
|
yield from dedent_if_necessary(indent_start)
|
||||||
yield t
|
|
||||||
|
|
||||||
if not pseudomatch: # scan for tokens
|
if not pseudomatch: # scan for tokens
|
||||||
match = whitespace.match(line, pos)
|
match = whitespace.match(line, pos)
|
||||||
if new_line and paren_level == 0 and not fstring_stack:
|
if new_line and paren_level == 0 and not fstring_stack:
|
||||||
for t in dedent_if_necessary(match.end()):
|
yield from dedent_if_necessary(match.end())
|
||||||
yield t
|
|
||||||
pos = match.end()
|
pos = match.end()
|
||||||
new_line = False
|
new_line = False
|
||||||
yield PythonToken(
|
yield PythonToken(
|
||||||
@@ -556,13 +554,11 @@ def tokenize_lines(lines, version_info, start_pos=(1, 0), indents=None, is_first
|
|||||||
# We only want to dedent if the token is on a new line.
|
# We only want to dedent if the token is on a new line.
|
||||||
m = re.match(r'[ \f\t]*$', line[:start])
|
m = re.match(r'[ \f\t]*$', line[:start])
|
||||||
if m is not None:
|
if m is not None:
|
||||||
for t in dedent_if_necessary(m.end()):
|
yield from dedent_if_necessary(m.end())
|
||||||
yield t
|
|
||||||
if is_identifier(token):
|
if is_identifier(token):
|
||||||
yield PythonToken(NAME, token, spos, prefix)
|
yield PythonToken(NAME, token, spos, prefix)
|
||||||
else:
|
else:
|
||||||
for t in _split_illegal_unicode_name(token, spos, prefix):
|
yield from _split_illegal_unicode_name(token, spos, prefix)
|
||||||
yield t # yield from Python 2
|
|
||||||
elif initial in '\r\n':
|
elif initial in '\r\n':
|
||||||
if any(not f.allow_multiline() for f in fstring_stack):
|
if any(not f.allow_multiline() for f in fstring_stack):
|
||||||
# Would use fstring_stack.clear, but that's not available
|
# Would use fstring_stack.clear, but that's not available
|
||||||
|
|||||||
+5
-10
@@ -363,8 +363,7 @@ class Scope(PythonBaseNode, DocstringMixin):
|
|||||||
if element.type in names:
|
if element.type in names:
|
||||||
yield element
|
yield element
|
||||||
if element.type in _FUNC_CONTAINERS:
|
if element.type in _FUNC_CONTAINERS:
|
||||||
for e in scan(element.children):
|
yield from scan(element.children)
|
||||||
yield e
|
|
||||||
|
|
||||||
return scan(self.children)
|
return scan(self.children)
|
||||||
|
|
||||||
@@ -615,8 +614,7 @@ class Function(ClassOrFunc):
|
|||||||
else:
|
else:
|
||||||
yield element
|
yield element
|
||||||
else:
|
else:
|
||||||
for result in scan(nested_children):
|
yield from scan(nested_children)
|
||||||
yield result
|
|
||||||
|
|
||||||
return scan(self.children)
|
return scan(self.children)
|
||||||
|
|
||||||
@@ -630,8 +628,7 @@ class Function(ClassOrFunc):
|
|||||||
or element.type == 'keyword' and element.value == 'return':
|
or element.type == 'keyword' and element.value == 'return':
|
||||||
yield element
|
yield element
|
||||||
if element.type in _RETURN_STMT_CONTAINERS:
|
if element.type in _RETURN_STMT_CONTAINERS:
|
||||||
for e in scan(element.children):
|
yield from scan(element.children)
|
||||||
yield e
|
|
||||||
|
|
||||||
return scan(self.children)
|
return scan(self.children)
|
||||||
|
|
||||||
@@ -645,8 +642,7 @@ class Function(ClassOrFunc):
|
|||||||
or element.type == 'keyword' and element.value == 'raise':
|
or element.type == 'keyword' and element.value == 'raise':
|
||||||
yield element
|
yield element
|
||||||
if element.type in _RETURN_STMT_CONTAINERS:
|
if element.type in _RETURN_STMT_CONTAINERS:
|
||||||
for e in scan(element.children):
|
yield from scan(element.children)
|
||||||
yield e
|
|
||||||
|
|
||||||
return scan(self.children)
|
return scan(self.children)
|
||||||
|
|
||||||
@@ -1098,8 +1094,7 @@ class ExprStmt(PythonBaseNode, DocstringMixin):
|
|||||||
first = first.children[2]
|
first = first.children[2]
|
||||||
yield first
|
yield first
|
||||||
|
|
||||||
for operator in self.children[3::2]:
|
yield from self.children[3::2]
|
||||||
yield operator
|
|
||||||
|
|
||||||
|
|
||||||
class Param(PythonBaseNode):
|
class Param(PythonBaseNode):
|
||||||
|
|||||||
Reference in New Issue
Block a user