Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[scope] remove iter call to be more efficient #302

Merged
merged 1 commit into from
May 28, 2020
Merged
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
20 changes: 10 additions & 10 deletions libcst/metadata/scope_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from typing import (
Collection,
Dict,
Iterable,
Iterator,
List,
Mapping,
Expand Down Expand Up @@ -607,22 +606,23 @@ class ComprehensionScope(LocalScope):
# each string has the corresponding CSTNode attached to it
def _gen_dotted_names(
node: Union[cst.Attribute, cst.Name]
) -> Iterable[Tuple[str, Union[cst.Attribute, cst.Name]]]:
) -> Iterator[Tuple[str, Union[cst.Attribute, cst.Name]]]:
if isinstance(node, cst.Name):
yield (node.value, node)
yield node.value, node
else:
value = node.value
if not isinstance(value, (cst.Attribute, cst.Name)):
# this is not an import
return
name_values = iter(_gen_dotted_names(value))
next_pair = next(name_values, None)
if next_pair is None:
name_values = _gen_dotted_names(value)
try:
next_name, next_node = next(name_values)
except StopIteration:
return
(next_name, next_node) = next_pair
yield (f"{next_name}.{node.attr.value}", node)
yield (next_name, next_node)
yield from name_values
else:
yield f"{next_name}.{node.attr.value}", node
yield next_name, next_node
yield from name_values


class ScopeVisitor(cst.CSTVisitor):
Expand Down