Changed the reportUnboundVariable default severity from "warning" to "none" when typeCheckingMode is "off". There were too many complaints of false positives from users who have no interest in type checking.

This commit is contained in:
Eric Traut 2021-02-05 21:57:48 -08:00
parent df5bf6551b
commit 36c168c1ae
5 changed files with 58 additions and 4 deletions

View File

@ -271,7 +271,7 @@ The following table lists the default severity levels for each diagnostic rule w
| reportSelfClsParameterName | "none" | "warning" | "error" |
| reportImplicitStringConcatenation | "none" | "none" | "none" |
| reportUndefinedVariable | "warning" | "error" | "error" |
| reportUnboundVariable | "warning" | "error" | "error" |
| reportUnboundVariable | "none" | "error" | "error" |
| reportInvalidStubStatement | "none" | "none" | "error" |
| reportUnsupportedDunderAll | "none" | "warning" | "error" |
| reportUnusedCallResult | "none" | "none" | "none" |

View File

@ -369,7 +369,7 @@ export function getOffDiagnosticRuleSet(): DiagnosticRuleSet {
reportAssertAlwaysTrue: 'none',
reportSelfClsParameterName: 'none',
reportImplicitStringConcatenation: 'none',
reportUnboundVariable: 'warning',
reportUnboundVariable: 'none',
reportUndefinedVariable: 'warning',
reportInvalidStubStatement: 'none',
reportUnsupportedDunderAll: 'none',

View File

@ -0,0 +1,48 @@
# This sample tests for/else loops for cases where variables
# are potentially unbound.
# For with no break and no else.
def func1():
for x in []:
a = 0
# This should generate a "potentially unbound" error.
print(a)
# This should generate a "potentially unbound" error.
print(x)
# For with no break and else.
def func2():
for x in []:
a = 0
else:
b = 0
# This should generate a "potentially unbound" error.
print(a)
print(b)
# This should generate a "potentially unbound" error.
print(x)
# For with break and else.
def func3():
for x in []:
a = 0
break
else:
b = 0
# This should generate a "potentially unbound" error.
print(a)
# This should generate a "potentially unbound" error.
print(b)
# This should generate a "potentially unbound" error.
print(x)

View File

@ -966,12 +966,18 @@ test('Loops6', () => {
TestUtils.validateResults(analysisResults, 0);
});
test('ForLoops1', () => {
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['forLoops1.py']);
test('ForLoop1', () => {
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['forLoop1.py']);
TestUtils.validateResults(analysisResults, 2);
});
test('ForLoop2', () => {
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['forLoop2.py']);
TestUtils.validateResults(analysisResults, 7);
});
test('ListComprehension1', () => {
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['listComprehension1.py']);