Fixed bug in unresolved references inspection for '__dict__' in '__slots__' (PY-5255)

This commit is contained in:
Andrey Vlasovskikh
2011-12-08 20:56:16 +04:00
parent 74b7e27524
commit 8f16f88dff
2 changed files with 13 additions and 4 deletions
@@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableSet;
import com.intellij.codeInspection.*;
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
import com.intellij.codeInspection.ui.ListEditForm;
import com.intellij.lang.ASTNode;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.util.Comparing;
@@ -122,8 +123,10 @@ public class PyUnresolvedReferencesInspection extends PyInspection {
final PyClass pyClass = ((PyClassType)type).getPyClass();
if (pyClass != null && pyClass.isNewStyleClass()) {
final List<String> slots = pyClass.getSlots();
if (slots != null && !slots.contains(node.getReferencedName())) {
registerProblem(node, "'" + pyClass.getName() + "' object has no attribute '" + node.getReferencedName() + "'");
if (slots != null && !slots.contains(node.getReferencedName()) && !slots.contains("__dict__")) {
final ASTNode nameNode = node.getNameElement();
final PsiElement e = nameNode != null ? nameNode.getPsi() : node;
registerProblem(e, "'" + pyClass.getName() + "' object has no attribute '" + node.getReferencedName() + "'");
}
}
}
@@ -2,10 +2,16 @@ class B(object):
__slots__ = ['foo']
b = B()
<warning descr="'B' object has no attribute 'bar'">b.bar</warning> = 1
b.<warning descr="'B' object has no attribute 'bar'">bar</warning> = 1
class C(B):
pass
c = C()
<warning descr="'C' object has no attribute 'bar'">c.bar</warning> = 1
c.<warning descr="'C' object has no attribute 'bar'">bar</warning> = 1
def test_slots_with_dict():
class C(object):
__slots__ = ['__local', '__name__', '__dict__']
a = C()
a.foo = 1 #pass