mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
fix false positive of 'from __future__ import' inspection
This commit is contained in:
@@ -1,16 +1,12 @@
|
||||
package com.jetbrains.python.inspections;
|
||||
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.PyNames;
|
||||
import com.jetbrains.python.actions.MoveFromFutureImportQuickFix;
|
||||
import com.jetbrains.python.psi.PyFile;
|
||||
import com.jetbrains.python.psi.PyFromImportStatement;
|
||||
import com.jetbrains.python.psi.PyReferenceExpression;
|
||||
import com.jetbrains.python.psi.PyStatement;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -46,7 +42,14 @@ public class PyFromFutureImportInspection extends PyInspection {
|
||||
PsiFile file = importSource.getContainingFile();
|
||||
if (file instanceof PyFile) {
|
||||
final List<PyStatement> statementList = ((PyFile)file).getStatements();
|
||||
boolean skippedDocString = false;
|
||||
for (PyStatement statement : statementList) {
|
||||
if (statement instanceof PyExpressionStatement &&
|
||||
((PyExpressionStatement) statement).getExpression() instanceof PyStringLiteralExpression &&
|
||||
!skippedDocString) {
|
||||
skippedDocString = true;
|
||||
continue;
|
||||
}
|
||||
if (statement instanceof PyFromImportStatement) {
|
||||
if (statement == node) {
|
||||
return;
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>test.py</file>
|
||||
<line>7</line>
|
||||
<description>from __future__ imports must occur at the beginning of the file</description>
|
||||
</problem>
|
||||
</problems>
|
||||
@@ -0,0 +1,3 @@
|
||||
# This is a comment
|
||||
""" This is a module docstring """
|
||||
from __future__ import print_function
|
||||
@@ -0,0 +1,7 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
|
||||
class A:
|
||||
pass
|
||||
|
||||
<warning descr="from __future__ imports must occur at the beginning of the file">from __future__ import with_statement</warning>
|
||||
@@ -2,7 +2,6 @@ package com.jetbrains.python;
|
||||
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.jetbrains.python.fixtures.PyLightFixtureTestCase;
|
||||
import com.jetbrains.python.inspections.*;
|
||||
import com.jetbrains.python.psi.LanguageLevel;
|
||||
@@ -164,8 +163,15 @@ public class PythonInspectionsTest extends PyLightFixtureTestCase {
|
||||
}
|
||||
|
||||
public void testPyFromFutureImportInspection() throws Throwable {
|
||||
LocalInspectionTool inspection = new PyFromFutureImportInspection();
|
||||
doTest(getTestName(false), inspection);
|
||||
myFixture.configureByFile("inspections/" + getTestName(true) + "/test.py");
|
||||
myFixture.enableInspections(PyFromFutureImportInspection.class);
|
||||
myFixture.checkHighlighting(true, false, false);
|
||||
}
|
||||
|
||||
public void testPyFromFutureImportInspectionDocString() throws Throwable {
|
||||
myFixture.configureByFile("inspections/PyFromFutureImportInspection/module_docstring.py");
|
||||
myFixture.enableInspections(PyFromFutureImportInspection.class);
|
||||
myFixture.checkHighlighting(true, false, false);
|
||||
}
|
||||
|
||||
public void testPyComparisonWithNoneInspection() throws Throwable {
|
||||
|
||||
Reference in New Issue
Block a user