mirror of
https://github.com/microsoft/pyright.git
synced 2024-10-26 19:01:08 +03:00
#173: Added type checker knowledge of the built-in type "ModuleType" so imported modules are assignable to this type.
This commit is contained in:
parent
051e32cb96
commit
1ca24e034c
@ -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') {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
7
server/src/tests/samples/module2.py
Normal file
7
server/src/tests/samples/module2.py
Normal 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)
|
@ -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']);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user