Skip to content

Commit 79edce3

Browse files
SONARPY-986 S5644 should not raise issues on "collections" symbols (#1085)
1 parent 7bb5c43 commit 79edce3

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

python-checks/src/main/java/org/sonar/python/checks/ItemOperationsTypeCheck.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public boolean isValidSubscription(Expression subscriptionObject, String require
5757
}
5858
if (subscriptionObject instanceof HasSymbol) {
5959
Symbol symbol = ((HasSymbol) subscriptionObject).symbol();
60-
if (symbol == null || isTypingSymbol(symbol)) {
60+
if (symbol == null || isTypingOrCollectionsSymbol(symbol)) {
6161
return true;
6262
}
6363
if (symbol.is(FUNCTION, CLASS)) {
@@ -81,10 +81,10 @@ public String message(@Nullable String name, String missingMethod) {
8181
return String.format("Fix this code; this expression does not have a \"%s\" method.", missingMethod);
8282
}
8383

84-
private static boolean isTypingSymbol(Symbol symbol) {
84+
private static boolean isTypingOrCollectionsSymbol(Symbol symbol) {
8585
String fullyQualifiedName = symbol.fullyQualifiedName();
8686
// avoid FP for typing symbols like 'Awaitable[None]'
87-
return fullyQualifiedName != null && fullyQualifiedName.startsWith("typing");
87+
return fullyQualifiedName != null && (fullyQualifiedName.startsWith("typing") || fullyQualifiedName.startsWith("collections"));
8888
}
8989

9090
private static boolean canHaveMethod(Symbol symbol, String requiredMethod, @Nullable String classRequiredMethod) {

python-checks/src/test/resources/checks/itemOperationsTypeCheck/itemOperations_getitem.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ def my_func() -> Awaitable[bool]: ... # OK
165165
def my_other_func(arg: Awaitable[bool]): ... # OK
166166
x: Awaitable[bool] # OK
167167
Awaitable[None]
168+
from collections import Set
169+
CustomSet = Set[str]
168170

169171
def decorated_classes():
170172
import enum

0 commit comments

Comments
 (0)