mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-15 20:26:04 +07:00
PY-10988 Instance attribute defined outside __init__ with property setter
This commit is contained in:
@@ -79,7 +79,8 @@ public class PyAttributeOutsideInitInspection extends PyInspection {
|
||||
PyClassImpl.collectInstanceAttributes(node, attributes);
|
||||
|
||||
for (Map.Entry<String, PyTargetExpression> attribute : attributes.entrySet()) {
|
||||
if (!attributesInInit.containsKey(attribute.getKey())) {
|
||||
final Property property = containingClass.findProperty(attribute.getKey());
|
||||
if (!attributesInInit.containsKey(attribute.getKey()) && property == null) {
|
||||
registerProblem(attribute.getValue(), PyBundle.message("INSP.attribute.$0.outside.init", attribute.getKey()),
|
||||
new PyMoveAttributeToInitQuickFix());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
class FavouriteManager(object):
|
||||
"""Favourite manager"""
|
||||
|
||||
def __init__(self, session):
|
||||
self._session = session
|
||||
|
||||
@property
|
||||
def _favourite_ids(self):
|
||||
"""Get favourites"""
|
||||
try:
|
||||
return map(int, self._session.get('favourite', '').split(','))
|
||||
except ValueError:
|
||||
return []
|
||||
|
||||
@_favourite_ids.setter
|
||||
def _favourite_ids(self, ids):
|
||||
"""Set favourites ids"""
|
||||
self._session['favourite'] = ','.join(set(ids))
|
||||
|
||||
def add(self, estate):
|
||||
"""Add estate to favourite"""
|
||||
ids = self._favourite_ids
|
||||
ids.append(estate.id)
|
||||
self._favourite_ids = ids
|
||||
@@ -8,23 +8,23 @@ import com.jetbrains.python.inspections.PyUnresolvedReferencesInspection;
|
||||
public class AddFieldQuickFixTest extends PyQuickFixTestCase {
|
||||
|
||||
public void testAddClassField() {
|
||||
doInspectionTest(PyUnresolvedReferencesInspection.class, PyBundle.message("QFIX.NAME.add.field.$0.to.class.$1", "FIELD", "A"));
|
||||
doQuickFixTest(PyUnresolvedReferencesInspection.class, PyBundle.message("QFIX.NAME.add.field.$0.to.class.$1", "FIELD", "A"));
|
||||
}
|
||||
|
||||
public void testAddFieldFromMethod() {
|
||||
doInspectionTest(PyUnresolvedReferencesInspection.class, PyBundle.message("QFIX.NAME.add.field.$0.to.class.$1", "y", "A"));
|
||||
doQuickFixTest(PyUnresolvedReferencesInspection.class, PyBundle.message("QFIX.NAME.add.field.$0.to.class.$1", "y", "A"));
|
||||
}
|
||||
|
||||
public void testAddFieldFromInstance() {
|
||||
doInspectionTest(PyUnresolvedReferencesInspection.class, PyBundle.message("QFIX.NAME.add.field.$0.to.class.$1", "y", "A"));
|
||||
doQuickFixTest(PyUnresolvedReferencesInspection.class, PyBundle.message("QFIX.NAME.add.field.$0.to.class.$1", "y", "A"));
|
||||
}
|
||||
|
||||
public void testAddFieldAddConstructor() {
|
||||
doInspectionTest(PyUnresolvedReferencesInspection.class, PyBundle.message("QFIX.NAME.add.field.$0.to.class.$1", "x", "B"));
|
||||
doQuickFixTest(PyUnresolvedReferencesInspection.class, PyBundle.message("QFIX.NAME.add.field.$0.to.class.$1", "x", "B"));
|
||||
}
|
||||
|
||||
public void testAddFieldNewConstructor() {
|
||||
doInspectionTest(PyUnresolvedReferencesInspection.class, PyBundle.message("QFIX.NAME.add.field.$0.to.class.$1", "x", "B"));
|
||||
doQuickFixTest(PyUnresolvedReferencesInspection.class, PyBundle.message("QFIX.NAME.add.field.$0.to.class.$1", "x", "B"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,23 +9,23 @@ import com.jetbrains.python.inspections.PyUnresolvedReferencesInspection;
|
||||
public class AddMethodQuickFixTest extends PyQuickFixTestCase {
|
||||
|
||||
public void testAddInit() {
|
||||
doInspectionTest(PyClassHasNoInitInspection.class, PyBundle.message("QFIX.NAME.add.method.$0.to.class.$1", "__init__", "A"));
|
||||
doQuickFixTest(PyClassHasNoInitInspection.class, PyBundle.message("QFIX.NAME.add.method.$0.to.class.$1", "__init__", "A"));
|
||||
}
|
||||
|
||||
public void testAddInitAfterDocstring() {
|
||||
doInspectionTest(PyClassHasNoInitInspection.class, PyBundle.message("QFIX.NAME.add.method.$0.to.class.$1", "__init__", "A"));
|
||||
doQuickFixTest(PyClassHasNoInitInspection.class, PyBundle.message("QFIX.NAME.add.method.$0.to.class.$1", "__init__", "A"));
|
||||
}
|
||||
|
||||
public void testAddMethodReplacePass() {
|
||||
doInspectionTest(PyUnresolvedReferencesInspection.class, PyBundle.message("QFIX.NAME.add.method.$0.to.class.$1", "y", "A"));
|
||||
doQuickFixTest(PyUnresolvedReferencesInspection.class, PyBundle.message("QFIX.NAME.add.method.$0.to.class.$1", "y", "A"));
|
||||
}
|
||||
|
||||
public void testAddMethodFromInstance() {
|
||||
doInspectionTest(PyUnresolvedReferencesInspection.class, PyBundle.message("QFIX.NAME.add.method.$0.to.class.$1", "y", "A"));
|
||||
doQuickFixTest(PyUnresolvedReferencesInspection.class, PyBundle.message("QFIX.NAME.add.method.$0.to.class.$1", "y", "A"));
|
||||
}
|
||||
|
||||
public void testAddMethodFromMethod() {
|
||||
doInspectionTest(PyUnresolvedReferencesInspection.class, PyBundle.message("QFIX.NAME.add.method.$0.to.class.$1", "y", "A"));
|
||||
doQuickFixTest(PyUnresolvedReferencesInspection.class, PyBundle.message("QFIX.NAME.add.method.$0.to.class.$1", "y", "A"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,39 +8,39 @@ import com.jetbrains.python.inspections.PyMethodMayBeStaticInspection;
|
||||
public class PyMakeFunctionFromMethodQuickFixTest extends PyQuickFixTestCase {
|
||||
|
||||
public void testOneParam() {
|
||||
doInspectionTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.function"));
|
||||
doQuickFixTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.function"));
|
||||
}
|
||||
|
||||
public void testTwoParams() {
|
||||
doInspectionTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.function"));
|
||||
doQuickFixTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.function"));
|
||||
}
|
||||
|
||||
public void testEmptyParam() {
|
||||
doInspectionTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.function"));
|
||||
doQuickFixTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.function"));
|
||||
}
|
||||
|
||||
public void testFirstMethod() {
|
||||
doInspectionTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.function"));
|
||||
doQuickFixTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.function"));
|
||||
}
|
||||
|
||||
public void testEmptyStatementList() {
|
||||
doInspectionTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.function"));
|
||||
doQuickFixTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.function"));
|
||||
}
|
||||
|
||||
public void testNoSelf() {
|
||||
doInspectionTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.function"));
|
||||
doQuickFixTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.function"));
|
||||
}
|
||||
|
||||
public void testUpdateUsage() {
|
||||
doInspectionTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.function"));
|
||||
doQuickFixTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.function"));
|
||||
}
|
||||
|
||||
public void testUsageClassCallArgument() {
|
||||
doInspectionTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.function"));
|
||||
doQuickFixTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.function"));
|
||||
}
|
||||
|
||||
public void testUsageAssignment() {
|
||||
doInspectionTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.function"));
|
||||
doQuickFixTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.function"));
|
||||
}
|
||||
|
||||
public void testUsageImport() {
|
||||
@@ -56,6 +56,6 @@ public class PyMakeFunctionFromMethodQuickFixTest extends PyQuickFixTestCase {
|
||||
}
|
||||
|
||||
public void testUsageSelf() {
|
||||
doInspectionTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.function"));
|
||||
doQuickFixTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.function"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,31 +8,31 @@ import com.jetbrains.python.inspections.PyMethodMayBeStaticInspection;
|
||||
public class PyMakeMethodStaticQuickFixTest extends PyQuickFixTestCase {
|
||||
|
||||
public void testOneParam() {
|
||||
doInspectionTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.static"));
|
||||
doQuickFixTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.static"));
|
||||
}
|
||||
|
||||
public void testTwoParams() {
|
||||
doInspectionTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.static"));
|
||||
doQuickFixTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.static"));
|
||||
}
|
||||
|
||||
public void testEmptyParam() {
|
||||
doInspectionTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.static"));
|
||||
doQuickFixTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.static"));
|
||||
}
|
||||
|
||||
public void testFunctionWithDeco() {
|
||||
doInspectionTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.static"));
|
||||
doQuickFixTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.static"));
|
||||
}
|
||||
|
||||
public void testDecoWithParams() {
|
||||
doInspectionTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.static"));
|
||||
doQuickFixTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.static"));
|
||||
}
|
||||
|
||||
public void testNoSelf() {
|
||||
doInspectionTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.static"));
|
||||
doQuickFixTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.static"));
|
||||
}
|
||||
|
||||
public void testUsage() {
|
||||
doInspectionTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.static"));
|
||||
doQuickFixTest(PyMethodMayBeStaticInspection.class, PyBundle.message("QFIX.NAME.make.static"));
|
||||
}
|
||||
|
||||
public void testUsageImport() {
|
||||
|
||||
@@ -10,31 +10,35 @@ import com.jetbrains.python.inspections.PyAttributeOutsideInitInspection;
|
||||
public class PyMoveAttributeToInitQuickFixTest extends PyQuickFixTestCase {
|
||||
|
||||
public void testMoveToInit() {
|
||||
doInspectionTest(PyAttributeOutsideInitInspection.class, PyBundle.message("QFIX.move.attribute"));
|
||||
doQuickFixTest(PyAttributeOutsideInitInspection.class, PyBundle.message("QFIX.move.attribute"));
|
||||
}
|
||||
|
||||
public void testCreateInit() {
|
||||
doInspectionTest(PyAttributeOutsideInitInspection.class, PyBundle.message("QFIX.move.attribute"));
|
||||
doQuickFixTest(PyAttributeOutsideInitInspection.class, PyBundle.message("QFIX.move.attribute"));
|
||||
}
|
||||
|
||||
public void testAddPass() {
|
||||
doInspectionTest(PyAttributeOutsideInitInspection.class, PyBundle.message("QFIX.move.attribute"));
|
||||
doQuickFixTest(PyAttributeOutsideInitInspection.class, PyBundle.message("QFIX.move.attribute"));
|
||||
}
|
||||
|
||||
public void testRemovePass() {
|
||||
doInspectionTest(PyAttributeOutsideInitInspection.class, PyBundle.message("QFIX.move.attribute"));
|
||||
doQuickFixTest(PyAttributeOutsideInitInspection.class, PyBundle.message("QFIX.move.attribute"));
|
||||
}
|
||||
|
||||
public void testSkipDocstring() {
|
||||
doInspectionTest(PyAttributeOutsideInitInspection.class, PyBundle.message("QFIX.move.attribute"));
|
||||
doQuickFixTest(PyAttributeOutsideInitInspection.class, PyBundle.message("QFIX.move.attribute"));
|
||||
}
|
||||
|
||||
public void testAddSuperCall() {
|
||||
doInspectionTest(PyAttributeOutsideInitInspection.class, PyBundle.message("QFIX.move.attribute"));
|
||||
doQuickFixTest(PyAttributeOutsideInitInspection.class, PyBundle.message("QFIX.move.attribute"));
|
||||
}
|
||||
|
||||
public void testAddSuperCallOldStyle() {
|
||||
doInspectionTest(PyAttributeOutsideInitInspection.class, PyBundle.message("QFIX.move.attribute"));
|
||||
doQuickFixTest(PyAttributeOutsideInitInspection.class, PyBundle.message("QFIX.move.attribute"));
|
||||
}
|
||||
|
||||
public void testPropertyNegative() {
|
||||
doInspectionTest(PyAttributeOutsideInitInspection.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.jetbrains.python;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.jetbrains.python.PythonTestUtil;
|
||||
import com.jetbrains.python.fixtures.PyTestCase;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -18,7 +17,7 @@ public abstract class PyQuickFixTestCase extends PyTestCase {
|
||||
return PythonTestUtil.getTestDataPath() + "/quickFixes/" + getClass().getSimpleName();
|
||||
}
|
||||
|
||||
protected void doInspectionTest(final Class inspectionClass, final String hint) {
|
||||
protected void doQuickFixTest(final Class inspectionClass, final String hint) {
|
||||
final String testFileName = getTestName(true);
|
||||
myFixture.enableInspections(inspectionClass);
|
||||
myFixture.configureByFile(testFileName + ".py");
|
||||
@@ -29,6 +28,13 @@ public abstract class PyQuickFixTestCase extends PyTestCase {
|
||||
myFixture.checkResultByFile(testFileName + "_after.py", true);
|
||||
}
|
||||
|
||||
protected void doInspectionTest(final Class inspectionClass) {
|
||||
final String testFileName = getTestName(true);
|
||||
myFixture.enableInspections(inspectionClass);
|
||||
myFixture.configureByFile(testFileName + ".py");
|
||||
myFixture.checkHighlighting(true, false, false);
|
||||
}
|
||||
|
||||
protected void doMultifilesTest(@NotNull final Class inspectionClass, @NotNull final String hint, @NotNull final String[] files) {
|
||||
final String testFileName = getTestName(true);
|
||||
myFixture.enableInspections(inspectionClass);
|
||||
|
||||
Reference in New Issue
Block a user