mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 13:31:28 +07:00
PY-21651 Fixed: Unresolved reference for attributes created by with statements
Visit with-statements while collecting targets inside `__int__` and `__new__` methods
This commit is contained in:
@@ -1214,6 +1214,15 @@ public class PyClassImpl extends PyBaseElementImpl<PyClassStub> implements PyCla
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyWithStatement(PyWithStatement node) {
|
||||
StreamEx
|
||||
.of(node.getWithItems())
|
||||
.map(PyWithItem::getTarget)
|
||||
.select(PyTargetExpression.class)
|
||||
.forEach(result::add);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
from foo import Foo
|
||||
|
||||
print(Foo().scope)
|
||||
@@ -0,0 +1,4 @@
|
||||
class Foo(object):
|
||||
def __init__(self):
|
||||
with open('scope') as self.scope:
|
||||
pass
|
||||
@@ -0,0 +1,7 @@
|
||||
class Foo(object):
|
||||
def __init__(self):
|
||||
with open('scope') as self.scope:
|
||||
pass
|
||||
|
||||
def get_scope(self):
|
||||
return self.scope
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 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.
|
||||
@@ -19,11 +19,14 @@ import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.xdebugger.impl.XSourcePositionImpl;
|
||||
import com.jetbrains.python.debugger.PyDebuggerEditorsProvider;
|
||||
import com.jetbrains.python.fixtures.PyInspectionTestCase;
|
||||
import com.jetbrains.python.inspections.unresolvedReference.PyUnresolvedReferencesInspection;
|
||||
import com.jetbrains.python.psi.LanguageLevel;
|
||||
import com.jetbrains.python.psi.PyFile;
|
||||
import com.jetbrains.python.psi.impl.PyExpressionCodeFragmentImpl;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -744,6 +747,22 @@ public class PyUnresolvedReferencesInspectionTest extends PyInspectionTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-21651
|
||||
public void testInstanceAttributeCreatedThroughWithStatement() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-21651
|
||||
public void testInstanceAttributeCreatedThroughWithStatementInAnotherFile() {
|
||||
doMultiFileTest();
|
||||
|
||||
final VirtualFile fooVFile = myFixture.getFile().getVirtualFile().getParent().getChildren()[1];
|
||||
assertEquals("foo.py", fooVFile.getName());
|
||||
|
||||
final PsiFile fooPsiFile = PsiManager.getInstance(myFixture.getProject()).findFile(fooVFile);
|
||||
assertNotParsed((PyFile)fooPsiFile);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Class<? extends PyInspection> getInspectionClass() {
|
||||
|
||||
Reference in New Issue
Block a user