diff --git a/python/src/com/jetbrains/python/psi/types/PyTypeChecker.java b/python/src/com/jetbrains/python/psi/types/PyTypeChecker.java index e181ce5cb582..70b2bcd91259 100644 --- a/python/src/com/jetbrains/python/psi/types/PyTypeChecker.java +++ b/python/src/com/jetbrains/python/psi/types/PyTypeChecker.java @@ -860,6 +860,9 @@ public class PyTypeChecker { if (type instanceof PyStructuralType && ((PyStructuralType)type).isInferredFromUsages()) { return true; } + if (type instanceof PyGenericType) { + return ((PyGenericType)type).isDefinition(); + } return false; } diff --git a/python/testData/inspections/PyCallingNonCallableInspection/explicitClassObjectTypeAnnotation.py b/python/testData/inspections/PyCallingNonCallableInspection/explicitClassObjectTypeAnnotation.py new file mode 100644 index 000000000000..23be3996c820 --- /dev/null +++ b/python/testData/inspections/PyCallingNonCallableInspection/explicitClassObjectTypeAnnotation.py @@ -0,0 +1,10 @@ +from typing import Type + + +class MyClass(object): + pass + + +def func(param): + # type: (Type[MyClass]) -> MyClass + param() diff --git a/python/testData/inspections/PyCallingNonCallableInspection/genericClassObjectTypeAnnotation.py b/python/testData/inspections/PyCallingNonCallableInspection/genericClassObjectTypeAnnotation.py new file mode 100644 index 000000000000..46013aa4b133 --- /dev/null +++ b/python/testData/inspections/PyCallingNonCallableInspection/genericClassObjectTypeAnnotation.py @@ -0,0 +1,13 @@ +from typing import TypeVar, Type + + +class User: + pass + + +U = TypeVar('U', bound=User) + + +def new_user(user_class): + # type: (Type[U]) -> U + return user_class() diff --git a/python/testSrc/com/jetbrains/python/inspections/PyCallingNonCallableInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyCallingNonCallableInspectionTest.java index a197ca87b0bb..0a08bba14c71 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyCallingNonCallableInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyCallingNonCallableInspectionTest.java @@ -113,6 +113,16 @@ public class PyCallingNonCallableInspectionTest extends PyInspectionTestCase { doMultiFileTest(); } + // PY-24161 + public void testGenericClassObjectTypeAnnotation() { + doTest(); + } + + // PY-24161 + public void testExplicitClassObjectTypeAnnotation() { + doTest(); + } + @NotNull @Override protected Class getInspectionClass() {