Skip to content

Commit

Permalink
SONARPY-1530 Fix FN and FP regarding the Ellipsis and the ellipsis ty…
Browse files Browse the repository at this point in the history
…pe. (#1619)
  • Loading branch information
Jeremi Do Dinh authored Oct 24, 2023
1 parent c7a5304 commit 4554af9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 0 additions & 3 deletions its/ruling/src/test/resources/expected/python-S5806.json
Original file line number Diff line number Diff line change
Expand Up @@ -658,9 +658,6 @@
836,
5816,
],
'project:tensorflow/python/ops/linalg_grad.py':[
61,
],
'project:tensorflow/python/ops/math_ops.py':[
751,
786,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class BuiltinShadowingAssignmentCheck extends PythonSubscriptionCheck {
public static final String RENAME_PREFIX = "_";
public static final String QUICK_FIX_MESSAGE_FORMAT = "Rename to " + RENAME_PREFIX+ " %s";
private final Map<Symbol, PreciseIssue> variableIssuesRaised = new HashMap<>();
public static final String ELLIPSIS = "ellipsis";

@Override
public void initialize(Context context) {
Expand Down Expand Up @@ -184,6 +185,10 @@ private boolean shouldReportIssue(Tree tree) {
}

private boolean isBuiltInName(Name name) {
// Workaround to fix the FP raised. A definite fix should be implemented as part of SONARPY-1531.
if (ELLIPSIS.equals(name.name())) {
return false;
}
return TypeShed.builtinSymbols().containsKey(name.name());
}
}
4 changes: 4 additions & 0 deletions python-checks/src/test/resources/checks/builtinShadowing.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ def redefine():
def iPython():
display = 42

def ellipsis_test():
ellipsis = "" # OK
Ellipsis = 42 # Noncompliant {{Rename this variable; it shadows a builtin.}}
ellipsis = "..." # OK

0 comments on commit 4554af9

Please sign in to comment.