Skip to content

Commit 7119dc6

Browse files
SONARPY-2362 Document no issue on S6542 when inheriting from annotated class member (#2174)
1 parent 4e4d5b9 commit 7119dc6

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

python-checks/src/test/resources/checks/useOfAnyAsTypeHintCheck/useOfAnyAsTypeHint.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,11 @@ def return_type_check(self, text) -> Any: # Compliant
118118
@my_annotation[42]
119119
def some_annotated_method(self, text: Any): # Noncompliant
120120
...
121+
122+
from typing import Callable
123+
class LocalClassWithAnnotatedMember:
124+
my_member: Callable[[Any],Any] # No issue on nested values of "Callable"
125+
126+
class LocalClassChild(LocalClassWithAnnotatedMember):
127+
def my_member(self, param: Any) -> Any: # OK, defined in parent
128+
...

python-checks/src/test/resources/checks/useOfAnyAsTypeHintCheck/useOfAnyAsTypeHintImported.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
class ImportedParentWithoutMetaClass: ...
44

55
class ImportedParentWithMetaClass(metaclass=ABCMeta): ...
6+
7+
from typing import Callable
8+
class MyClassWithAnnotatedMember:
9+
my_member: Callable[[Any],Any] # No issue on nested values of "Callable"

python-checks/src/test/resources/checks/useOfAnyAsTypeHintCheck/useOfAnyAsTypeHintImporting.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any
22
from abc import ABCMeta
3-
from useOfAnyAsTypeHintImported import ImportedParentWithoutMetaClass, ImportedParentWithMetaClass
3+
from useOfAnyAsTypeHintImported import ImportedParentWithoutMetaClass, ImportedParentWithMetaClass, MyClassWithAnnotatedMember
44

55
class LocalParentWithMetaClass(metaclass=ABCMeta): ...
66

@@ -14,3 +14,7 @@ def imported_inherited_foo(self) -> Any: # Noncompliant
1414
class ImportedWithMetaClassInherited(ImportedParentWithMetaClass):
1515
def imported_inherited_foo(self) -> Any: # Noncompliant
1616
...
17+
18+
class MyChild(MyClassWithAnnotatedMember):
19+
def my_member(self, param: Any) -> Any: # OK, defined in parent
20+
...

0 commit comments

Comments
 (0)