diff --git a/python/src/com/jetbrains/python/psi/types/PyTypeChecker.java b/python/src/com/jetbrains/python/psi/types/PyTypeChecker.java index 1fae1c8a8e57..ce0f4de96a15 100644 --- a/python/src/com/jetbrains/python/psi/types/PyTypeChecker.java +++ b/python/src/com/jetbrains/python/psi/types/PyTypeChecker.java @@ -50,9 +50,6 @@ public class PyTypeChecker { if (actual instanceof PyTypeReference) { return match(expected, ((PyTypeReference)actual).resolve(null, context), context, substitutions, false); } - if (isUnknown(actual)) { - return true; - } if (expected instanceof PyGenericType && substitutions != null) { final PyGenericType generic = (PyGenericType)expected; final PyType subst = substitutions.get(generic); @@ -72,6 +69,9 @@ public class PyTypeChecker { return true; } } + if (isUnknown(actual)) { + return true; + } if (actual instanceof PyUnionType) { for (PyType m : ((PyUnionType)actual).getMembers()) { if (!match(expected, m, context, substitutions, recursive)) { @@ -149,7 +149,7 @@ public class PyTypeChecker { } public static boolean isUnknown(@Nullable PyType type) { - if (type == null || type instanceof PyTypeReference) { + if (type == null || type instanceof PyTypeReference || type instanceof PyGenericType) { return true; } if (type instanceof PyUnionType) { diff --git a/python/testData/inspections/PyTypeCheckerInspection/GenericArguments.py b/python/testData/inspections/PyTypeCheckerInspection/GenericArguments.py new file mode 100644 index 000000000000..b7fc3e6b4416 --- /dev/null +++ b/python/testData/inspections/PyTypeCheckerInspection/GenericArguments.py @@ -0,0 +1,18 @@ +class B(object): + def __init__(self, x): + """ + :type x: T + :rtype: B of T + """ + self._x = x + + def foo(self): + """ + :rtype: T + """ + return self._x + +class C(B): + def bar(self): + expr = self.foo() + return 'foo' + expr #pass \ No newline at end of file diff --git a/python/testData/inspections/PyUnresolvedReferencesInspection/attributesOfGenerics.py b/python/testData/inspections/PyUnresolvedReferencesInspection/attributesOfGenerics.py new file mode 100644 index 000000000000..d424c822ad42 --- /dev/null +++ b/python/testData/inspections/PyUnresolvedReferencesInspection/attributesOfGenerics.py @@ -0,0 +1,18 @@ +class B(object): + def __init__(self, x): + """ + :type x: T + :rtype: B of T + """ + self._x = x + + def foo(self): + """ + :rtype: T + """ + return self._x + +class C(B): + def bar(self): + expr = self.foo() + return expr.upper() #pass \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/inspections/PyTypeCheckerInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyTypeCheckerInspectionTest.java index 0169210658f1..2f8009f33a7c 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyTypeCheckerInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyTypeCheckerInspectionTest.java @@ -140,4 +140,9 @@ public class PyTypeCheckerInspectionTest extends PyTestCase { public void testAssignedOperator() { doTest(); } + + // PY-7244 + public void testGenericArguments() { + doTest(); + } } diff --git a/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java index 64886dc36c81..b4a532e133df 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java @@ -175,6 +175,11 @@ public class PyUnresolvedReferencesInspectionTest extends PyTestCase { doTest(); } + // PY-7244 + public void testAttributesOfGenerics() { + doTest(); + } + private void doTest() { myFixture.configureByFile(TEST_DIRECTORY + getTestName(true) + ".py"); myFixture.enableInspections(PyUnresolvedReferencesInspection.class);