#173: Added type checker knowledge of the built-in type "ModuleType" so imported modules are assignable to this type.

This commit is contained in:
Eric Traut 2019-07-19 10:45:37 -07:00
parent 051e32cb96
commit 1ca24e034c
4 changed files with 19 additions and 0 deletions

View File

@ -161,6 +161,7 @@ export class SourceFile {
this._isBuiltInStubFile = false;
if (this._isStubFile) {
if (this._filePath.endsWith('/collections/__init__.pyi') ||
fileName === '_importlib_modulespec.pyi' ||
fileName === 'dataclasses.pyi' ||
fileName === 'abc.pyi' ||
fileName === 'enum.pyi') {

View File

@ -420,6 +420,11 @@ export class TypeUtils {
}
return true;
}
} else if (srcType instanceof ModuleType) {
// Is the destination the built-in "ModuleType"?
if (destClassType.isBuiltIn() && destClassType.getClassName() === 'ModuleType') {
return true;
}
}
}

View File

@ -0,0 +1,7 @@
# This sample tests that a module is assignable
# to the built-in type "ModuleType".
import typing
import importlib
importlib.reload(typing)

View File

@ -331,6 +331,12 @@ test('Module1', () => {
validateResults(analysisResults, 0);
});
test('Module2', () => {
let analysisResults = TestUtils.typeAnalyzeSampleFiles(['module2.py']);
validateResults(analysisResults, 0);
});
test('Ellipsis1', () => {
let analysisResults = TestUtils.typeAnalyzeSampleFiles(['ellipsis1.pyi']);