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

fix qualified name get bug #669

Merged
merged 2 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion libcst/metadata/scope_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,10 @@ def get_qualified_names_for(self, full_name: str) -> Set[QualifiedName]:
if eval_alias is not None:
as_name = eval_alias
if full_name.startswith(as_name):
remaining_name = full_name.split(as_name, 1)[1].lstrip(".")
remaining_name = full_name.split(as_name, 1)[1]
if remaining_name and not remaining_name.startswith("."):
continue
remaining_name = remaining_name.lstrip(".")
results.add(
QualifiedName(
f"{real_name}.{remaining_name}"
Expand Down
19 changes: 19 additions & 0 deletions libcst/metadata/tests/test_scope_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,25 @@ class C:
{QualifiedName("f4.<locals>.f5.<locals>.C", QualifiedNameSource.LOCAL)},
)

def test_get_qualified_names_for_the_same_prefix(self) -> None:
m, scopes = get_scope_metadata_provider(
"""
from a import b, bc
bc()
"""
)
call = ensure_type(
ensure_type(
ensure_type(m.body[1], cst.SimpleStatementLine).body[0], cst.Expr
).value,
cst.Call,
)
module_scope = scopes[m]
self.assertEqual(
module_scope.get_qualified_names_for(call.func),
{QualifiedName("a.bc", QualifiedNameSource.IMPORT)},
)

def test_get_qualified_names_for_dotted_imports(self) -> None:
m, scopes = get_scope_metadata_provider(
"""
Expand Down