diff --git a/docs/configuration.md b/docs/configuration.md index ba4a0c8aa..56784d1f6 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -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" | diff --git a/packages/pyright-internal/src/common/configOptions.ts b/packages/pyright-internal/src/common/configOptions.ts index 5d3770b5c..afbdf6605 100644 --- a/packages/pyright-internal/src/common/configOptions.ts +++ b/packages/pyright-internal/src/common/configOptions.ts @@ -369,7 +369,7 @@ export function getOffDiagnosticRuleSet(): DiagnosticRuleSet { reportAssertAlwaysTrue: 'none', reportSelfClsParameterName: 'none', reportImplicitStringConcatenation: 'none', - reportUnboundVariable: 'warning', + reportUnboundVariable: 'none', reportUndefinedVariable: 'warning', reportInvalidStubStatement: 'none', reportUnsupportedDunderAll: 'none', diff --git a/packages/pyright-internal/src/tests/samples/forLoops1.py b/packages/pyright-internal/src/tests/samples/forLoop1.py similarity index 100% rename from packages/pyright-internal/src/tests/samples/forLoops1.py rename to packages/pyright-internal/src/tests/samples/forLoop1.py diff --git a/packages/pyright-internal/src/tests/samples/forLoop2.py b/packages/pyright-internal/src/tests/samples/forLoop2.py new file mode 100644 index 000000000..d3d7ddb16 --- /dev/null +++ b/packages/pyright-internal/src/tests/samples/forLoop2.py @@ -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) diff --git a/packages/pyright-internal/src/tests/typeEvaluator1.test.ts b/packages/pyright-internal/src/tests/typeEvaluator1.test.ts index 94f254eaa..a9b4e52b9 100644 --- a/packages/pyright-internal/src/tests/typeEvaluator1.test.ts +++ b/packages/pyright-internal/src/tests/typeEvaluator1.test.ts @@ -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']);