From 8f16f88dff2e61f6aa979f705761c545e9ef6ea8 Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Thu, 8 Dec 2011 20:56:16 +0400 Subject: [PATCH] Fixed bug in unresolved references inspection for '__dict__' in '__slots__' (PY-5255) --- .../inspections/PyUnresolvedReferencesInspection.java | 7 +++++-- .../PyUnresolvedReferencesInspection/slots.py | 10 ++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) 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