-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SONARPY-2229 Fix FP on S2201 when instantiating the result of a type call #2088
Conversation
8e4545c
to
cb92bfb
Compare
cb92bfb
to
fdd458b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to our discussion, I think it would make sense to change the type checks in TypeCheckBuilder
to either check if a type is an instance of a
or is a
.
Since this PR is using isTypeWithName
introducing this change for this method would make sense.
Maybe it also would make sense to align the behaviour of isInstanceOf
, so that checking with isTypeWithName
checks for the type and isInstanceOf
if it is an instance of a type. Having (somewhat) uniform behaviour for the type checkers when it comes to union type would make the API easier to use. But this should probably be its separate PR.
.filter(f -> typeChecker.typeCheckBuilder().isTypeWithName(f).check(pythonType).equals(TriBool.TRUE)) | ||
.findFirst() | ||
.ifPresent(result -> ctx.addIssue(callExpression.callee(), String.format(MESSAGE_FORMAT, result))); | ||
if (typeChecker.typeCheckBuilder().isObjectType().check(pythonType) == TriBool.FALSE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think extracting this condition into its own method would help readability as it can be named
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I removed the condition altogether)
ad794ca
to
ba82d4d
Compare
Following our discussion, I instead added the |
ca15700
to
b357ae9
Compare
Quality Gate passedIssues Measures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
This is admittedly a very naive approach to fix this FP.
However, I believe that this deserves a broader discussion, considering SONARPY-2013 to allow for easier manipulation of type predicates.
I also considered adding a proper
PythonType#kind
API to avoid checking for instances. However, I feel this can still be done later if the need proves real.