38
38
import org .sonar .python .semantic .FunctionSymbolImpl ;
39
39
import org .sonar .python .semantic .ProjectLevelSymbolTable ;
40
40
import org .sonar .python .semantic .v2 .converter .AnyDescriptorToPythonTypeConverter ;
41
- import org .sonar .python .types .InferredTypes ;
42
- import org .sonar .python .types .protobuf .SymbolsProtos ;
43
41
import org .sonar .python .types .v2 .ClassType ;
44
42
import org .sonar .python .types .v2 .FunctionType ;
45
43
import org .sonar .python .types .v2 .LazyTypeWrapper ;
46
44
import org .sonar .python .types .v2 .Member ;
47
45
import org .sonar .python .types .v2 .ModuleType ;
48
- import org .sonar .python .types .v2 .ObjectType ;
49
46
import org .sonar .python .types .v2 .ParameterV2 ;
50
47
import org .sonar .python .types .v2 .PythonType ;
51
- import org .sonar .python .types .v2 .SimpleTypeWrapper ;
52
48
import org .sonar .python .types .v2 .TypeOrigin ;
53
49
import org .sonar .python .types .v2 .TypeWrapper ;
54
50
import org .sonar .python .types .v2 .UnionType ;
@@ -131,7 +127,7 @@ private PythonType convertToFunctionType(FunctionSymbol symbol, Map<Symbol, Pyth
131
127
.map (this ::convertParameter )
132
128
.toList ();
133
129
134
- var returnType = getReturnTypeFromSymbol ( symbol ) ;
130
+ var returnType = PythonType . UNKNOWN ;
135
131
136
132
TypeOrigin typeOrigin = symbol .isStub () ? TypeOrigin .STUB : TypeOrigin .LOCAL ;
137
133
@@ -151,14 +147,6 @@ private PythonType convertToFunctionType(FunctionSymbol symbol, Map<Symbol, Pyth
151
147
return functionType ;
152
148
}
153
149
154
- private TypeWrapper getReturnTypeFromSymbol (FunctionSymbol symbol ) {
155
- var returnTypeFqns = getReturnTypeFqn (symbol );
156
- var returnTypeList = returnTypeFqns .stream ().map (lazyTypesContext ::getOrCreateLazyTypeWrapper ).map (ObjectType ::new ).toList ();
157
- //TODO Support type unions (SONARPY-2132)
158
- var type = returnTypeList .size () == 1 ? returnTypeList .get (0 ) : PythonType .UNKNOWN ;
159
- return new SimpleTypeWrapper (type );
160
- }
161
-
162
150
PythonType resolvePossibleLazyType (String fullyQualifiedName ) {
163
151
if (rootModule == null ) {
164
152
// If root module has not been created yet, return lazy type
@@ -243,59 +231,4 @@ private PythonType convertToType(Symbol symbol, Map<Symbol, PythonType> createdT
243
231
case OTHER -> PythonType .UNKNOWN ;
244
232
};
245
233
}
246
-
247
- private List <String > getReturnTypeFqn (FunctionSymbol symbol ) {
248
- List <String > fqnList = List .of ();
249
- if (symbol .annotatedReturnTypeName () != null && !OBJECT_TYPE_FQN .equals (symbol .annotatedReturnTypeName ())) {
250
- fqnList = List .of (symbol .annotatedReturnTypeName ());
251
- } else if (symbol instanceof FunctionSymbolImpl functionSymbol && functionSymbol .protobufReturnType () != null ) {
252
- var protoReturnType = functionSymbol .protobufReturnType ();
253
- fqnList = getSymbolTypeFqn (protoReturnType );
254
- }
255
- return fqnList ;
256
- }
257
-
258
- List <String > getSymbolTypeFqn (SymbolsProtos .Type type ) {
259
- if (OBJECT_TYPE_FQN .equals (type .getFullyQualifiedName ())) {
260
- return List .of ();
261
- }
262
- switch (type .getKind ()) {
263
- case INSTANCE :
264
- String typeName = type .getFullyQualifiedName ();
265
- // _SpecialForm is the type used for some special types, like Callable, Union, TypeVar, ...
266
- // It comes from CPython impl: https://github.com/python/cpython/blob/e39ae6bef2c357a88e232dcab2e4b4c0f367544b/Lib/typing.py#L439
267
- // This doesn't seem to be very precisely specified in typeshed, because it has special semantic.
268
- // To avoid FPs, we treat it as ANY
269
- if ("typing._SpecialForm" .equals (typeName )) {
270
- return List .of ();
271
- }
272
- typeName = typeName .replaceFirst ("^builtins\\ ." , "" );
273
- return typeName .isEmpty () ? List .of () : List .of (typeName );
274
- case TYPE :
275
- return List .of ("type" );
276
- case TYPE_ALIAS :
277
- return getSymbolTypeFqn (type .getArgs (0 ));
278
- case CALLABLE :
279
- // this should be handled as a function type - see SONARPY-953
280
- // Creates FPs with `sys.gettrace`
281
- return List .of ();
282
- case UNION :
283
- return type .getArgsList ().stream ().map (this ::getSymbolTypeFqn ).flatMap (Collection ::stream ).toList ();
284
- case TUPLE :
285
- return List .of ("tuple" );
286
- case NONE :
287
- return List .of ("NoneType" );
288
- case TYPED_DICT :
289
- return List .of ("dict" );
290
- case TYPE_VAR :
291
- return Optional .of (type )
292
- .filter (InferredTypes ::filterTypeVar )
293
- .map (SymbolsProtos .Type ::getFullyQualifiedName )
294
- .map (List ::of )
295
- .orElseGet (List ::of );
296
- default :
297
- return List .of ();
298
- }
299
- }
300
-
301
234
}
0 commit comments