PY-8325 Don't show unresolved reference warning inside format strings: show warnings provided by String Format Inspection

Merge remote-tracking branch 'origin/master'
This commit is contained in:
Valentina Kiryushkina
2017-05-15 14:37:53 +03:00
parent 4317349209
commit 03a05fc2eb
55 changed files with 47 additions and 224 deletions
@@ -41,6 +41,8 @@ import com.jetbrains.python.PyCustomType;
import com.jetbrains.python.PyNames;
import com.jetbrains.python.codeInsight.PyCodeInsightSettings;
import com.jetbrains.python.codeInsight.PyCustomMember;
import com.jetbrains.python.codeInsight.PyFunctionTypeCommentReferenceContributor;
import com.jetbrains.python.codeInsight.PySubstitutionChunkReference;
import com.jetbrains.python.codeInsight.controlflow.ScopeOwner;
import com.jetbrains.python.codeInsight.dataflow.scope.ScopeUtil;
import com.jetbrains.python.codeInsight.imports.AutoImportHintAction;
@@ -648,6 +650,10 @@ public class PyUnresolvedReferencesInspection extends PyInspection {
}
}
if (reference instanceof PySubstitutionChunkReference) {
return;
}
registerProblem(node, description, hl_type, null, rangeInElement, actions.toArray(new LocalQuickFix[actions.size()]));
}
@@ -0,0 +1,2 @@
print("{foo}".format(**dict({'foo': 'bar'})))
<warning descr="Too few mapping keys">"{}"</warning>.format()
@@ -0,0 +1 @@
print (<warning descr="Mapping key \"fst\" is unused">"first is {fst}"</warning>.format(**{1: "3"})<EOLError descr="')' expected"></EOLError>
@@ -0,0 +1 @@
print(<warning descr="Mapping key \"foo\" is unused">"{foo}"</warning>.format(**{}))
@@ -0,0 +1,6 @@
def foo():
return {"foo": "bar"}
print("pos: {} {} {}".format(1, *[2, 3]))
"%s" %<warning descr="Too few arguments for format string">()</warning>
@@ -0,0 +1,6 @@
def f():
return dict(foo=0)
'{foo}'.format(**f())
<warning descr="Too few mapping keys">"{}"</warning>.format()
@@ -0,0 +1,4 @@
ref = {"fst": 1, "snd": 2}
print "first is {fst}, second is {snd}".format(**ref)
<warning descr="Too few mapping keys">"{}"</warning>.format()
@@ -0,0 +1 @@
print(<warning descr="Too few mapping keys">'{}'</warning>.format(foo='foo'))
@@ -0,0 +1,2 @@
"{0}%64".format("cVar")
"%s" % <warning descr="Too few arguments for format string">()</warning>
@@ -0,0 +1 @@
"%(foo)s" % <warning descr="Format requires a mapping">[1, 2, 3]</warning>
@@ -0,0 +1 @@
"%(foo)s" % <warning descr="Format requires a mapping">{1, 2}</warning>
@@ -0,0 +1 @@
"%s%s" % <warning descr="Too few arguments for format string">{"foo": 1}</warning>
@@ -0,0 +1 @@
"%s%s" % <warning descr="Too few arguments for format string">[1, 2, 3]</warning>
@@ -0,0 +1,2 @@
"%s" % dict()
"%s" % <warning descr="Too few arguments for format string">()</warning>
@@ -0,0 +1,2 @@
"%s" % dict(a=1)
"%s" % <warning descr="Too few arguments for format string">()</warning>
@@ -0,0 +1 @@
var = "%s %s" % <warning descr="Too few arguments for format string">dict()</warning>, 1
@@ -0,0 +1,2 @@
"%s" % dict(a=1)["a"]
"%s" % <warning descr="Too few arguments for format string">()</warning>
@@ -0,0 +1,2 @@
var = "if (1 == x)\n{\n%s;\n}" % "return 0"
"%s" % <warning descr="Too few arguments for format string">()</warning>
@@ -1 +1,2 @@
<warning descr="Too few mapping keys">"{} {}"</warning>.format(1)
<warning descr="Too few mapping keys">"{} {}"</warning>.format(1)
<warning descr="Too few mapping keys">'{}'</warning>.format()
@@ -1 +1,2 @@
<warning descr="Mapping key \"name\" is unused">"{name}"</warning>.format()
<warning descr="Mapping key \"name\" is unused">"{name}"</warning>.format()
<warning descr="Mapping key \"foo\" is unused">'{foo}'</warning>.format(boo=1)
@@ -1 +0,0 @@
print ("first is %(<warning descr="Unresolved reference 'fst'">fst</warning>)s" % {1: "3"})
@@ -1 +0,0 @@
'{<warning descr="Unresolved reference 'foo'">foo</warning>}'.format(boo=1)
@@ -1,5 +0,0 @@
def f():
return dict(foo=0)
'{foo}'.format(**f())
@@ -1,2 +0,0 @@
ref = {"fst": 1, "snd": 2}
print "first is {fst}, second is {snd}".format(**ref)
@@ -1 +0,0 @@
v = '<warning descr="Unresolved reference '{}'">{}</warning>'.format()
@@ -1 +0,0 @@
print('<warning descr="Unresolved reference '{}'">{}</warning>'.format(foo='foo'))
@@ -1,3 +0,0 @@
def foo():
return 'foo'
print("{foo}".format(**{'bar': 10, foo(): 20}))
@@ -1 +0,0 @@
print("{foo}".format(**dict({'foo': 'bar'})))
@@ -1 +0,0 @@
print("{<warning descr="Unresolved reference 'foo'">foo</warning>}".format(**{}))
@@ -1,4 +0,0 @@
def foo():
return {"foo":"bar"}
print("pos: {} {} {}".format(1, *[2, 3]))
@@ -1,3 +0,0 @@
f = "fst"
s = "snd"
print ("first is %(fst)s, second is %(snd)s" % {s: "3", f: "1"})
@@ -1,4 +0,0 @@
def f():
return [1]
"%s" % f()
@@ -1 +0,0 @@
v = "first is %(<warning descr="Unresolved reference 'fst'">fst</warning>)s" % {"snd": 2}
@@ -1,2 +0,0 @@
snd = "snd"
print "%(f)s %(snd)s" % { "f": 2, 1: 1, snd: 2}
@@ -1 +0,0 @@
"%(<warning descr="Unresolved reference 'foo'">foo</warning>)s" % [1, 2, 3]
@@ -1 +0,0 @@
"%(<warning descr="Unresolved reference 'foo'">foo</warning>)s" % {1, 2}
@@ -1 +0,0 @@
"%(<warning descr="Unresolved reference 'foo'">foo</warning>)s" % (1,2,3)
@@ -1 +0,0 @@
"%s<warning descr="Unresolved reference '%s'">%s</warning>" % {"foo": 1}
@@ -1 +0,0 @@
"%s<warning descr="Unresolved reference '%s'">%s</warning>" % [1, 2, 3]
@@ -1 +0,0 @@
"%s<warning descr="Unresolved reference '%s'">%s</warning>" % {1, 2, 3}
@@ -1,2 +0,0 @@
d = {"fst": 1, "snd": 2}
print "first is %(fst)s, second is %(snd)s" % d
@@ -1,3 +0,0 @@
def f():
return 'foo', 'bar'
print('%s %s' % f())
@@ -1 +0,0 @@
var = "%s <warning descr="Unresolved reference '%s'">%s</warning>" % dict(), 1
@@ -1 +0,0 @@
"%s" % dict(a=1)["a"]
@@ -1 +0,0 @@
var = "if (1 == x)\n{\n%s;\n}" % "return 0"
@@ -529,71 +529,6 @@ public class PyUnresolvedReferencesInspectionTest extends PyInspectionTestCase {
public void testPropertyNotListedInSlots() {
doTest();
}
// PY-2748
public void testFormatStringPositional() {
doTest();
}
// PY-2748
public void testFormatStringKeyword() {
doTest();
}
// PY-2748
public void testPercentStringPositional() {
doTest();
}
// PY-2748
public void testPercentStringKeyword() {
doTest();
}
// PY-2748
public void testFormatStringPackedFunctionCall() {
doTest();
}
// PY-2748
public void testPercentStringFunctionCall() {
doTest();
}
// PY-2748
public void testFormatStringPackedReference() {
doTest();
}
// PY-2748
public void testPercentStringReference() {
doTest();
}
// PY-2748
public void testFormatStringDictLiteralArgumentWithReferenceExprKeys() {
doTest();
}
// PY-2748
public void testPercentStringDictLiteralArgumentWithReferenceExprKeys() {
doTest();
}
// PY-2748
public void testFormatStringDictLiteralArgumentWithNumericExprKeys() {
doTest();
}
// PY-18769
public void testFormatStringInRegularExpressions() {
doTest();
}
// PY-18751
public void testFormatStringInMapExpression() {
doTest();
}
// PY-18751
public void testStringWithFormatSyntax() {
@@ -605,82 +540,6 @@ public class PyUnresolvedReferencesInspectionTest extends PyInspectionTestCase {
doTest();
}
// PY-18751
public void testPercentStringWithFormatStringReplacementSymbols() {
doTest();
}
// PY-18751, PY-18824
public void testFormatStringWithPercentStringReplacementSymbols() {
doTest();
}
// PY-18837
public void testPercentStringWithDictArgument() {
doTest();
}
// PY-18115
public void testPercentStringWithDictCallArgument() {
doTest();
}
// PY-18115
public void testPercentStringWithTupleSlicing() {
doTest();
}
// PY-18115
public void testPercentStringWithDictElement() {
doTest();
}
// PY-18115
public void testPercentStringWithEmptyDict() {
doTest();
}
// PY-18115
public void testPercentStringWithDictCall() {
doTest();
}
// PY-18115
public void testFormatStringPositionalSubstitutionWithDictArg() {
doTest();
}
// PY-18115
public void testPercentStringWithCallArgument() {
doTest();
}
// PY-18115
public void testFormatStringWithEmptyDictArg() {
doTest();
}
// PY-18115
public void testFormatStringWithDictLiteralExprInsideDictCall() {
doTest();
}
// PY-18115
public void testFormatStringWithDictArgWithCallExprKey() {
doTest();
}
// PY-18115
public void testFormatStringWithPackedAndNonPackedArgs() {
doTest();
}
// PY-18950
public void testPercentStringKeywordArgumentWithReferenceKeyDictArgument() {
doTest();
}
// PY-18254
public void testVarargsAnnotatedWithFunctionComment() {
doTest();
@@ -691,42 +550,12 @@ public class PyUnresolvedReferencesInspectionTest extends PyInspectionTestCase {
myFixture.copyDirectoryToProject("typing", "");
runWithLanguageLevel(LanguageLevel.PYTHON30, this::doTest);
}
// PY-22620
public void testTupleTypeCommentsUseImportsFromTyping() {
myFixture.copyDirectoryToProject("typing", "");
doTest();
}
// PY-19084
public void testPercentStringPositionalListArgument() {
doTest();
}
// PY-19084
public void testPercentStringPositionalSetArgument() {
doTest();
}
// PY-19084
public void testPercentStringPositionalDictArgument() {
doTest();
}
// PY-19084
public void testPercentStringKeywordListArgument() {
doTest();
}
// PY-19084
public void testPercentStringKeywordSetArgument() {
doTest();
}
// PY-19084
public void testPercentStringKeywordTupleArgument() {
doTest();
}
// PY-13734
public void testDunderClass() {