Added code to prevent "variable possibly unbound" error from propagating to other variables. It should be reported only once.

This commit is contained in:
Eric Traut 2020-07-05 14:56:29 -07:00
parent c92434483f
commit a97a5878d3
3 changed files with 25 additions and 0 deletions

View File

@ -2440,6 +2440,11 @@ export function createTypeEvaluator(importLookup: ImportLookup, printTypeFlags:
}
}
// If the type was partially unbound, an error will have already been logged.
// Remove the unbound before assigning to the target expression so the unbound
// error doesn't propagate.
type = removeUnboundFromUnion(type);
switch (target.nodeType) {
case ParseNodeType.Name: {
const name = target;

View File

@ -1104,6 +1104,12 @@ test('Unbound2', () => {
validateResults(analysisResults, 1);
});
test('Unbound3', () => {
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['unbound3.py']);
validateResults(analysisResults, 1);
});
test('UnnecessaryCast', () => {
const configOptions = new ConfigOptions('.');

View File

@ -0,0 +1,14 @@
# This sample tests that "possibly unbound" error messages don't propagate.
def foo(a: bool):
if a:
b = 3
# This should generate an error.
c = b
# These should not.
d = c
e = d