mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
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:
parent
8a6dcca91a
commit
ad17925f50
@ -91,7 +91,13 @@
|
|||||||
"pyright.openFilesOnly": {
|
"pyright.openFilesOnly": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true,
|
"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"
|
"scope": "resource"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.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.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.
|
**python.pythonPath** [path]: Path to Python interpreter.
|
||||||
|
@ -36,10 +36,6 @@ import { TypeStubWriter } from './typeStubWriter';
|
|||||||
|
|
||||||
const _maxImportDepth = 256;
|
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 {
|
export interface SourceFileInfo {
|
||||||
sourceFile: SourceFile;
|
sourceFile: SourceFile;
|
||||||
isTracked: boolean;
|
isTracked: boolean;
|
||||||
@ -968,7 +964,7 @@ export class Program {
|
|||||||
private _isImportAllowed(importer: SourceFileInfo, importResult: ImportResult,
|
private _isImportAllowed(importer: SourceFileInfo, importResult: ImportResult,
|
||||||
isImportStubFile: boolean): boolean {
|
isImportStubFile: boolean): boolean {
|
||||||
|
|
||||||
let thirdPartyImportAllowed = _allowAllThirdPartyImports;
|
let thirdPartyImportAllowed = this._configOptions.useLibraryCodeForTypes;
|
||||||
|
|
||||||
if (importResult.importType === ImportType.ThirdParty ||
|
if (importResult.importType === ImportType.ThirdParty ||
|
||||||
(importer.isThirdPartyImport && importResult.importType === ImportType.Local)) {
|
(importer.isThirdPartyImport && importResult.importType === ImportType.Local)) {
|
||||||
|
@ -328,6 +328,7 @@ export class AnalyzerService {
|
|||||||
|
|
||||||
configOptions.verboseOutput = !!commandLineOptions.verboseOutput;
|
configOptions.verboseOutput = !!commandLineOptions.verboseOutput;
|
||||||
configOptions.checkOnlyOpenFiles = !!commandLineOptions.checkOnlyOpenFiles;
|
configOptions.checkOnlyOpenFiles = !!commandLineOptions.checkOnlyOpenFiles;
|
||||||
|
configOptions.useLibraryCodeForTypes = !!commandLineOptions.useLibraryCodeForTypes;
|
||||||
|
|
||||||
// Do some sanity checks on the specified settings and report missing
|
// Do some sanity checks on the specified settings and report missing
|
||||||
// or inconsistent information.
|
// or inconsistent information.
|
||||||
|
@ -49,6 +49,10 @@ export class CommandLineOptions {
|
|||||||
// Indicates that only open files should be checked.
|
// Indicates that only open files should be checked.
|
||||||
checkOnlyOpenFiles?: boolean;
|
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
|
// Indicates that the settings came from VS Code rather than
|
||||||
// from the command-line. Useful for providing clearer error
|
// from the command-line. Useful for providing clearer error
|
||||||
// messages.
|
// messages.
|
||||||
|
@ -332,6 +332,10 @@ export class ConfigOptions {
|
|||||||
// Perform type checking and report diagnostics only for open files?
|
// Perform type checking and report diagnostics only for open files?
|
||||||
checkOnlyOpenFiles: boolean;
|
checkOnlyOpenFiles: boolean;
|
||||||
|
|
||||||
|
// In the absence of type stubs, use library implementations to extract
|
||||||
|
// type information?
|
||||||
|
useLibraryCodeForTypes: boolean;
|
||||||
|
|
||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------
|
||||||
// Diagnostics Settings
|
// Diagnostics Settings
|
||||||
|
|
||||||
|
@ -110,6 +110,7 @@ function processArgs() {
|
|||||||
|
|
||||||
options.verboseOutput = !!args.verbose;
|
options.verboseOutput = !!args.verbose;
|
||||||
options.checkOnlyOpenFiles = false;
|
options.checkOnlyOpenFiles = false;
|
||||||
|
options.useLibraryCodeForTypes = false;
|
||||||
|
|
||||||
const watch = args.watch !== undefined;
|
const watch = args.watch !== undefined;
|
||||||
options.watch = watch;
|
options.watch = watch;
|
||||||
|
@ -33,6 +33,7 @@ interface PythonSettings {
|
|||||||
interface PyrightSettings {
|
interface PyrightSettings {
|
||||||
disableLanguageServices?: boolean;
|
disableLanguageServices?: boolean;
|
||||||
openFilesOnly?: boolean;
|
openFilesOnly?: boolean;
|
||||||
|
useLibraryCodeForTypes?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface WorkspaceServiceInstance {
|
interface WorkspaceServiceInstance {
|
||||||
@ -618,6 +619,8 @@ function updateOptionsAndRestartService(workspace: WorkspaceServiceInstance,
|
|||||||
commandLineOptions.watch = true;
|
commandLineOptions.watch = true;
|
||||||
commandLineOptions.checkOnlyOpenFiles = pyrightSettings ?
|
commandLineOptions.checkOnlyOpenFiles = pyrightSettings ?
|
||||||
!!pyrightSettings.openFilesOnly : true;
|
!!pyrightSettings.openFilesOnly : true;
|
||||||
|
commandLineOptions.useLibraryCodeForTypes = pyrightSettings ?
|
||||||
|
!!pyrightSettings.useLibraryCodeForTypes : false;
|
||||||
|
|
||||||
if (pythonSettings.venvPath) {
|
if (pythonSettings.venvPath) {
|
||||||
commandLineOptions.venvPath = combinePaths(workspace.rootPath || _rootPath,
|
commandLineOptions.venvPath = combinePaths(workspace.rootPath || _rootPath,
|
||||||
|
Loading…
Reference in New Issue
Block a user