From 4c7ff620dd6760542fd6c21d2f6fcee3f309a1da Mon Sep 17 00:00:00 2001 From: Maksim Grebeniuk Date: Thu, 21 Nov 2024 13:23:11 +0100 Subject: [PATCH 1/3] SONARPY-2360 Add unit test case on S5655 when compared types has decorators --- .../src/test/resources/checks/argumentType.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/python-checks/src/test/resources/checks/argumentType.py b/python-checks/src/test/resources/checks/argumentType.py index 560ad911c7..4ae5192454 100644 --- a/python-checks/src/test/resources/checks/argumentType.py +++ b/python-checks/src/test/resources/checks/argumentType.py @@ -267,3 +267,16 @@ class EnumA(Enum): C = 3 len(EnumA) + +def fp_decorated_types(): + import dataclasses + + @dataclasses.dataclass + class DecoratedClass: + x : int + + def decorated_type_expecting_foo(data: DecoratedClass): ... + + data = dataclasses.replace(...) + # FP SONARPY-2359 + decorated_type_expecting_foo(data) # Noncompliant From 1b5c18207f8b1cc01bed6c69d520bee52fbd0bbf Mon Sep 17 00:00:00 2001 From: Maksim Grebeniuk Date: Thu, 21 Nov 2024 14:46:51 +0100 Subject: [PATCH 2/3] CR fix --- python-checks/src/test/resources/checks/argumentType.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python-checks/src/test/resources/checks/argumentType.py b/python-checks/src/test/resources/checks/argumentType.py index 4ae5192454..63b9f310af 100644 --- a/python-checks/src/test/resources/checks/argumentType.py +++ b/python-checks/src/test/resources/checks/argumentType.py @@ -270,13 +270,12 @@ class EnumA(Enum): def fp_decorated_types(): import dataclasses - @dataclasses.dataclass class DecoratedClass: x : int def decorated_type_expecting_foo(data: DecoratedClass): ... + data = dataclasses.replace(DecoratedClass(42)) - data = dataclasses.replace(...) # FP SONARPY-2359 decorated_type_expecting_foo(data) # Noncompliant From da51d7d485234dbb76c9264a1531280133f6ca51 Mon Sep 17 00:00:00 2001 From: Maksim Grebeniuk Date: Thu, 21 Nov 2024 15:23:12 +0100 Subject: [PATCH 3/3] CR fix 2 --- .../src/test/resources/checks/argumentType.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/python-checks/src/test/resources/checks/argumentType.py b/python-checks/src/test/resources/checks/argumentType.py index 63b9f310af..c682318f67 100644 --- a/python-checks/src/test/resources/checks/argumentType.py +++ b/python-checks/src/test/resources/checks/argumentType.py @@ -268,14 +268,13 @@ class EnumA(Enum): len(EnumA) -def fp_decorated_types(): - import dataclasses - @dataclasses.dataclass - class DecoratedClass: - x : int +import dataclasses +@dataclasses.dataclass +class DecoratedDataClass: + x : int - def decorated_type_expecting_foo(data: DecoratedClass): ... - data = dataclasses.replace(DecoratedClass(42)) +def decorated_dataclass_expected(data: DecoratedDataClass): ... +data = dataclasses.replace(DecoratedDataClass(42)) - # FP SONARPY-2359 - decorated_type_expecting_foo(data) # Noncompliant +# FP SONARPY-2359 +decorated_dataclass_expected(data) # Noncompliant \ No newline at end of file