Skip to content

Commit 0424db1

Browse files
SONARPY-1257 fix quality flaws (#1365)
1 parent 19db2c9 commit 0424db1

File tree

3 files changed

+19
-33
lines changed

3 files changed

+19
-33
lines changed

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,17 @@ public abstract class AbstractUnreadPrivateMembersCheck extends PythonSubscripti
3838
@Override
3939
public void initialize(Context context) {
4040
String memberPrefix = memberPrefix();
41-
context.registerSyntaxNodeConsumer(CLASSDEF, ctx -> {
42-
Optional.of(ctx.syntaxNode())
43-
.map(ClassDef.class::cast)
44-
// avoid checking for classes with decorators since it is impossible to analyze its final behavior
45-
.filter(classDef -> classDef.decorators().isEmpty())
46-
.map(TreeUtils::getClassSymbolFromDef)
47-
.map(ClassSymbol::declaredMembers)
48-
.stream()
49-
.flatMap(Collection::stream)
50-
.filter(s -> s.name().startsWith(memberPrefix) && !s.name().endsWith("__") && equalsToKind(s) && isNeverRead(s))
51-
.filter(Predicate.not(this::isException))
52-
.forEach(symbol -> reportIssue(ctx, symbol));
53-
});
41+
context.registerSyntaxNodeConsumer(CLASSDEF, ctx -> Optional.of(ctx.syntaxNode())
42+
.map(ClassDef.class::cast)
43+
// avoid checking for classes with decorators since it is impossible to analyze its final behavior
44+
.filter(classDef -> classDef.decorators().isEmpty())
45+
.map(TreeUtils::getClassSymbolFromDef)
46+
.map(ClassSymbol::declaredMembers)
47+
.stream()
48+
.flatMap(Collection::stream)
49+
.filter(s -> s.name().startsWith(memberPrefix) && !s.name().endsWith("__") && equalsToKind(s) && isNeverRead(s))
50+
.filter(Predicate.not(this::isException))
51+
.forEach(symbol -> reportIssue(ctx, symbol)));
5452
}
5553

5654
protected boolean isException(Symbol symbol) {

python-checks/src/main/java/org/sonar/python/checks/cdk/CdkUtils.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -290,19 +290,6 @@ public SubscriptionContext ctx() {
290290
}
291291
}
292292

293-
/**
294-
* In the case of unpacking expression, we cannot generate flows at the moment.
295-
* However, to avoid a wrong interpretation of the unpacked expression in the context of absent arguments,
296-
* an alternative dummy must be returned, which should not lead to false positives.
297-
* The resolving of such expressions can be improved by <a href="https://sonarsource.atlassian.net/browse/SONARPY-1164">SONARPY-1164</a> if necessary.
298-
*/
299-
static class UnresolvedExpressionFlow extends ExpressionFlow {
300-
301-
private UnresolvedExpressionFlow(SubscriptionContext ctx) {
302-
super(ctx, new LinkedList<>());
303-
}
304-
}
305-
306293
/**
307294
* Dataclass to store a resolved KeyValuePair structure
308295
*/

python-frontend/src/main/java/org/sonar/python/semantic/BuiltinSymbols.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ private BuiltinSymbols() {
3030
// empty constructor
3131
}
3232

33+
34+
public static final String CLASS_METHOD_DECORATOR = "classmethod";
35+
public static final String STATIC_METHOD_DECORATOR = "staticmethod";
36+
3337
/**
3438
* See https://docs.python.org/3/library/constants.html#built-in-consts
3539
*/
@@ -70,7 +74,7 @@ private BuiltinSymbols() {
7074
"enumerate",
7175
"input",
7276
"oct",
73-
"staticmethod",
77+
STATIC_METHOD_DECORATOR,
7478
"bool",
7579
"eval",
7680
"int",
@@ -101,7 +105,7 @@ private BuiltinSymbols() {
101105
"list",
102106
"range",
103107
"vars",
104-
"classmethod",
108+
CLASS_METHOD_DECORATOR,
105109
"getattr",
106110
"locals",
107111
"repr",
@@ -124,7 +128,7 @@ private BuiltinSymbols() {
124128
"divmod",
125129
"input",
126130
"open",
127-
"staticmethod",
131+
STATIC_METHOD_DECORATOR,
128132
"all",
129133
"enumerate",
130134
"int",
@@ -165,7 +169,7 @@ private BuiltinSymbols() {
165169
"long",
166170
"reload",
167171
"vars",
168-
"classmethod",
172+
CLASS_METHOD_DECORATOR,
169173
"getattr",
170174
"map",
171175
"repr",
@@ -339,8 +343,5 @@ public static Set<String> all() {
339343
return all;
340344
}
341345

342-
public static final String CLASS_METHOD_DECORATOR = "classmethod";
343-
public static final String STATIC_METHOD_DECORATOR = "staticmethod";
344-
345346
public static final Set<String> STATIC_AND_CLASS_METHOD_DECORATORS = Set.of(CLASS_METHOD_DECORATOR, STATIC_METHOD_DECORATOR);
346347
}

0 commit comments

Comments
 (0)