Changed priority of shadowed names inspection to weak warning

This commit is contained in:
Andrey Vlasovskikh
2013-09-04 18:46:19 +04:00
parent 208c44b022
commit 682d2ad537
6 changed files with 42 additions and 31 deletions
+1 -1
View File
@@ -323,7 +323,7 @@
<localInspection language="Python" shortName="PyProtectedMemberInspection" displayName="Access to a protected member of a class" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WEAK WARNING" implementationClass="com.jetbrains.python.inspections.PyProtectedMemberInspection"/>
<localInspection language="Python" shortName="PyMethodMayBeStaticInspection" displayName="Method may be static" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WEAK WARNING" implementationClass="com.jetbrains.python.inspections.PyMethodMayBeStaticInspection"/>
<localInspection language="Python" shortName="PyDocstringTypesInspection" bundle="com.jetbrains.python.PyBundle" key="INSP.NAME.docstring.types" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WEAK WARNING" implementationClass="com.jetbrains.python.inspections.PyDocstringTypesInspection"/>
<localInspection language="Python" shortName="PyShadowingNamesInspection" displayName="Shadowing names" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WARNING" implementationClass="com.jetbrains.python.inspections.PyShadowingNamesInspection"/>
<localInspection language="Python" shortName="PyShadowingNamesInspection" displayName="Shadowing names" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WEAK WARNING" implementationClass="com.jetbrains.python.inspections.PyShadowingNamesInspection"/>
<localInspection language="Python" shortName="PyAbstractClassInspection" displayName="Class must implement all abstract methods" groupKey="INSP.GROUP.python" enabledByDefault="true" level="WARNING" implementationClass="com.jetbrains.python.inspections.PyAbstractClassInspection"/>
<localInspection language="Python" shortName="PyPep8NamingInspection" displayName="PEP 8 naming convention violation" groupKey="INSP.GROUP.python" enabledByDefault="true" level="INFO" implementationClass="com.jetbrains.python.inspections.PyPep8NamingInspection"/>
@@ -107,7 +107,7 @@ public class PyShadowingNamesInspection extends PyInspection {
@NotNull PsiElement builtin) {
if (!PyUtil.inSameFile(builtin, element)) {
registerProblem(problemElement, String.format("Shadows built-in name '%s'", name),
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, null, new PyRenameElementQuickFix(),
ProblemHighlightType.WEAK_WARNING, null, new PyRenameElementQuickFix(),
new PyIgnoreBuiltinQuickFix(name));
}
}
@@ -125,7 +125,7 @@ public class PyShadowingNamesInspection extends PyInspection {
final PsiElement resolved = processor.getResult();
if (resolved != null) {
registerProblem(problemElement, String.format("Shadows name '%s' from outer scope", name),
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, null, new PyRenameElementQuickFix());
ProblemHighlightType.WEAK_WARNING, null, new PyRenameElementQuickFix());
}
}
}
@@ -1,37 +1,37 @@
def test_import_builtin_names():
import float
from foo import float
from bar import baz as <warning descr="Shadows built-in name 'float'">float</warning>
from bar import baz as <weak_warning descr="Shadows built-in name 'float'">float</weak_warning>
def test_builtin_function_parameters():
def test1(x, _, <warning descr="Shadows built-in name 'len'">len</warning>, <warning descr="Shadows built-in name 'file'">file</warning>=None):
def test1(x, _, <weak_warning descr="Shadows built-in name 'len'">len</weak_warning>, <weak_warning descr="Shadows built-in name 'file'">file</weak_warning>=None):
pass
def test_builtin_function_name():
def <warning descr="Shadows built-in name 'list'">list</warning>():
def <weak_warning descr="Shadows built-in name 'list'">list</weak_warning>():
pass
def test_builtin_assignment_targets():
foo = 2
<warning descr="Shadows built-in name 'list'">list</warning> = []
for <warning descr="Shadows built-in name 'int'">int</warning> in range(10):
<weak_warning descr="Shadows built-in name 'list'">list</weak_warning> = []
for <weak_warning descr="Shadows built-in name 'int'">int</weak_warning> in range(10):
print(int)
<warning descr="Shadows built-in name 'range'">range</warning> = []
<warning descr="Shadows built-in name 'list'">list</warning>, _ = (1, 2)
return [int for <warning descr="Shadows built-in name 'int'">int</warning> in range(10)]
<weak_warning descr="Shadows built-in name 'range'">range</weak_warning> = []
<weak_warning descr="Shadows built-in name 'list'">list</weak_warning>, _ = (1, 2)
return [int for <weak_warning descr="Shadows built-in name 'int'">int</weak_warning> in range(10)]
def test_builtin_class_name():
class <warning descr="Shadows built-in name 'list'">list</warning>(object):
class <weak_warning descr="Shadows built-in name 'list'">list</weak_warning>(object):
pass
def test_builtin_method_name():
class C:
def <warning descr="Shadows built-in name 'list'">list</warning>(self):
def <weak_warning descr="Shadows built-in name 'list'">list</weak_warning>(self):
pass
@@ -47,18 +47,18 @@ def test_builtin_qualified_name():
# PY-10164
def test_builtin_class_attribute():
class C:
<warning descr="Shadows built-in name 'id'">id</warning> = 1
<weak_warning descr="Shadows built-in name 'id'">id</weak_warning> = 1
def test_outer_function():
foo = 1
def bar():
<warning descr="Shadows name 'foo' from outer scope">foo</warning>, <warning descr="Shadows name 'bar' from outer scope">bar</warning> = 1, 2
def baz(<warning descr="Shadows name 'foo' from outer scope">foo</warning>, <warning descr="Shadows name 'bar' from outer scope">bar</warning>, <warning descr="Shadows name 'baz' from outer scope">baz</warning>):
<weak_warning descr="Shadows name 'foo' from outer scope">foo</weak_warning>, <weak_warning descr="Shadows name 'bar' from outer scope">bar</weak_warning> = 1, 2
def baz(<weak_warning descr="Shadows name 'foo' from outer scope">foo</weak_warning>, <weak_warning descr="Shadows name 'bar' from outer scope">bar</weak_warning>, <weak_warning descr="Shadows name 'baz' from outer scope">baz</weak_warning>):
pass
def nested():
def <warning descr="Shadows name 'baz' from outer scope">baz</warning>(<warning descr="Shadows name 'foo' from outer scope">foo</warning>):
<warning descr="Shadows name 'bar' from outer scope">bar</warning> = 1
def <weak_warning descr="Shadows name 'baz' from outer scope">baz</weak_warning>(<weak_warning descr="Shadows name 'foo' from outer scope">foo</weak_warning>):
<weak_warning descr="Shadows name 'bar' from outer scope">bar</weak_warning> = 1
def test_outer_class():
@@ -68,16 +68,16 @@ def test_outer_class():
class C(object):
def foo(self):
def foo():
def <warning descr="Shadows name 'bar' from outer scope">bar</warning>():
class <warning descr="Shadows name 'C' from outer scope">C</warning>:
def <warning descr="Shadows name 'baz' from outer scope">baz</warning>(self):
def <weak_warning descr="Shadows name 'bar' from outer scope">bar</weak_warning>():
class <weak_warning descr="Shadows name 'C' from outer scope">C</weak_warning>:
def <weak_warning descr="Shadows name 'baz' from outer scope">baz</weak_warning>(self):
pass
def bar():
pass
<warning descr="Shadows name 'baz' from outer scope">baz</warning> = 2
<weak_warning descr="Shadows name 'baz' from outer scope">baz</weak_warning> = 2
def <warning descr="Shadows name 'spam' from outer scope">spam</warning>(self):
def <weak_warning descr="Shadows name 'spam' from outer scope">spam</weak_warning>(self):
pass
<warning descr="Shadows name 'quux' from outer scope">quux</warning> = 1
<weak_warning descr="Shadows name 'quux' from outer scope">quux</weak_warning> = 1
@@ -1,4 +1,4 @@
def <warning descr="Shadows a built-in with the same name">i<caret>d</warning>(x):
def <weak_warning descr="Shadows built-in name 'id'">i<caret>d</weak_warning>(x):
return x
@@ -1,3 +1,3 @@
def f(name):
<warning descr="Shadows a built-in with the same name">f<caret>ile</warning> = open(name, 'rb')
<weak_warning descr="Shadows built-in name 'file'">f<caret>ile</weak_warning> = open(name, 'rb')
return file.read()
@@ -431,15 +431,26 @@ public class PyQuickFixTest extends PyTestCase {
// PY-8788
public void testRenameShadowingBuiltins() {
doInspectionTest("RenameShadowingBuiltins.py", PyShadowingNamesInspection.class,
"Rename element", true, true);
final String fileName = "RenameShadowingBuiltins.py";
myFixture.configureByFile(fileName);
myFixture.enableInspections(PyShadowingNamesInspection.class);
myFixture.checkHighlighting(true, false, true);
final IntentionAction intentionAction = myFixture.getAvailableIntention("Rename element");
assertNotNull(intentionAction);
myFixture.launchAction(intentionAction);
myFixture.checkResultByFile(graftBeforeExt(fileName, "_after"));
}
// PY-8788
public void testRenameFunctionShadowingBuiltins() {
doInspectionTest("RenameFunctionShadowingBuiltins.py", PyShadowingNamesInspection.class,
"Rename element", true, true);
final String fileName = "RenameFunctionShadowingBuiltins.py";
myFixture.configureByFile(fileName);
myFixture.enableInspections(PyShadowingNamesInspection.class);
myFixture.checkHighlighting(true, false, true);
final IntentionAction intentionAction = myFixture.getAvailableIntention("Rename element");
assertNotNull(intentionAction);
myFixture.launchAction(intentionAction);
myFixture.checkResultByFile(graftBeforeExt(fileName, "_after"));
}
@Override