PY-20026 Add test for the scenario provided by the user
authorMikhail Golubev <mikhail.golubev@jetbrains.com>
Tue, 16 Aug 2016 14:52:56 +0000 (17:52 +0300)
committerMikhail Golubev <mikhail.golubev@jetbrains.com>
Fri, 19 Aug 2016 13:52:42 +0000 (16:52 +0300)
The problem itself has been already remedied by the previous fix,
nonetheless, the example given by the user provides an interesting
case where we can encounter duplicate base classes in practice,
since we are not able to find out result of type(SomeClass) expression
yet.

python/testData/codeInsight/classMRO/UnresolvedMetaClassAncestors.py [new file with mode: 0644]
python/testSrc/com/jetbrains/python/codeInsight/PyClassMROTest.java

diff --git a/python/testData/codeInsight/classMRO/UnresolvedMetaClassAncestors.py b/python/testData/codeInsight/classMRO/UnresolvedMetaClassAncestors.py
new file mode 100644 (file)
index 0000000..c26077f
--- /dev/null
@@ -0,0 +1,27 @@
+# --- TypeField ---
+
+class TypeFieldMeta(type):
+    pass
+
+
+class TypeField(metaclass=TypeFieldMeta):
+    pass
+
+
+# --- FieldedType ---
+
+class FieldedTypeMeta(type):
+    pass
+
+
+class FieldedType(metaclass=FieldedTypeMeta):
+    pass
+
+
+# --- CompositeField ---
+
+class CompositeFieldMeta(type(FieldedType), type(TypeField)):
+    # The superclass declaration is spelled they way it is to true and isolate this bit of code
+    # from the implementation details of whether or not FieldedType and TypeField have special
+    # metaclasses of their own or not and still get a metaclass MRO that keeps Python happy.
+    pass
index dc03ee27d0cfd0fad5906efaa3d842a84d321a09..7ced73929b59cfc4a47d2424798aceb984f7f28b 100644 (file)
@@ -17,6 +17,7 @@ package com.jetbrains.python.codeInsight;
 
 import com.intellij.util.ArrayUtil;
 import com.jetbrains.python.fixtures.PyTestCase;
+import com.jetbrains.python.psi.LanguageLevel;
 import com.jetbrains.python.psi.PyClass;
 import com.jetbrains.python.psi.types.PyClassLikeType;
 import com.jetbrains.python.psi.types.TypeEvalContext;
@@ -115,6 +116,11 @@ public class PyClassMROTest extends PyTestCase {
     assertMRO(getClass("MyClass"), "Base", "object");
   }
 
+  // PY-20026
+  public void testUnresolvedMetaClassAncestors() {
+    runWithLanguageLevel(LanguageLevel.PYTHON30, () -> assertMRO(getClass("CompositeFieldMeta"), "type", "object"));
+  }
+
   @NotNull
   public PyClass getClass(@NotNull String name) {
     myFixture.configureByFile(getPath(getTestName(false)));