diff --git a/python/src/com/jetbrains/python/inspections/PyUnresolvedReferencesInspection.java b/python/src/com/jetbrains/python/inspections/PyUnresolvedReferencesInspection.java index f4c3e28c4c03..428bd668f674 100644 --- a/python/src/com/jetbrains/python/inspections/PyUnresolvedReferencesInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyUnresolvedReferencesInspection.java @@ -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 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() + "'"); } } } diff --git a/python/testData/inspections/PyUnresolvedReferencesInspection/slots.py b/python/testData/inspections/PyUnresolvedReferencesInspection/slots.py index adc353f45f2c..6929ebccd548 100644 --- a/python/testData/inspections/PyUnresolvedReferencesInspection/slots.py +++ b/python/testData/inspections/PyUnresolvedReferencesInspection/slots.py @@ -2,10 +2,16 @@ class B(object): __slots__ = ['foo'] b = B() -b.bar = 1 +b.bar = 1 class C(B): pass c = C() -c.bar = 1 +c.bar = 1 + +def test_slots_with_dict(): + class C(object): + __slots__ = ['__local', '__name__', '__dict__'] + a = C() + a.foo = 1 #pass