mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 16:06:39 +03:00
Fixed regression where modules imported with "import X" statement were reported as unbound if there was no type stub found.
This commit is contained in:
parent
4988097618
commit
44108dc8e7
@ -22,10 +22,10 @@ import * as assert from 'assert';
|
||||
import { DiagnosticLevel } from '../common/configOptions';
|
||||
import { PythonVersion } from '../common/pythonVersion';
|
||||
import { TextRange } from '../common/textRange';
|
||||
import { AwaitExpressionNode, ClassNode, ErrorExpressionNode, ExpressionNode,
|
||||
FunctionNode, GlobalNode, IfNode, LambdaNode, ModuleNameNode, ModuleNode,
|
||||
NameNode, NonlocalNode, RaiseNode, StringNode, SuiteNode, TryNode, WhileNode,
|
||||
YieldExpressionNode, YieldFromExpressionNode } from '../parser/parseNodes';
|
||||
import { AwaitExpressionNode, ClassNode, DelNode, ErrorExpressionNode,
|
||||
ExpressionNode, FunctionNode, GlobalNode, IfNode, LambdaNode, ModuleNameNode,
|
||||
ModuleNode, NameNode, NonlocalNode, RaiseNode, StringNode, SuiteNode, TryNode,
|
||||
WhileNode, YieldExpressionNode, YieldFromExpressionNode } from '../parser/parseNodes';
|
||||
import { StringTokenFlags } from '../parser/tokenizerTypes';
|
||||
import { ScopeUtils } from '../scopeUtils';
|
||||
import { AnalyzerFileInfo } from './analyzerFileInfo';
|
||||
|
@ -1275,6 +1275,21 @@ export class TypeAnalyzer extends ParseTreeWalker {
|
||||
this._bindMultiPartModuleNameToType(node.module.nameParts,
|
||||
moduleType, moduleDeclaration);
|
||||
}
|
||||
} else {
|
||||
// We were unable to resolve the import. Bind the names (or alias)
|
||||
// to an unknown type.
|
||||
const symbolType = UnknownType.create();
|
||||
const nameNode = node.module.nameParts.length > 0 ? node.module.nameParts[0] : undefined;
|
||||
const aliasNode = node.alias || nameNode;
|
||||
|
||||
if (node.alias && nameNode) {
|
||||
this._updateExpressionTypeForNode(nameNode, symbolType);
|
||||
}
|
||||
|
||||
if (aliasNode) {
|
||||
this._assignTypeToNameNode(aliasNode, symbolType);
|
||||
this._updateExpressionTypeForNode(aliasNode, symbolType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1375,7 +1390,7 @@ export class TypeAnalyzer extends ParseTreeWalker {
|
||||
if (node.imports.length !== 0) {
|
||||
node.imports.forEach(importAs => {
|
||||
const aliasNode = importAs.alias || importAs.name;
|
||||
let symbolType = UnknownType.create();
|
||||
const symbolType = UnknownType.create();
|
||||
|
||||
this._updateExpressionTypeForNode(importAs.name, symbolType);
|
||||
if (importAs.alias) {
|
||||
|
Loading…
Reference in New Issue
Block a user