mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
Added code to prevent "variable possibly unbound" error from propagating to other variables. It should be reported only once.
This commit is contained in:
parent
c92434483f
commit
a97a5878d3
@ -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;
|
||||
|
@ -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('.');
|
||||
|
||||
|
14
server/src/tests/samples/unbound3.py
Normal file
14
server/src/tests/samples/unbound3.py
Normal 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
|
||||
|
Loading…
Reference in New Issue
Block a user