fixed PY-11588 "Instance attribute %s defined outside __init__" in static method

This commit is contained in:
Ekaterina Tuzova
2013-12-17 18:49:14 +04:00
parent a239ed4396
commit 84cbbc910d
3 changed files with 13 additions and 0 deletions

View File

@@ -70,6 +70,9 @@ public class PyAttributeOutsideInitInspection extends PyInspection {
if (!isApplicable(containingClass)) {
return;
}
final PyFunction.Modifier modifier = node.getModifier();
if (modifier != null) return;
final List<PyTargetExpression> classAttributes = containingClass.getClassAttributes();
Map<String, PyTargetExpression> attributesInInit = new HashMap<String, PyTargetExpression>();

View File

@@ -0,0 +1,6 @@
class C(object):
@staticmethod
def static_method(obj, name):
obj.name = name # warning here

View File

@@ -62,6 +62,10 @@ public class PyAttributeOutsideInitInspectionTest extends PyTestCase {
doTest();
}
public void testStaticMethod() {
doTest();
}
private void doTest() {
myFixture.configureByFile("inspections/PyAttributeOutsideInitInspection/" + getTestName(true) + ".py");
myFixture.enableInspections(PyAttributeOutsideInitInspection.class);