Removed reportTypeshedErrors diagnostic rule. It no longer makes sense given how errors are being reported.

This commit is contained in:
Eric Traut 2020-05-23 14:00:50 -07:00
parent 9efedddd31
commit 500da74c69
8 changed files with 14 additions and 70 deletions

View File

@ -122,12 +122,6 @@
"title": "Controls reporting of general type issues",
"default": "error"
},
"reportTypeshedErrors": {
"$id": "#/properties/reportTypeshedErrors",
"$ref": "#/definitions/diagnostic",
"title": "Controls reporting of errors found within typeshed stub files",
"default": "none"
},
"reportMissingImports": {
"$id": "#/properties/reportMissingImports",
"$ref": "#/definitions/diagnostic",

View File

@ -46,8 +46,6 @@ The following settings control pyrights diagnostic output (warnings or errors
**reportGeneralTypeIssues** [boolean or string, optional]: Generate or suppress diagnostics for general type inconsistencies, unsupported operations, argument/parameter mismatches, etc. This covers all of the basic type-checking rules not covered by other rules. It does not include syntax errors. The default value for this setting is 'error'.
**reportTypeshedErrors** [boolean or string, optional]: Generate or suppress diagnostics for typeshed type stub files. In general, these type stub files should be “clean” and generate no errors. The default value for this setting is 'none'.
**reportMissingImports** [boolean or string, optional]: Generate or suppress diagnostics for imports that have no corresponding imported python file or type stub file. The default value for this setting is 'none', although pyright can do a much better job of static type checking if type stub files are provided for all imports.
**reportMissingModuleSource** [boolean or string, optional]: Generate or suppress diagnostics for imports that have no corresponding source file. This happens when a type stub is found, but the module source file was not found, indicating that the code may fail at runtime when using this execution environment. Type checking will be done using the type stub. The default value for this setting is 'warning'.
@ -168,7 +166,6 @@ The following is an example of a pyright config file:
"stubPath": "src/typestubs",
"venvPath": "/home/foo/.venvs",
"reportTypeshedErrors": false,
"reportMissingImports": true,
"reportMissingTypeStubs": false,

View File

@ -174,7 +174,7 @@ export class Program {
return sourceFileInfo.sourceFile;
}
const sourceFile = new SourceFile(this._fs, filePath, false, false, this._console);
const sourceFile = new SourceFile(this._fs, filePath, false, this._console);
sourceFileInfo = {
sourceFile,
isTracked: true,
@ -192,7 +192,7 @@ export class Program {
setFileOpened(filePath: string, version: number | null, contents: string) {
let sourceFileInfo = this._sourceFileMap.get(filePath);
if (!sourceFileInfo) {
const sourceFile = new SourceFile(this._fs, filePath, false, false, this._console);
const sourceFile = new SourceFile(this._fs, filePath, false, this._console);
sourceFileInfo = {
sourceFile,
isTracked: false,
@ -509,7 +509,7 @@ export class Program {
return sourceFileInfo.sourceFile;
}
const sourceFile = new SourceFile(this._fs, filePath, false, false, this._console);
const sourceFile = new SourceFile(this._fs, filePath, false, this._console);
sourceFileInfo = {
sourceFile,
isTracked: true,
@ -624,10 +624,7 @@ export class Program {
}
// Don't bother checking third-party imports or typeshed files unless they're open.
if (
fileToCheck.isThirdPartyImport ||
(fileToCheck.isTypeshedFile && this._configOptions.diagnosticRuleSet.reportTypeshedErrors === 'none')
) {
if (fileToCheck.isThirdPartyImport || fileToCheck.isTypeshedFile) {
if (!fileToCheck.isOpenByClient) {
return false;
}
@ -1427,16 +1424,14 @@ export class Program {
}
});
} else if (options.verboseOutput) {
if (!sourceFileInfo.isTypeshedFile || options.diagnosticRuleSet.reportTypeshedErrors !== 'none') {
this._console.log(
`Could not import '${importResult.importName}' ` +
`in file '${sourceFileInfo.sourceFile.getFilePath()}'`
);
if (importResult.importFailureInfo) {
importResult.importFailureInfo.forEach((diag) => {
this._console.log(` ${diag}`);
});
}
this._console.log(
`Could not import '${importResult.importName}' ` +
`in file '${sourceFileInfo.sourceFile.getFilePath()}'`
);
if (importResult.importFailureInfo) {
importResult.importFailureInfo.forEach((diag) => {
this._console.log(` ${diag}`);
});
}
}
});
@ -1467,7 +1462,6 @@ export class Program {
const sourceFile = new SourceFile(
this._fs,
importPath,
importInfo.isTypeshedFile,
importInfo.isThirdPartyImport,
this._console
);

View File

@ -67,9 +67,6 @@ export class SourceFile {
// (.py) file.
private readonly _isStubFile: boolean;
// True if the file is a typeshed stub file.
private readonly _isTypeshedStubFile: boolean;
// True if the file was imported as a third-party import.
private readonly _isThirdPartyImport: boolean;
@ -148,18 +145,11 @@ export class SourceFile {
readonly fileSystem: FileSystem;
constructor(
fs: FileSystem,
filePath: string,
isTypeshedStubFile: boolean,
isThirdPartyImport: boolean,
console?: ConsoleInterface
) {
constructor(fs: FileSystem, filePath: string, isThirdPartyImport: boolean, console?: ConsoleInterface) {
this.fileSystem = fs;
this._console = console || new StandardConsole();
this._filePath = filePath;
this._isStubFile = filePath.endsWith('.pyi');
this._isTypeshedStubFile = isTypeshedStubFile;
this._isThirdPartyImport = isThirdPartyImport;
const fileName = getFileName(filePath);
this._isTypingStubFile =
@ -256,21 +246,6 @@ export class SourceFile {
);
}
if (this._isTypeshedStubFile) {
if (options.diagnosticRuleSet.reportTypeshedErrors === 'none') {
includeWarningsAndErrors = false;
} else {
// convert category to effective ones
const effectiveCategory = convertLevelToCategory(options.diagnosticRuleSet.reportTypeshedErrors);
diagList = diagList.map((diag) => {
if (diag.category !== effectiveCategory) {
return new Diagnostic(effectiveCategory, diag.message, diag.range);
}
return diag;
});
}
}
// If the file is in the ignore list, clear the diagnostic list.
if (options.ignore.find((ignoreFileSpec) => ignoreFileSpec.regExp.test(this._filePath))) {
diagList = [];

View File

@ -70,9 +70,6 @@ export interface DiagnosticRuleSet {
// Report general type issues?
reportGeneralTypeIssues: DiagnosticLevel;
// Report diagnostics in typeshed files?
reportTypeshedErrors: DiagnosticLevel;
// Report missing imports?
reportMissingImports: DiagnosticLevel;
@ -208,7 +205,6 @@ export function getBooleanDiagnosticRules() {
export function getDiagLevelDiagnosticRules() {
return [
DiagnosticRule.reportGeneralTypeIssues,
DiagnosticRule.reportTypeshedErrors,
DiagnosticRule.reportMissingImports,
DiagnosticRule.reportMissingModuleSource,
DiagnosticRule.reportMissingTypeStubs,
@ -264,7 +260,6 @@ export function getStrictDiagnosticRuleSet(): DiagnosticRuleSet {
strictParameterNoneValue: true,
enableTypeIgnoreComments: true, // Not overridden by strict mode
reportGeneralTypeIssues: 'error',
reportTypeshedErrors: 'error',
reportMissingImports: 'error',
reportMissingModuleSource: 'warning',
reportMissingTypeStubs: 'error',
@ -316,7 +311,6 @@ export function getNoTypeCheckingDiagnosticRuleSet(): DiagnosticRuleSet {
strictParameterNoneValue: false,
enableTypeIgnoreComments: true,
reportGeneralTypeIssues: 'none',
reportTypeshedErrors: 'none',
reportMissingImports: 'warning',
reportMissingModuleSource: 'warning',
reportMissingTypeStubs: 'none',
@ -368,7 +362,6 @@ export function getDefaultDiagnosticRuleSet(): DiagnosticRuleSet {
strictParameterNoneValue: false,
enableTypeIgnoreComments: true,
reportGeneralTypeIssues: 'error',
reportTypeshedErrors: 'none',
reportMissingImports: 'error',
reportMissingModuleSource: 'warning',
reportMissingTypeStubs: 'none',
@ -701,13 +694,6 @@ export class ConfigOptions {
defaultSettings.reportGeneralTypeIssues
),
// Read the "reportTypeshedErrors" entry.
reportTypeshedErrors: this._convertDiagnosticLevel(
configObj.reportTypeshedErrors,
DiagnosticRule.reportTypeshedErrors,
defaultSettings.reportTypeshedErrors
),
// Read the "reportMissingImports" entry.
reportMissingImports: this._convertDiagnosticLevel(
configObj.reportMissingImports,

View File

@ -15,7 +15,6 @@ export const enum DiagnosticRule {
enableTypeIgnoreComments = 'enableTypeIgnoreComments',
reportGeneralTypeIssues = 'reportGeneralTypeIssues',
reportTypeshedErrors = 'reportTypeshedErrors',
reportMissingImports = 'reportMissingImports',
reportMissingModuleSource = 'reportMissingModuleSource',
reportMissingTypeStubs = 'reportMissingTypeStubs',

View File

@ -16,7 +16,7 @@ import { combinePaths } from '../common/pathUtils';
test('Empty', () => {
const filePath = combinePaths(process.cwd(), 'tests/samples/test_file1.py');
const fs = createFromRealFileSystem();
const sourceFile = new SourceFile(fs, filePath, false, false);
const sourceFile = new SourceFile(fs, filePath, false);
const configOptions = new ConfigOptions(process.cwd());
const importResolver = new ImportResolver(fs, configOptions);

View File

@ -71,7 +71,6 @@ test('Configuration', () => {
//// "typingsPath": "src/typestubs",
//// "venvPath": "/home/foo/.venvs",
////
//// "reportTypeshedErrors": false,
//// "reportMissingImports": true,
//// "reportMissingTypeStubs": false,
////