fixed PY-12033 PyAbstractClass invalid warning for properties.

This commit is contained in:
Ekaterina Tuzova
2014-03-11 13:20:24 +04:00
parent 7438ce848b
commit 6f6d8136f8
5 changed files with 68 additions and 4 deletions
+1 -1
View File
@@ -331,7 +331,7 @@
<localInspection language="Python" shortName="PyDocstringTypesInspection" bundle="com.jetbrains.python.PyBundle" key="INSP.NAME.docstring.types" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WEAK WARNING" implementationClass="com.jetbrains.python.inspections.PyDocstringTypesInspection"/>
<localInspection language="Python" shortName="PyShadowingBuiltinsInspection" displayName="Shadowing built-ins" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WEAK WARNING" implementationClass="com.jetbrains.python.inspections.PyShadowingBuiltinsInspection"/>
<localInspection language="Python" shortName="PyShadowingNamesInspection" displayName="Shadowing names from outer scopes" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WEAK WARNING" implementationClass="com.jetbrains.python.inspections.PyShadowingNamesInspection"/>
<localInspection language="Python" shortName="PyAbstractClassInspection" displayName="Class must implement all abstract methods" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WARNING" implementationClass="com.jetbrains.python.inspections.PyAbstractClassInspection"/>
<localInspection language="Python" shortName="PyAbstractClassInspection" displayName="Class must implement all abstract methods" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WEAK WARNING" implementationClass="com.jetbrains.python.inspections.PyAbstractClassInspection"/>
<localInspection language="Python" shortName="PyPep8NamingInspection" displayName="PEP 8 naming convention violation" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WEAK WARNING" implementationClass="com.jetbrains.python.inspections.PyPep8NamingInspection"/>
<localInspection language="Python" shortName="PyAssignmentToLoopOrWithParameterInspection" displayName="Assignment to 'for' loop or 'with' statement parameter" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WEAK WARNING" implementationClass="com.jetbrains.python.inspections.PyAssignmentToLoopOrWithParameterInspection"/>
@@ -16,7 +16,6 @@
package com.jetbrains.python.inspections;
import com.intellij.codeInspection.LocalInspectionToolSession;
import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElementVisitor;
@@ -63,14 +62,16 @@ public class PyAbstractClassInspection extends PyInspection {
Set<PyFunction> toBeImplemented = new HashSet<PyFunction>();
final Collection<PyFunction> functions = PyOverrideImplementUtil.getAllSuperFunctions(node);
for (PyFunction method : functions) {
if (node.findMethodByName(method.getName(), false) == null && PyUtil.isDecoratedAsAbstract(method)) {
final String methodName = method.getName();
if (methodName != null && PyUtil.isDecoratedAsAbstract(method) &&
node.findMethodByName(methodName, false) == null && node.findClassAttribute(methodName, false) == null) {
toBeImplemented.add(method);
}
}
final ASTNode nameNode = node.getNameNode();
if (!toBeImplemented.isEmpty() && nameNode != null) {
registerProblem(nameNode.getPsi(), PyBundle.message("INSP.NAME.abstract.class.$0.must.implement", node.getName()),
ProblemHighlightType.INFO, null, new PyImplementMethodsQuickFix(node, toBeImplemented));
new PyImplementMethodsQuickFix(node, toBeImplemented));
}
}
}
@@ -0,0 +1,14 @@
import abc
class A(object):
__metaclass__ = abc.ABCMeta
@abc.abstractproperty
def foo(self):
pass
class <weak_warning descr="Class C must implement all abstract methods">C</weak_warning>(A):
def bar(self):
pass
@@ -0,0 +1,13 @@
import abc
class A(object):
__metaclass__ = abc.ABCMeta
@abc.abstractproperty
def foo(self):
pass
class C(A):
foo = 'bar'
@@ -0,0 +1,36 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jetbrains.python.inspections;
import com.jetbrains.python.fixtures.PyInspectionTestCase;
import org.jetbrains.annotations.NotNull;
public class PyAbstractClassInspectionTest extends PyInspectionTestCase {
public void testAbstract() {
doTest();
}
public void testOverriddenAsField() {
doTest();
}
@NotNull
@Override
protected Class<? extends PyInspection> getInspectionClass() {
return PyAbstractClassInspection.class;
}
}