Added new VS Code experimental setting "useLibraryCodeForTypes". If enabled, pyright will attempt to extract type information from library implementation files.

This commit is contained in:
Eric Traut 2019-11-19 21:50:27 -08:00
parent 8a6dcca91a
commit ad17925f50
8 changed files with 23 additions and 6 deletions

View File

@ -91,7 +91,13 @@
"pyright.openFilesOnly": {
"type": "boolean",
"default": true,
"description": "Report errors for all files in the workspace or only currently-open files?",
"description": "Report errors only for currently-open files.",
"scope": "resource"
},
"pyright.useLibraryCodeForTypes": {
"type": "boolean",
"default": false,
"description": "In the absence of type stub files, use library implementations to extract type information.",
"scope": "resource"
}
}

View File

@ -6,6 +6,8 @@ The Pyright VS Code extension honors the following settings.
**pyright.openFilesOnly** [boolean]: Determines whether pyright analyzes (and reports errors for) all files in the workspace, as indicated by the config file. If this option is set to true, pyright analyzes only open files.
**pyright.useLibraryCodeForTypes** [boolean]: Determines whether pyright reads, parses and analyzes library code to extract type information in the absence of type stub files. This can add significant overhead and may result in poor-quality type information. The default value for this option is false.
**python.analysis.typeshedPaths** [array of paths]: Paths to look for typeshed modules. Pyright currently honors only the first path in the array.
**python.pythonPath** [path]: Path to Python interpreter.

View File

@ -36,10 +36,6 @@ import { TypeStubWriter } from './typeStubWriter';
const _maxImportDepth = 256;
// We may enable this through a switch in future versions. For now,
// disable analysis of third-party library implementations.
const _allowAllThirdPartyImports = false;
export interface SourceFileInfo {
sourceFile: SourceFile;
isTracked: boolean;
@ -968,7 +964,7 @@ export class Program {
private _isImportAllowed(importer: SourceFileInfo, importResult: ImportResult,
isImportStubFile: boolean): boolean {
let thirdPartyImportAllowed = _allowAllThirdPartyImports;
let thirdPartyImportAllowed = this._configOptions.useLibraryCodeForTypes;
if (importResult.importType === ImportType.ThirdParty ||
(importer.isThirdPartyImport && importResult.importType === ImportType.Local)) {

View File

@ -328,6 +328,7 @@ export class AnalyzerService {
configOptions.verboseOutput = !!commandLineOptions.verboseOutput;
configOptions.checkOnlyOpenFiles = !!commandLineOptions.checkOnlyOpenFiles;
configOptions.useLibraryCodeForTypes = !!commandLineOptions.useLibraryCodeForTypes;
// Do some sanity checks on the specified settings and report missing
// or inconsistent information.

View File

@ -49,6 +49,10 @@ export class CommandLineOptions {
// Indicates that only open files should be checked.
checkOnlyOpenFiles?: boolean;
// In the absence of type stubs, use library implementations
// to extract type information?
useLibraryCodeForTypes?: boolean;
// Indicates that the settings came from VS Code rather than
// from the command-line. Useful for providing clearer error
// messages.

View File

@ -332,6 +332,10 @@ export class ConfigOptions {
// Perform type checking and report diagnostics only for open files?
checkOnlyOpenFiles: boolean;
// In the absence of type stubs, use library implementations to extract
// type information?
useLibraryCodeForTypes: boolean;
//---------------------------------------------------------------
// Diagnostics Settings

View File

@ -110,6 +110,7 @@ function processArgs() {
options.verboseOutput = !!args.verbose;
options.checkOnlyOpenFiles = false;
options.useLibraryCodeForTypes = false;
const watch = args.watch !== undefined;
options.watch = watch;

View File

@ -33,6 +33,7 @@ interface PythonSettings {
interface PyrightSettings {
disableLanguageServices?: boolean;
openFilesOnly?: boolean;
useLibraryCodeForTypes?: boolean;
}
interface WorkspaceServiceInstance {
@ -618,6 +619,8 @@ function updateOptionsAndRestartService(workspace: WorkspaceServiceInstance,
commandLineOptions.watch = true;
commandLineOptions.checkOnlyOpenFiles = pyrightSettings ?
!!pyrightSettings.openFilesOnly : true;
commandLineOptions.useLibraryCodeForTypes = pyrightSettings ?
!!pyrightSettings.useLibraryCodeForTypes : false;
if (pythonSettings.venvPath) {
commandLineOptions.venvPath = combinePaths(workspace.rootPath || _rootPath,