fixed PY-10993 Instance attribute defined outside __init__, which is strictly true, but it's an invalid issue.

This commit is contained in:
Ekaterina Tuzova
2013-10-02 15:21:45 +04:00
parent be7a549a1d
commit baec2af48e
3 changed files with 17 additions and 0 deletions
@@ -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
@@ -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);