diff --git a/python/src/com/jetbrains/python/codeInsight/typing/PyTypingInspectionExtension.kt b/python/src/com/jetbrains/python/codeInsight/typing/PyTypingInspectionExtension.kt index 938498a6edfb..01c4e61997a1 100644 --- a/python/src/com/jetbrains/python/codeInsight/typing/PyTypingInspectionExtension.kt +++ b/python/src/com/jetbrains/python/codeInsight/typing/PyTypingInspectionExtension.kt @@ -36,7 +36,7 @@ class PyTypingInspectionExtension : PyInspectionExtension() { private fun isGenericItselfOrDescendant(type: PyClassLikeType, context: TypeEvalContext): Boolean { return PyTypingTypeProvider.GENERIC_CLASSES.contains(type.classQName) || - type.getSuperClassTypes(context).any { PyTypingTypeProvider.GENERIC_CLASSES.contains(it.classQName) } + type.getAncestorTypes(context).any { PyTypingTypeProvider.GENERIC_CLASSES.contains(it.classQName) } } private fun isBuiltin(type: PyClassLikeType): Boolean { diff --git a/python/testData/inspections/PyUnresolvedReferencesInspection3K/typingGenericIndirectInheritorGetItem.py b/python/testData/inspections/PyUnresolvedReferencesInspection3K/typingGenericIndirectInheritorGetItem.py new file mode 100644 index 000000000000..9ac4f278ea56 --- /dev/null +++ b/python/testData/inspections/PyUnresolvedReferencesInspection3K/typingGenericIndirectInheritorGetItem.py @@ -0,0 +1,19 @@ +import typing + + +T = typing.TypeVar('T') + + +class X(typing.Generic[T]): + pass + + +class Y(X[T]): + pass + + +class Z(Y[T]): + pass + + +Z[int] \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/inspections/Py3UnresolvedReferencesInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/Py3UnresolvedReferencesInspectionTest.java index a789363f4d20..e3d3a7763ce7 100644 --- a/python/testSrc/com/jetbrains/python/inspections/Py3UnresolvedReferencesInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/Py3UnresolvedReferencesInspectionTest.java @@ -215,6 +215,11 @@ public class Py3UnresolvedReferencesInspectionTest extends PyInspectionTestCase doTest(); } + // PY-27102 + public void testTypingGenericIndirectInheritorGetItem() { + doTest(); + } + // PY-21655 public void testUsageOfFunctionDecoratedWithAsyncioCoroutine() { doMultiFileTest("a.py");