Skip to content

Commit

Permalink
#173: Added type checker knowledge of the built-in type "ModuleType" …
Browse files Browse the repository at this point in the history
…so imported modules are assignable to this type.
  • Loading branch information
msfterictraut committed Jul 19, 2019
1 parent 051e32c commit 1ca24e0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions server/src/analyzer/sourceFile.ts
Expand Up @@ -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') {
Expand Down
5 changes: 5 additions & 0 deletions server/src/analyzer/typeUtils.ts
Expand Up @@ -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;
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions server/src/tests/samples/module2.py
@@ -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)
6 changes: 6 additions & 0 deletions server/src/tests/typeAnalyzer.test.ts
Expand Up @@ -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']);

Expand Down

0 comments on commit 1ca24e0

Please sign in to comment.