mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
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:
@@ -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";
|
||||
|
||||
+5
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user