mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fix PY-16473 Inspection naming error for namedtuple declared into a function
This commit is contained in:
@@ -25,6 +25,7 @@ import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.popup.PopupChooserBuilder;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
@@ -115,18 +116,24 @@ public class PyPep8NamingInspection extends PyInspection {
|
||||
final PyFunction function = PsiTreeUtil.getParentOfType(node, PyFunction.class, true, PyClass.class);
|
||||
if (function == null) return;
|
||||
final Scope scope = ControlFlowCache.getScope(function);
|
||||
for (PyExpression expression : node.getTargets()) {
|
||||
final String name = expression.getName();
|
||||
for (Pair<PyExpression, PyExpression> pair : node.getTargetsToValuesMapping()) {
|
||||
final String name = pair.getFirst().getName();
|
||||
if (name == null || scope.isGlobal(name)) continue;
|
||||
if (expression instanceof PyTargetExpression) {
|
||||
final PyExpression qualifier = ((PyTargetExpression)expression).getQualifier();
|
||||
if (pair.getFirst() instanceof PyTargetExpression) {
|
||||
final PyExpression qualifier = ((PyTargetExpression)pair.getFirst()).getQualifier();
|
||||
if (qualifier != null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final PyCallExpression assignedValue = PyUtil.as(pair.getSecond(), PyCallExpression.class);
|
||||
if (assignedValue != null
|
||||
&& assignedValue.getCallee() != null && PyNames.NAMEDTUPLE.equals(assignedValue.getCallee().getName())) {
|
||||
return;
|
||||
}
|
||||
final String errorCode = "N806";
|
||||
if (!LOWERCASE_REGEX.matcher(name).matches() && !name.startsWith("_") && !ignoredErrors.contains(errorCode)) {
|
||||
registerAndAddRenameAndIgnoreErrorQuickFixes(expression, errorCode);
|
||||
registerAndAddRenameAndIgnoreErrorQuickFixes(pair.getFirst(), errorCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
from collections import namedtuple
|
||||
|
||||
def f():
|
||||
Point = namedtuple("Point", ["x1", "x2"], verbose=True)
|
||||
<weak_warning descr="Variable in function should be lowercase">Test</weak_warning> = "foo"
|
||||
@@ -112,6 +112,10 @@ public class PyPep8NamingInspectionTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNamedTupleInsideFunction() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testOverrideFromModule() {
|
||||
myFixture.configureByFiles("inspections/PyPep8NamingInspection/" + getTestName(true) + ".py",
|
||||
"inspections/PyPep8NamingInspection/tmp1.py");
|
||||
|
||||
Reference in New Issue
Block a user