Skip to content

Commit 01940a8

Browse files
Fix double import FQN (#1363)
1 parent 45984b3 commit 01940a8

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

python-frontend/src/main/java/org/sonar/python/semantic/Scope.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void addImportedSymbol(Name nameTree, @CheckForNull String fullyQualifiedName, S
202202
globalSymbol = globalSymbol != null ? copySymbol(symbolName, globalSymbol) : null;
203203
}
204204
if (globalSymbol == null || isExistingSymbol(symbolName)) {
205-
addBindingUsage(nameTree, Usage.Kind.IMPORT, fullyQualifiedName);
205+
addBindingUsage(nameTree, Usage.Kind.IMPORT, globalSymbol != null ? globalSymbol.fullyQualifiedName() : fullyQualifiedName);
206206
} else {
207207
this.symbols.add(globalSymbol);
208208
symbolsByName.put(symbolName, globalSymbol);

python-frontend/src/test/java/org/sonar/python/semantic/FullyQualifiedNameTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,15 @@ public void fqn_of_inherited_method_with_import() {
610610
assertThat(qualifiedExpression.symbol().fullyQualifiedName()).isNull();
611611
}
612612

613+
@Test
614+
public void fqn_resolution_works_with_double_import() {
615+
FileInput tree = parse(
616+
"from flask import request, request",
617+
"request.cookies.get('a')"
618+
);
619+
assertNameAndQualifiedName(tree, "get", "flask.globals.request.cookies.get");
620+
}
621+
613622
private void assertNameAndQualifiedName(FileInput tree, String name, @Nullable String qualifiedName) {
614623
CallExpression callExpression = getCallExpression(tree);
615624
assertThat(callExpression.calleeSymbol()).isNotNull();

0 commit comments

Comments
 (0)