mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
Skip unnecessary py.typed file exist checks. (#7652)
* skip unnecessary py.typed file exist checks. * passed wrong uri * PR feedbacks * more comments * PR feedbacks
This commit is contained in:
parent
ed92822a64
commit
bd08098c5d
@ -16,8 +16,8 @@ import { Host } from '../common/host';
|
||||
import { stubsSuffix } from '../common/pathConsts';
|
||||
import { stripFileExtension } from '../common/pathUtils';
|
||||
import { PythonVersion, pythonVersion3_0 } from '../common/pythonVersion';
|
||||
import { ServiceProvider } from '../common/serviceProvider';
|
||||
import { ServiceKeys } from '../common/serviceKeys';
|
||||
import { ServiceProvider } from '../common/serviceProvider';
|
||||
import * as StringUtils from '../common/stringUtils';
|
||||
import { equateStringsCaseInsensitive } from '../common/stringUtils';
|
||||
import { Uri } from '../common/uri/uri';
|
||||
@ -26,7 +26,7 @@ import { isIdentifierChar, isIdentifierStartChar } from '../parser/characters';
|
||||
import { ImplicitImport, ImportResult, ImportType } from './importResult';
|
||||
import { getDirectoryLeadingDotsPointsTo } from './importStatementUtils';
|
||||
import { ImportPath, ParentDirectoryCache } from './parentDirectoryCache';
|
||||
import { PyTypedInfo, getPyTypedInfo } from './pyTypedUtils';
|
||||
import { PyTypedInfo, getPyTypedInfoForPyTypedFile } from './pyTypedUtils';
|
||||
import * as PythonPathUtils from './pythonPathUtils';
|
||||
import * as SymbolNameUtils from './symbolNameUtils';
|
||||
import { isDunderName } from './symbolNameUtils';
|
||||
@ -2708,7 +2708,8 @@ export class ImportResolver {
|
||||
if (!this.fileExistsCached(filePath.pytypedUri)) {
|
||||
return undefined;
|
||||
}
|
||||
return getPyTypedInfo(this.fileSystem, filePath);
|
||||
|
||||
return getPyTypedInfoForPyTypedFile(this.fileSystem, filePath.pytypedUri);
|
||||
}
|
||||
|
||||
private _resolveNativeModuleStub(
|
||||
|
@ -16,18 +16,32 @@ export interface PyTypedInfo {
|
||||
isPartiallyTyped: boolean;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieves information about a py.typed file, if it exists, under the given path.
|
||||
//
|
||||
export function getPyTypedInfo(fileSystem: FileSystem, dirPath: Uri): PyTypedInfo | undefined {
|
||||
if (!fileSystem.existsSync(dirPath) || !isDirectory(fileSystem, dirPath)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let isPartiallyTyped = false;
|
||||
const pyTypedPath = dirPath.pytypedUri;
|
||||
|
||||
if (!fileSystem.existsSync(pyTypedPath) || !isFile(fileSystem, pyTypedPath)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return getPyTypedInfoForPyTypedFile(fileSystem, pyTypedPath);
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieves information about a py.typed file. The pyTypedPath provided must be a valid path.
|
||||
//
|
||||
export function getPyTypedInfoForPyTypedFile(fileSystem: FileSystem, pyTypedPath: Uri) {
|
||||
// This function intentionally doesn't check whether the given py.typed path exists or not,
|
||||
// as filesystem access is expensive if done repeatedly.
|
||||
// The caller should verify the file's validity before calling this method and use a cache if possible
|
||||
// to avoid high filesystem access costs.
|
||||
let isPartiallyTyped = false;
|
||||
|
||||
// Read the contents of the file as text.
|
||||
const fileStats = fileSystem.statSync(pyTypedPath);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user