Skip to content

Commit

Permalink
Add maxsplit value in QualifiedName retrieval (Instagram#312)
Browse files Browse the repository at this point in the history
Maxsplit value to account for repeated letters in a QualifiedName
  • Loading branch information
josieesh authored Jun 11, 2020
1 parent dbcb5be commit cc7bb9d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libcst/metadata/scope_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def find_qualified_name_for_import_alike(
if eval_alias is not None:
as_name = eval_alias
if full_name.startswith(as_name):
remaining_name = full_name.split(as_name)[1].lstrip(".")
remaining_name = full_name.split(as_name, 1)[1].lstrip(".")
results.add(
QualifiedName(
f"{real_name}.{remaining_name}"
Expand Down
24 changes: 24 additions & 0 deletions libcst/metadata/tests/test_qualified_name_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,27 @@ def test_name_in_attribute(self) -> None:
)
eval = attr.attr
self.assertEqual(names[eval], set())

def test_repeated_values_in_qualified_name(self) -> None:
m, names = get_qualified_name_metadata_provider(
"""
import a
class Foo:
bar: a.aa.aaa
"""
)
foo = ensure_type(m.body[1], cst.ClassDef)
bar = ensure_type(
ensure_type(
ensure_type(foo.body, cst.IndentedBlock).body[0],
cst.SimpleStatementLine,
).body[0],
cst.AnnAssign,
)

annotation = ensure_type(bar.annotation, cst.Annotation)
attribute = ensure_type(annotation.annotation, cst.Attribute)

self.assertEqual(
names[attribute], {QualifiedName("a.aa.aaa", QualifiedNameSource.IMPORT)}
)

0 comments on commit cc7bb9d

Please sign in to comment.