SONARPY-751 Rule S5886: Function return types should be consistent with their type hint#825
SONARPY-751 Rule S5886: Function return types should be consistent with their type hint#825guillaume-dequenne merged 4 commits intomasterfrom
Conversation
a40ca18 to
2d67be6
Compare
aa107f6 to
690e40e
Compare
690e40e to
aa38974
Compare
aa38974 to
a10ddc5
Compare
andrea-guarino-sonarsource
left a comment
There was a problem hiding this comment.
LGTM, I left some minor comments
| @Beta | ||
| boolean isCompatibleWith(InferredType other); | ||
|
|
||
| @Beta |
There was a problem hiding this comment.
can you add a comment explaining why we're adding this API and how it differs from canBeOrExtend?
| Symbol symbol = ((Name) expression).symbol(); | ||
| if (symbol != null && "typing.Text".equals(symbol.fullyQualifiedName())) { | ||
| return InferredTypes.runtimeType(builtinSymbols.get("str")); | ||
| if (symbol != null ) { |
There was a problem hiding this comment.
minor: there is an extra space.
Why are we doing this? InferredTypes.runtimeType should already handle the case where symbol is null
There was a problem hiding this comment.
We still branch depending on symbol.fullyQualifiedName() right after so I think we still need the null check.
| else: | ||
| x = "hello" | ||
| return x # OK | ||
|
|
There was a problem hiding this comment.
I think we could add a test case:
def foo(cond) -> int:
if cond:
return 42
else:
return "hello"There was a problem hiding this comment.
There is a test case similar to this one on line 94-98, which does flag the str return as Noncompliant.
There was a problem hiding this comment.
ops sorry I missed it
443123c to
92eb475
Compare
|
Kudos, SonarQube Quality Gate passed! |
GitOrigin-RevId: 40db5dc813096f251eb1e54529891ae2544c5040
No description provided.