diff --git a/python-checks/src/test/java/org/sonar/python/checks/UseOfAnyAsTypeHintCheckTest.java b/python-checks/src/test/java/org/sonar/python/checks/UseOfAnyAsTypeHintCheckTest.java index abc837667c..d1bf2d0f94 100644 --- a/python-checks/src/test/java/org/sonar/python/checks/UseOfAnyAsTypeHintCheckTest.java +++ b/python-checks/src/test/java/org/sonar/python/checks/UseOfAnyAsTypeHintCheckTest.java @@ -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()); @@ -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() + ); + } } diff --git a/python-checks/src/test/resources/checks/useOfAnyAsTypeHintImported.py b/python-checks/src/test/resources/checks/useOfAnyAsTypeHintImported.py new file mode 100644 index 0000000000..402727afa6 --- /dev/null +++ b/python-checks/src/test/resources/checks/useOfAnyAsTypeHintImported.py @@ -0,0 +1,3 @@ +from abc import ABCMeta + +class ImportedParentWithMetaClass(metaclass=ABCMeta): ... diff --git a/python-checks/src/test/resources/checks/useOfAnyAsTypeHintImporting.py b/python-checks/src/test/resources/checks/useOfAnyAsTypeHintImporting.py new file mode 100644 index 0000000000..554453bcb4 --- /dev/null +++ b/python-checks/src/test/resources/checks/useOfAnyAsTypeHintImporting.py @@ -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 + ...