From a7ce426c01810e6001b1dfa91c829bad3ce99a7a Mon Sep 17 00:00:00 2001 From: Guillaume Dequenne Date: Tue, 26 Nov 2024 09:42:18 +0100 Subject: [PATCH] SONARPY-2363 Document no issue on S1172 when inheriting from annotated class member (#2175) --- .../unusedFunctionParameter/unusedFunctionParameter.py | 9 +++++++++ .../unusedFunctionParameterImport.py | 5 ++++- .../unusedFunctionParameterImported.py | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/python-checks/src/test/resources/checks/unusedFunctionParameter/unusedFunctionParameter.py b/python-checks/src/test/resources/checks/unusedFunctionParameter/unusedFunctionParameter.py index 153d027936..7dbdd14d9c 100644 --- a/python-checks/src/test/resources/checks/unusedFunctionParameter/unusedFunctionParameter.py +++ b/python-checks/src/test/resources/checks/unusedFunctionParameter/unusedFunctionParameter.py @@ -201,3 +201,12 @@ class FakeMetaclass(type): class ClassWithFakeMetaClass(metaclass=FakeMetaclass): def execute(self, name): print("Execute") + + +from typing import Callable +class LocalClassWithAnnotatedMember: + my_member: Callable[[str, int],str] + +class LocalClassChild(LocalClassWithAnnotatedMember): + def my_member(self, param, other_param): # OK, respecting contract defined in parent + print("Execute") diff --git a/python-checks/src/test/resources/checks/unusedFunctionParameter/unusedFunctionParameterImport.py b/python-checks/src/test/resources/checks/unusedFunctionParameter/unusedFunctionParameterImport.py index 0541b5bfbe..f9e9d7980a 100644 --- a/python-checks/src/test/resources/checks/unusedFunctionParameter/unusedFunctionParameterImport.py +++ b/python-checks/src/test/resources/checks/unusedFunctionParameter/unusedFunctionParameterImport.py @@ -1,4 +1,4 @@ -from unusedFunctionParameterImported import ImportedParent, ParentWithDuplicatedParent +from unusedFunctionParameterImported import ImportedParent, ParentWithDuplicatedParent, MyClassWithAnnotatedMember class ChildFromImported(ImportedParent): @@ -16,3 +16,6 @@ class ChildFromDuplicated(ParentWithDuplicatedParent): def do_something(self, a): # FN SONARPY-1829 ChildFromDuplicated has an unresolved type hierarchy, because of the duplicated parent classes return compute() +class MyChild(MyClassWithAnnotatedMember): + def my_member(self, param, other_param): # OK, respecting contract defined in parent + return compute() diff --git a/python-checks/src/test/resources/checks/unusedFunctionParameter/unusedFunctionParameterImported.py b/python-checks/src/test/resources/checks/unusedFunctionParameter/unusedFunctionParameterImported.py index 83be1ded3c..68585fac36 100644 --- a/python-checks/src/test/resources/checks/unusedFunctionParameter/unusedFunctionParameterImported.py +++ b/python-checks/src/test/resources/checks/unusedFunctionParameter/unusedFunctionParameterImported.py @@ -10,3 +10,7 @@ class DuplicatedParent: class ParentWithDuplicatedParent(DuplicatedParent): ... + +from typing import Callable +class MyClassWithAnnotatedMember: + my_member: Callable[[str, int],str]