mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-10993 Instance attribute defined outside __init__, which is strictly true, but it's an invalid issue.
This commit is contained in:
@@ -17,6 +17,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -54,8 +55,13 @@ public class PyAttributeOutsideInitInspection extends PyInspection {
|
||||
if (!isApplicable(containingClass)) {
|
||||
return;
|
||||
}
|
||||
final List<PyTargetExpression> classAttributes = containingClass.getClassAttributes();
|
||||
|
||||
Map<String, PyTargetExpression> attributesInInit = new HashMap<String, PyTargetExpression>();
|
||||
for (PyTargetExpression classAttr : classAttributes) {
|
||||
attributesInInit.put(classAttr.getName(), classAttr);
|
||||
}
|
||||
|
||||
final PyFunction initMethod = containingClass.findMethodByName(PyNames.INIT, false);
|
||||
if (initMethod != null) {
|
||||
PyClassImpl.collectInstanceAttributes(initMethod, attributesInInit);
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
__author__ = 'ktisha'
|
||||
|
||||
class A:
|
||||
ccc = True
|
||||
|
||||
def foo(self):
|
||||
self.ccc = False
|
||||
+4
@@ -35,6 +35,10 @@ public class PyAttributeOutsideInitInspectionTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testClassAttrs() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
myFixture.configureByFile("inspections/PyAttributeOutsideInitInspection/" + getTestName(true) + ".py");
|
||||
myFixture.enableInspections(PyAttributeOutsideInitInspection.class);
|
||||
|
||||
Reference in New Issue
Block a user