@@ -198,16 +198,16 @@ private static Set<Symbol> searchTypeShedForModule(String moduleName) {
198
198
return new HashSet <>();
199
199
}
200
200
modulesInProgress .add (moduleName );
201
- Collection <Symbol > symbolsFromProtobuf = getSymbolsFromProtobufModule (moduleName ).values ();
202
- if (!symbolsFromProtobuf .isEmpty ()) {
203
- modulesInProgress .remove (moduleName );
204
- return new HashSet <>(symbolsFromProtobuf );
205
- }
206
201
Set <Symbol > customSymbols = new HashSet <>(getModuleSymbols (moduleName , CUSTOM_THIRD_PARTY , builtinGlobalSymbols ).values ());
207
202
if (!customSymbols .isEmpty ()) {
208
203
modulesInProgress .remove (moduleName );
209
204
return customSymbols ;
210
205
}
206
+ Collection <Symbol > symbolsFromProtobuf = getSymbolsFromProtobufModule (moduleName ).values ();
207
+ if (!symbolsFromProtobuf .isEmpty ()) {
208
+ modulesInProgress .remove (moduleName );
209
+ return new HashSet <>(symbolsFromProtobuf );
210
+ }
211
211
Set <Symbol > thirdPartySymbols = new HashSet <>(getModuleSymbols (moduleName , THIRD_PARTY_2AND3 , builtinGlobalSymbols ).values ());
212
212
if (thirdPartySymbols .isEmpty ()) {
213
213
thirdPartySymbols = commonSymbols (getModuleSymbols (moduleName , THIRD_PARTY_2 , builtinGlobalSymbols ),
@@ -283,12 +283,28 @@ private static Symbol disambiguateWithLatestPythonSymbol(Set<Symbol> alternative
283
283
return latestPythonSymbol ;
284
284
}
285
285
286
+
287
+ /**
288
+ * Returns stub symbols to be used by SonarSecurity.
289
+ * Ambiguous symbols that only contain class symbols are disambiguated with latest Python version.
290
+ */
286
291
public static Collection <Symbol > stubFilesSymbols () {
287
292
Set <Symbol > symbols = new HashSet <>(TypeShed .builtinSymbols ().values ());
288
- typeShedSymbols .values ().forEach (symbolsByFqn -> symbols .addAll (symbolsByFqn .values ()));
293
+ for (Map <String , Symbol > symbolsByFqn : typeShedSymbols .values ()) {
294
+ for (Symbol symbol : symbolsByFqn .values ()) {
295
+ symbols .add (isAmbiguousSymbolOfClasses (symbol ) ? disambiguateWithLatestPythonSymbol (((AmbiguousSymbol ) symbol ).alternatives ()) : symbol );
296
+ }
297
+ }
289
298
return symbols ;
290
299
}
291
300
301
+ private static boolean isAmbiguousSymbolOfClasses (Symbol symbol ) {
302
+ if (symbol .is (Symbol .Kind .AMBIGUOUS )) {
303
+ return ((AmbiguousSymbol ) symbol ).alternatives ().stream ().allMatch (s -> s .is (Symbol .Kind .CLASS ));
304
+ }
305
+ return false ;
306
+ }
307
+
292
308
static class ReturnTypeVisitor extends BaseTreeVisitor {
293
309
294
310
@ Override
0 commit comments