mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fixed bug in unresolved references inspection for '__dict__' in '__slots__' (PY-5255)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user