Skip to content

Commit

Permalink
Push pylance changes to pyright (#4404)
Browse files Browse the repository at this point in the history
Co-authored-by: Bill Schnurr <bschnurr@microsoft.com>
Co-authored-by: HeeJae Chang <hechang@microsoft.com>
Co-authored-by: Erik De Bonte <erikd@microsoft.com>
Co-authored-by: Rich Chiodo <rchiodo@microsoft.com>
  • Loading branch information
5 people authored Jan 4, 2023
1 parent ca078ab commit b78a9e4
Show file tree
Hide file tree
Showing 28 changed files with 1,534 additions and 660 deletions.
534 changes: 288 additions & 246 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
"@types/glob": "^7.2.0",
"@types/node": "^17.0.45",
"@types/yargs": "^16.0.4",
"@typescript-eslint/eslint-plugin": "^5.43.0",
"@typescript-eslint/parser": "^5.43.0",
"@typescript-eslint/eslint-plugin": "^5.48.0",
"@typescript-eslint/parser": "^5.48.0",
"detect-indent": "^6.1.0",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
"eslint": "^8.31.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"glob": "^7.2.3",
"jsonc-parser": "^3.2.0",
"lerna": "^5.6.2",
"npm-check-updates": "^16.4.1",
"npm-check-updates": "^16.6.2",
"p-queue": "^6.6.2",
"prettier": "2.7.1",
"prettier": "2.8.1",
"syncpack": "^5.8.15",
"typescript": "~4.4.4",
"yargs": "^16.2.0"
Expand Down
106 changes: 59 additions & 47 deletions packages/pyright-internal/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions packages/pyright-internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"dependencies": {
"@iarna/toml": "2.2.5",
"@yarnpkg/fslib": "2.9.0",
"@yarnpkg/fslib": "2.10.0",
"@yarnpkg/libzip": "2.2.4",
"chalk": "^4.1.2",
"chokidar": "^3.5.3",
Expand All @@ -26,11 +26,11 @@
"source-map-support": "^0.5.21",
"tmp": "^0.2.1",
"typescript-char": "^0.0.0",
"vscode-jsonrpc": "8.1.0-next.1",
"vscode-languageserver": "8.1.0-next.1",
"vscode-languageserver-textdocument": "^1.0.7",
"vscode-jsonrpc": "8.1.0-next.5",
"vscode-languageserver": "8.1.0-next.4",
"vscode-languageserver-textdocument": "^1.0.8",
"vscode-languageserver-types": "3.17.2",
"vscode-uri": "^3.0.6"
"vscode-uri": "^3.0.7"
},
"devDependencies": {
"@types/command-line-args": "^5.2.0",
Expand Down
36 changes: 27 additions & 9 deletions packages/pyright-internal/src/analyzer/importResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,9 @@ export class ImportResolver {
sourceFilePath: string,
execEnv: ExecutionEnvironment,
moduleDescriptor: ImportedModuleDescriptor
): Set<string> {
): Map<string, string> {
const importFailureInfo: string[] = [];
const suggestions = new Set<string>();
const suggestions = new Map<string, string>();

// Is it a relative import?
if (moduleDescriptor.leadingDots > 0) {
Expand Down Expand Up @@ -707,6 +707,11 @@ export class ImportResolver {
return this._getStdlibTypeshedPath(execEnv, unused);
}

getTypeshedThirdPartyPath(execEnv: ExecutionEnvironment) {
const unused: string[] = [];
return this._getThirdPartyTypeshedPath(execEnv, unused);
}

isStdlibModule(module: ImportedModuleDescriptor, execEnv: ExecutionEnvironment): boolean {
if (!this._stdlibModules) {
this._stdlibModules = this._buildStdlibCache(this.getTypeshedStdLibPath(execEnv));
Expand Down Expand Up @@ -1693,7 +1698,7 @@ export class ImportResolver {
execEnv: ExecutionEnvironment,
moduleDescriptor: ImportedModuleDescriptor,
isStdLib: boolean,
suggestions: Set<string>
suggestions: Map<string, string>
) {
const importFailureInfo: string[] = [];

Expand Down Expand Up @@ -2015,7 +2020,7 @@ export class ImportResolver {
sourceFilePath: string,
execEnv: ExecutionEnvironment,
moduleDescriptor: ImportedModuleDescriptor,
suggestions: Set<string>
suggestions: Map<string, string>
) {
// Determine which search path this file is part of.
const directory = getDirectoryLeadingDotsPointsTo(
Expand Down Expand Up @@ -2050,7 +2055,7 @@ export class ImportResolver {
execEnv: ExecutionEnvironment,
rootPath: string,
moduleDescriptor: ImportedModuleDescriptor,
suggestions: Set<string>,
suggestions: Map<string, string>,
strictOnly = true
) {
// Starting at the specified path, walk the file system to find the
Expand Down Expand Up @@ -2112,7 +2117,7 @@ export class ImportResolver {
execEnv: ExecutionEnvironment,
currentPath: string,
filter: string,
suggestions: Set<string>,
suggestions: Map<string, string>,
leadingDots: number,
parentNameParts: string[],
strictOnly: boolean
Expand Down Expand Up @@ -2153,7 +2158,7 @@ export class ImportResolver {
return;
}

suggestions.add(fileWithoutExtension);
suggestions.set(fileWithoutExtension, combinePaths(currentPath, file));
}
});

Expand All @@ -2169,7 +2174,20 @@ export class ImportResolver {
return;
}

suggestions.add(dir);
const initPyiPath = combinePaths(currentPath, dir, '__init__.pyi');
if (this.fileExistsCached(initPyiPath)) {
suggestions.set(dir, initPyiPath);
return;
}

const initPyPath = combinePaths(currentPath, dir, '__init__.py');
if (this.fileExistsCached(initPyPath)) {
suggestions.set(dir, initPyPath);
return;
}

// It is a namespace package. there is no corresponding module path.
suggestions.set(dir, '');
});
}

Expand Down Expand Up @@ -2202,7 +2220,7 @@ export class ImportResolver {
return this._resolveImport(sourceFilePath, execEnv, moduleDescriptor).isImportFound;
}

private _isUniqueValidSuggestion(suggestionToAdd: string, suggestions: Set<string>) {
private _isUniqueValidSuggestion(suggestionToAdd: string, suggestions: Map<string, string>) {
if (suggestions.has(suggestionToAdd)) {
return false;
}
Expand Down
Loading

0 comments on commit b78a9e4

Please sign in to comment.