Skip to content
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-2360 Add unit test case on S5655 when compared types has decorators #2173

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions python-checks/src/test/resources/checks/argumentType.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,14 @@ class EnumA(Enum):
C = 3

len(EnumA)

Copy link
Contributor

Choose a reason for hiding this comment

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

To be more explicit about the scope of the ticket, I suggest to add a more general test case.
I was going to propose this test but I 'm not able to raise the issue with it. Any idea why?

class AnotherClass:
  x: int
  y: float

@decorator
class DecoratedClass:
  x : int

def decorated_class_expected(data: DecoratedClass): ...

data = AnotherClass()
# FP SONARPY-2359
decorated_class_expected(data)  # Noncompliant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cause in this example it compares AnotherClass to be compatible with DecoratedClass and since it has member x as DecoratedClass has - it says that it is compatible type

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, thanks

import dataclasses
@dataclasses.dataclass
class DecoratedDataClass:
x : int

def decorated_dataclass_expected(data: DecoratedDataClass): ...
data = dataclasses.replace(DecoratedDataClass(42))

# FP SONARPY-2359
decorated_dataclass_expected(data) # Noncompliant
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
decorated_dataclass_expected(data) # Noncompliant
decorated_dataclass_expected(data) # Noncompliant