mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Don't collect names in parameter default and annotation for visited function (PY-19599)
Because they are collected in the outer scope and outer scope is considered as their owner in ScopeUtil.getScopeOwner.
This commit is contained in:
@@ -236,6 +236,11 @@ public class ScopeImpl implements Scope {
|
||||
super.visitPyFunction(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyNamedParameter(PyNamedParameter node) {
|
||||
processNamedElement(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyClass(PyClass node) {
|
||||
visitDecorators(node.getDecoratorList());
|
||||
@@ -249,11 +254,7 @@ public class ScopeImpl implements Scope {
|
||||
@Override
|
||||
public void visitPyElement(PyElement node) {
|
||||
if (node instanceof PsiNamedElement && !(node instanceof PyKeywordArgument)) {
|
||||
final String name = node.getName();
|
||||
if (!namedElements.containsKey(name)) {
|
||||
namedElements.put(name, Sets.newLinkedHashSet());
|
||||
}
|
||||
namedElements.get(name).add((PsiNamedElement)node);
|
||||
processNamedElement((PsiNamedElement)node);
|
||||
}
|
||||
if (node instanceof PyImportedNameDefiner) {
|
||||
importedNameDefiners.add((PyImportedNameDefiner)node);
|
||||
@@ -274,6 +275,10 @@ public class ScopeImpl implements Scope {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void processNamedElement(@NotNull PsiNamedElement element) {
|
||||
namedElements.computeIfAbsent(element.getName(), __ -> Sets.newLinkedHashSet()).add(element);
|
||||
}
|
||||
});
|
||||
|
||||
myNamedElements = namedElements;
|
||||
|
||||
+7
@@ -714,6 +714,13 @@ public class PyUnresolvedReferencesInspectionTest extends PyInspectionTestCase {
|
||||
" self.value = self.datetime(2016, 1, 1)");
|
||||
}
|
||||
|
||||
// PY-19599
|
||||
public void testDefinedInParameterDefaultAndBody() {
|
||||
doTestByText("def f(p=(x for x in [])):\n" +
|
||||
" x = 1\n" +
|
||||
" return x");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Class<? extends PyInspection> getInspectionClass() {
|
||||
|
||||
Reference in New Issue
Block a user