Skip to content

Commit fadb4c7

Browse files
SONARPY-949 S5756 (NonCallableCalled): avoid reporting on typeshed sy… (#1030)
1 parent ff4d92b commit fadb4c7

File tree

4 files changed

+7
-36
lines changed

4 files changed

+7
-36
lines changed

its/ruling/src/test/resources/expected/python-S5756.json

Lines changed: 0 additions & 34 deletions
This file was deleted.

python-checks/src/test/resources/checks/nonCallableCalled.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ def member_access():
6666
my_callable.non_callable = 42
6767
my_callable.non_callable() # FN
6868

69-
def types_from_typeshed():
69+
def types_from_typeshed(foo):
7070
from math import acos
71+
from functools import wraps
7172
acos(42)() # Noncompliant {{Fix this call; this expression has type float and it is not callable.}}
7273
# ^^^^^^^^
74+
wraps(func)(foo) # OK, wraps returns a Callable
7375

7476
def with_metaclass():
7577
class Factory: ...

python-frontend/src/main/java/org/sonar/python/types/InferredTypes.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,10 @@ public static InferredType fromTypeshedProtobuf(SymbolsProtos.Type type) {
156156
String typeName = type.getFullyQualifiedName();
157157
return typeName.isEmpty() ? anyType() : runtimeType(TypeShed.symbolWithFQN(typeName));
158158
case TYPE_ALIAS:
159-
case CALLABLE:
160159
return fromTypeshedProtobuf(type.getArgs(0));
160+
case CALLABLE:
161+
// this should be handled as a function type - see SONARPY-953
162+
return anyType();
161163
case UNION:
162164
return union(type.getArgsList().stream().map(InferredTypes::fromTypeshedProtobuf));
163165
case TUPLE:

python-frontend/src/test/java/org/sonar/python/types/InferredTypesTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ public void test_type_from_protobuf() throws TextFormat.ParseException {
359359
"fully_qualified_name: \"mod.t\""
360360
))
361361
.isEqualTo(InferredTypes.or(STR, INT));
362+
assertThat(protobufType("kind: CALLABLE")).isEqualTo(anyType());
362363
}
363364

364365
private static InferredType protobufType(String protobuf) throws TextFormat.ParseException {

0 commit comments

Comments
 (0)