PY-19702 Fixed: Unresolved metaclass attributes in children

In case of definition resolve attribute in metaclass definition and instance.
In case of instance check if metaclass is PyClass and look for attribute in instance attributes.
Same with completion.
This commit is contained in:
Semyon Proshev
2016-11-15 15:33:07 +03:00
parent 0bfd59ed6e
commit 5c920951f0
4 changed files with 140 additions and 13 deletions
@@ -205,6 +205,58 @@ public class Py3CompletionTest extends PyTestCase {
runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest);
}
// PY-19702
public void testMetaclassAttributeOnDefinition() {
final List<String> suggested = doTestByText("class Meta(type):\n" +
" def __init__(self, what, bases, dict):\n" +
" self.meta_attr = \"attr\"\n" +
" super().__init__(what, bases, dict)\n" +
"class A(metaclass=Meta):\n" +
" pass\n" +
"print(A.<caret>)");
assertNotNull(suggested);
assertContainsElements(suggested, "meta_attr");
}
// PY-19702
public void testMetaclassAttributeOnInstance() {
final List<String> suggested = doTestByText("class Meta(type):\n" +
" def __init__(self, what, bases, dict):\n" +
" self.meta_attr = \"attr\"\n" +
" super().__init__(what, bases, dict)\n" +
"class A(metaclass=Meta):\n" +
" pass\n" +
"print(A().<caret>)");
assertNotNull(suggested);
assertContainsElements(suggested, "meta_attr");
}
public void testMetaclassMethodOnDefinition() {
final List<String> suggested = doTestByText("class Meta(type):\n" +
" def meta_method(cls):\n" +
" pass\n" +
"class A(metaclass=Meta):\n" +
" pass\n" +
"print(A.<caret>)");
assertNotNull(suggested);
assertContainsElements(suggested, "meta_method");
}
public void testMetaclassMethodOnInstance() {
final List<String> suggested = doTestByText("class Meta(type):\n" +
" def meta_method(cls):\n" +
" pass\n" +
"class A(metaclass=Meta):\n" +
" pass\n" +
"print(A().<caret>)");
assertNotNull(suggested);
assertDoesntContain(suggested, "meta_method");
}
@Override
protected String getTestDataPath() {
return super.getTestDataPath() + "/completion";
@@ -95,6 +95,11 @@ public class Py3UnresolvedReferencesInspectionTest extends PyTestCase {
doTest();
}
// PY-19702
public void testMetaclassAttribute() {
doTest();
}
public void testMetaclassStub() {
doMultiFileTest("a.py");
final Project project = myFixture.getProject();