From 8678782c6569d213e3ab216c78c5e15a2bd3e792 Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Mon, 11 Dec 2017 15:02:32 +0300 Subject: [PATCH] Ignore `__getitem__` for `Generic` indirect inheritors (PY-27102) --- .../typing/PyTypingInspectionExtension.kt | 2 +- .../typingGenericIndirectInheritorGetItem.py | 19 +++++++++++++++++++ ...Py3UnresolvedReferencesInspectionTest.java | 5 +++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 python/testData/inspections/PyUnresolvedReferencesInspection3K/typingGenericIndirectInheritorGetItem.py 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");