Skip to content

SONARPY-743 RSPEC-5864 Calling a non-callable type#828

Merged
andrea-guarino-sonarsource merged 3 commits intomasterfrom
SONARPY-743
Aug 12, 2020
Merged

SONARPY-743 RSPEC-5864 Calling a non-callable type#828
andrea-guarino-sonarsource merged 3 commits intomasterfrom
SONARPY-743

Conversation

@andrea-guarino-sonarsource
Copy link
Copy Markdown
Contributor

No description provided.

@andrea-guarino-sonarsource andrea-guarino-sonarsource force-pushed the SONARPY-743 branch 9 times, most recently from b4c5ed8 to 5f6ab80 Compare August 12, 2020 11:27
@andrea-guarino-sonarsource andrea-guarino-sonarsource marked this pull request as ready for review August 12, 2020 11:27
Copy link
Copy Markdown
Contributor

@guillaume-dequenne guillaume-dequenne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, minor comments.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you mean returns true here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed :) Thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rename to declaresMember to be consistent with the way we named the other methods.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I named it like this to be consistent with resolveMember. I think we're already inconsistent (we have isCompatibleWith), not sure which one we should prefer

Comment on lines 2 to 5
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice issues 😃

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused by type.canHaveMember("__call__"). Is this a way of asserting that we're dealing with a DeclaredType? It feels a bit indirect and implementation dependent to me.

That said I'm not sure I have a suggestion for a more direct check (checking directly that type is an instance of DeclaredType should do the trick but it might be heavy-handed...but then again this rule is tailored for DeclaredType only so it might make sense)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the idea is to avoid raising twice the same issue (one for the bug rule and one for code smell).

I think we cannot check only for type being instance of DeclaredType. It could also be a UnionType containing DeclaredType and we still want to raise an issue.
I agree it's a bit indirect; if you agree I'll add a comment explaining this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following the fix on copyWithoutUsages, I think you can remove this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we should consider this a FN. We should raise a code smell for the impossible + operation above, though, then we shouldn't be able to resolve a type for z I assume.
I believe this one would be a FN though (we should infer a DeclaredType of str for y):

def foo(x: str):
  y = x + "hello"
  y() # FN

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes indeed, I agree

@sonarsource-next
Copy link
Copy Markdown

Kudos, SonarQube Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

97.3% 97.3% Coverage
0.0% 0.0% Duplication

@andrea-guarino-sonarsource andrea-guarino-sonarsource merged commit 970120e into master Aug 12, 2020
@andrea-guarino-sonarsource andrea-guarino-sonarsource deleted the SONARPY-743 branch August 12, 2020 14:23
hashicorp-vault-sonar-prod Bot pushed a commit that referenced this pull request Feb 3, 2026
GitOrigin-RevId: afe2cf9a7e9b8d88d79321adda5bc9aa2bdbb4b3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants