Skip to content

Commit

Permalink
SONARPY-2330 Add unit test case on S6542 when a class is inherited fr…
Browse files Browse the repository at this point in the history
…om an imported class with a metaclass
  • Loading branch information
maksim-grebeniuk-sonarsource committed Nov 13, 2024
1 parent 4da8b75 commit d69535d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class UseOfAnyAsTypeHintCheckTest {
void useOfAny() {
PythonCheckVerifier.verify("src/test/resources/checks/useOfAnyAsTypeHint.py", new UseOfAnyAsTypeHintCheck());
}

@Test
void useOfTypingAny() {
PythonCheckVerifier.verify("src/test/resources/checks/useOftypingAnyAsTypeHint.py", new UseOfAnyAsTypeHintCheck());
Expand All @@ -42,4 +43,15 @@ void useOfUserDefinedTypeCalledAny() {
void useOfOverrideOrOverloadDecorator() {
PythonCheckVerifier.verify(List.of("src/test/resources/checks/useOfOverrideOrOverloadDecorator.py", "src/test/resources/checks/reexport_typing_overload_override.py"), new UseOfAnyAsTypeHintCheck());
}

@Test
void useOfAnyImpored() {
PythonCheckVerifier.verify(
List.of(
"src/test/resources/checks/useOfAnyAsTypeHintImported.py",
"src/test/resources/checks/useOfAnyAsTypeHintImporting.py"
),
new UseOfAnyAsTypeHintCheck()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from abc import ABCMeta

class ImportedParentWithMetaClass(metaclass=ABCMeta): ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import Any
from abc import ABCMeta
from useOfAnyAsTypeHintImported import ImportedParentWithMetaClass

class LocalParent: ...

class LocalParentWithMetaClass(metaclass=ABCMeta): ...

class LocalWithMetaClassInherited(LocalParentWithMetaClass):
def local_inherited_foo(self) -> Any: # Noncompliant
...

class ImportedWithMetaClassInherited(ImportedParentWithMetaClass):
def imported_inherited_foo(self) -> Any: # FN SONARPY-2331
...

0 comments on commit d69535d

Please sign in to comment.