Skip to content

Commit

Permalink
SONARPY-2306 Support annotated return type information conversion fro…
Browse files Browse the repository at this point in the history
…m PythonType to FunctionDescriptor
  • Loading branch information
maksim-grebeniuk-sonarsource committed Nov 6, 2024
1 parent 7baa415 commit 1b9e88a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ private static Descriptor convert(String moduleFqn, FunctionType type) {
.filter(Objects::nonNull)
.toList();

var annotatedReturnTypeName = typeFqn(moduleFqn, type.returnType());

// Using FunctionType#name and FunctionType#fullyQualifiedName instead of symbol is only accurate if the function has not been reassigned
// This logic should be revisited when tackling SONARPY-2285
return new FunctionDescriptor(type.name(), type.fullyQualifiedName(),
Expand All @@ -105,7 +107,7 @@ private static Descriptor convert(String moduleFqn, FunctionType type) {
decorators,
type.hasDecorators(),
type.definitionLocation().orElse(null),
null,
annotatedReturnTypeName,
null
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ void testConvertFunctionTypeWithoutDecorator() {
assertThat(functionDescriptor.isAsynchronous()).isTrue();
assertThat(functionDescriptor.isInstanceMethod()).isTrue();

// TODO SONARPY-2223 support for return type is missing in FunctionType
assertThat(functionDescriptor.annotatedReturnTypeName()).isNull();

// TODO SONARPY-2223 support for type annotation is missing in FunctionType
assertThat(functionDescriptor.annotatedReturnTypeName()).isEqualTo("float");
assertThat(functionDescriptor.typeAnnotationDescriptor()).isNull();

assertThat(functionDescriptor.hasDecorators()).isTrue();
Expand Down

0 comments on commit 1b9e88a

Please sign in to comment.