Skip to content

Commit

Permalink
pull-pylance-with-pyright-1.1.391-20250108-044808 (#9673)
Browse files Browse the repository at this point in the history
  • Loading branch information
bschnurr authored Jan 8, 2025
1 parent cba1872 commit 36a58cd
Show file tree
Hide file tree
Showing 26 changed files with 7,996 additions and 9,730 deletions.
14,002 changes: 5,681 additions & 8,321 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"devDependencies": {
"@types/glob": "^7.2.0",
"@types/node": "^22.7.0",
"@types/node": "^22.10.5",
"@types/yargs": "^16.0.9",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
Expand All @@ -32,7 +32,7 @@
"eslint-plugin-simple-import-sort": "^10.0.0",
"glob": "^7.2.3",
"jsonc-parser": "^3.3.1",
"lerna": "^8.1.8",
"lerna": "^8.1.9",
"npm-check-updates": "^16.14.20",
"p-queue": "^6.6.2",
"prettier": "2.8.8",
Expand Down
1,370 changes: 849 additions & 521 deletions packages/pyright-internal/package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions packages/pyright-internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
"devDependencies": {
"@types/command-line-args": "^5.2.3",
"@types/fs-extra": "^11.0.4",
"@types/jest": "^29.5.13",
"@types/lodash": "^4.17.7",
"@types/node": "^22.7.0",
"@types/jest": "^29.5.14",
"@types/lodash": "^4.17.14",
"@types/node": "^22.10.5",
"@types/tmp": "^0.2.6",
"copy-webpack-plugin": "^11.0.0",
"esbuild-loader": "^3.2.0",
Expand All @@ -51,7 +51,7 @@
"ts-jest": "^29.2.5",
"ts-loader": "^9.5.1",
"typescript": "~5.5.4",
"webpack": "^5.94.0",
"webpack": "^5.97.1",
"webpack-cli": "^5.1.4",
"word-wrap": "1.2.5"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { TokenType } from '../parser/tokenizerTypes';
import * as AnalyzerNodeInfo from './analyzerNodeInfo';
import { ModuleNameAndType } from './importResolver';
import { ImportResult, ImportType } from './importResult';
import { findTokenAfter, getTokenAt } from './parseTreeUtils';
import { getTokenAfter, getTokenAt } from './parseTreeUtils';
import * as SymbolNameUtils from './symbolNameUtils';

export interface ImportStatement {
Expand Down Expand Up @@ -797,8 +797,8 @@ function getEditsPreservingFirstCommentAfterCommaIfExist(
return [{ start: offsetOfPreviousNodeEnd, length }];
}

const commaToken = findTokenAfter(
parseFileResults.tokenizerOutput,
const commaToken = getTokenAfter(
parseFileResults.tokenizerOutput.tokens,
TextRange.getEnd(previousNode),
(t) => t.type === TokenType.Comma
);
Expand Down
47 changes: 29 additions & 18 deletions packages/pyright-internal/src/analyzer/parseTreeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1909,6 +1909,35 @@ export function getTokenAtLeft(
return tokens.getItemAt(index);
}

export function getTokenIndexAfter(
tokens: TextRangeCollection<Token>,
position: number,
predicate: (t: Token) => boolean
) {
const index = tokens.getItemAtPosition(position);
if (index < 0) {
return -1;
}

for (let i = index; i < tokens.length; i++) {
const token = tokens.getItemAt(i);
if (predicate(token)) {
return i;
}
}

return -1;
}

export function getTokenAfter(tokens: TextRangeCollection<Token>, position: number, predicate: (t: Token) => boolean) {
const index = getTokenIndexAfter(tokens, position, predicate);
if (index < 0) {
return undefined;
}

return tokens.getItemAt(index);
}

export function isWhitespace(token: Token) {
return token.type === TokenType.NewLine || token.type === TokenType.Indent || token.type === TokenType.Dedent;
}
Expand Down Expand Up @@ -1941,24 +1970,6 @@ export function getIndexOfTokenOverlapping(tokens: TextRangeCollection<Token>, p
return TextRange.overlaps(token, position) ? index : -1;
}

export function findTokenAfter(tokenizerOutput: TokenizerOutput, offset: number, predicate: (t: Token) => boolean) {
const tokens = tokenizerOutput.tokens;

const index = tokens.getItemAtPosition(offset);
if (index < 0) {
return undefined;
}

for (let i = index; i < tokens.length; i++) {
const token = tokens.getItemAt(i);
if (predicate(token)) {
return token;
}
}

return undefined;
}

export function getCommentsAtTokenIndex(tokens: TextRangeCollection<Token>, index: number) {
let token = getTokenAtIndex(tokens, index);
if (!token) {
Expand Down
50 changes: 31 additions & 19 deletions packages/pyright-internal/src/languageService/autoImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,21 @@ import { IndexAliasData } from './symbolIndexer';
import { fromLSPAny } from '../common/lspUtils';

export interface AutoImportSymbol {
readonly importAlias?: IndexAliasData;
readonly symbol?: Symbol;
readonly name: string;
readonly library: boolean;

readonly kind?: SymbolKind;
readonly itemKind?: CompletionItemKind;
readonly importAlias?: IndexAliasData;

readonly symbol?: Symbol;
readonly inDunderAll?: boolean;
readonly hasRedundantAlias?: boolean;
}

export interface ModuleSymbolTable {
readonly uri: Uri;
getSymbols(): Generator<{ symbol: AutoImportSymbol; name: string; library: boolean }>;
getSymbols(): Generator<AutoImportSymbol>;
}

export type ModuleSymbolMap = Map<string, ModuleSymbolTable>;
Expand Down Expand Up @@ -164,7 +168,14 @@ export function buildModuleSymbolsMap(files: readonly SourceFileInfo[]): ModuleS
declaration.type === DeclarationType.Variable && !declaration.isConstant && !declaration.isFinal
? SymbolKind.Variable
: undefined;
yield { symbol: { symbol, kind: variableKind }, name, library: !isUserCode(file) };

yield {
name,
symbol,
kind: variableKind,
library: !isUserCode(file),
inDunderAll: symbol.isInDunderAll(),
};
}
},
});
Expand Down Expand Up @@ -351,14 +362,15 @@ export class AutoImporter {
}

const dotCount = StringUtils.getCharacterCount(importSource, '.');
for (const { symbol: autoImportSymbol, name } of topLevelSymbols.getSymbols()) {
if (!this.shouldIncludeVariable(autoImportSymbol, name, fileProperties.isStub)) {
for (const autoSymbol of topLevelSymbols.getSymbols()) {
if (!this.shouldIncludeVariable(autoSymbol, fileProperties.isStub)) {
continue;
}

// For very short matching strings, we will require an exact match. Otherwise
// we will tend to return a list that's too long. Once we get beyond two
// characters, we can do a fuzzy match.
const name = autoSymbol.name;
const isSimilar = this._isSimilar(word, name, similarityLimit);
if (!isSimilar) {
continue;
Expand All @@ -370,9 +382,9 @@ export class AutoImporter {
}

// We will collect all aliases and then process it later
if (autoImportSymbol.importAlias) {
if (autoSymbol.importAlias) {
this._addToImportAliasMap(
autoImportSymbol.importAlias,
autoSymbol.importAlias,
{
importParts: {
symbolName: name,
Expand All @@ -383,12 +395,12 @@ export class AutoImporter {
moduleNameAndType,
},
importGroup,
symbol: autoImportSymbol.symbol,
kind: autoImportSymbol.importAlias.kind,
itemKind: autoImportSymbol.importAlias.itemKind,
inDunderAll: autoImportSymbol.inDunderAll,
hasRedundantAlias: autoImportSymbol.hasRedundantAlias,
fileUri: autoImportSymbol.importAlias.moduleUri,
symbol: autoSymbol.symbol,
kind: autoSymbol.importAlias.kind,
itemKind: autoSymbol.importAlias.itemKind,
inDunderAll: autoSymbol.inDunderAll,
hasRedundantAlias: autoSymbol.hasRedundantAlias,
fileUri: autoSymbol.importAlias.moduleUri,
},
importAliasMap
);
Expand All @@ -407,9 +419,9 @@ export class AutoImporter {
this._addResult(results, {
name,
alias: abbrFromUsers,
symbol: autoImportSymbol.symbol,
symbol: autoSymbol.symbol,
source: importSource,
kind: autoImportSymbol.itemKind ?? convertSymbolKindToCompletionItemKind(autoImportSymbol.kind),
kind: autoSymbol.itemKind ?? convertSymbolKindToCompletionItemKind(autoSymbol.kind),
insertionText: autoImportTextEdits.insertionText,
edits: autoImportTextEdits.edits,
declUri: moduleUri,
Expand Down Expand Up @@ -497,14 +509,14 @@ export class AutoImporter {
return StringUtils.getStringComparer()(left.importParts.importName, right.importParts.importName);
}

protected shouldIncludeVariable(autoImportSymbol: AutoImportSymbol, name: string, isStub: boolean) {
protected shouldIncludeVariable(autoSymbol: AutoImportSymbol, isStub: boolean) {
// If it is not a stub file and symbol is Variable, we only include it if
// name is public constant or type alias
if (isStub || autoImportSymbol.kind !== SymbolKind.Variable) {
if (isStub || autoSymbol.kind !== SymbolKind.Variable) {
return true;
}

return SymbolNameUtils.isPublicConstantOrTypeAlias(name);
return SymbolNameUtils.isPublicConstantOrTypeAlias(autoSymbol.name);
}

private _addToImportAliasMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -815,10 +815,10 @@
"unhashableType": "Typ „{type}“ nejde zatřiďovat",
"uninitializedAbstractVariable": "Proměnná instance {name} je definovaná v abstraktní základní třídě {classType}, ale neinicializovala se",
"unreachableExcept": "{exceptionType} je podtřídou {parentType}",
"useDictInstead": "Označte typ slovníku pomocí Dict[T1, T2]",
"useListInstead": "Použijte List[T] k označení typu seznamu (list) nebo Union[T1, T2] k označení typu sjednocení (union).",
"useTupleInstead": "Použijte tuple[T1, ..., Tn] k označení typu řazené kolekce členů (tuple) nebo Union[T1, T2] k označení typu sjednocení (union).",
"useTypeInstead": "Místo toho použít Type[T]",
"useDictInstead": "Use dict[T1, T2] to indicate a dictionary type",
"useListInstead": "Use list[T] to indicate a list type or T1 | T2 to indicate a union type",
"useTupleInstead": "Use tuple[T1, ..., Tn] to indicate a tuple type or T1 | T2 to indicate a union type",
"useTypeInstead": "Use type[T] instead",
"varianceMismatchForClass": "Odchylka argumentu typu „{typeVarName}“ není kompatibilní se základní třídou „{className}“",
"varianceMismatchForTypeAlias": "Rozptyl argumentu typu „{typeVarName}“ není kompatibilní s typem „{typeAliasParam}“"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -815,10 +815,10 @@
"unhashableType": "Der Typ \"{type}\" kann nicht mit einem Hash erstellt werden.",
"uninitializedAbstractVariable": "Die Instanzvariable \"{name}\" ist in einer abstrakten Basisklasse \"{classType}\" definiert, aber nicht initialisiert.",
"unreachableExcept": "\"{exceptionType}\" ist eine Unterklasse von \"{parentType}\"",
"useDictInstead": "Verwenden Sie Dict[T1, T2], um einen Wörterbuchtyp anzugeben.",
"useListInstead": "Verwenden Sie List[T], um einen list Typ anzugeben, oder Union[T1, T2], um einen union-Typ anzugeben.",
"useTupleInstead": "Verwenden Sie tuple[T1, ..., Tn], um einen tuple-Typ anzugeben, oder Union[T1, T2], um einen union-Typ anzugeben.",
"useTypeInstead": "Stattdessen Type[T] verwenden",
"useDictInstead": "Use dict[T1, T2] to indicate a dictionary type",
"useListInstead": "Use list[T] to indicate a list type or T1 | T2 to indicate a union type",
"useTupleInstead": "Use tuple[T1, ..., Tn] to indicate a tuple type or T1 | T2 to indicate a union type",
"useTypeInstead": "Use type[T] instead",
"varianceMismatchForClass": "Die Varianz des Typarguments \"{typeVarName}\" ist nicht mit der Basisklasse \"{className}\" kompatibel",
"varianceMismatchForTypeAlias": "Die Varianz des Typarguments \"{typeVarName}\" ist nicht mit \"{typeAliasParam}\" kompatibel"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -815,10 +815,10 @@
"unhashableType": "El tipo \"{type}\" no admite hash",
"uninitializedAbstractVariable": "La variable de instancia \"{name}\" está definida en la clase base abstracta \"{classType} \" pero no inicializada.",
"unreachableExcept": "\"{exceptionType}\" es una subclase de \"{parentType}\"",
"useDictInstead": "Usar Dict[T1, T2] para indicar un tipo de diccionario",
"useListInstead": "Usar List[T] para indicar un tipo de list o Union[T1, T2] para indicar un tipo de union",
"useTupleInstead": "Utilice tuple[T1, ..., Tn] para indicar un tipo de tuple o Union[T1, T2] para indicar un tipo de union.",
"useTypeInstead": "Utilice Type[T] en su lugar",
"useDictInstead": "Use dict[T1, T2] to indicate a dictionary type",
"useListInstead": "Use list[T] to indicate a list type or T1 | T2 to indicate a union type",
"useTupleInstead": "Use tuple[T1, ..., Tn] to indicate a tuple type or T1 | T2 to indicate a union type",
"useTypeInstead": "Use type[T] instead",
"varianceMismatchForClass": "La varianza del argumento de tipo \"{typeVarName}\" no es compatible con la clase base \"{className}\"",
"varianceMismatchForTypeAlias": "La varianza del argumento de tipo \"{typeVarName}\" no es compatible con \"{typeAliasParam}\""
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -815,10 +815,10 @@
"unhashableType": "Le type \"{type}\" n'est pas hachable",
"uninitializedAbstractVariable": "La variable d’instance « {name} » est définie dans la classe de base abstraite « {classType} » mais n’est pas initialisée",
"unreachableExcept": "« {exceptionType} » est une sous-classe de « {parentType} »",
"useDictInstead": "Utilisez Dict[T1, T2] pour indiquer un type de dictionnaire",
"useListInstead": "Utilisez List[T] pour indiquer un type de liste ou Union[T1, T2] pour indiquer un type d'union",
"useTupleInstead": "Utiliser tuple[T1, ..., Tn] pour indiquer un type de tuple ou Union[T1, T2] pour indiquer un type d’union",
"useTypeInstead": "Utiliser le Type[T] à la place",
"useDictInstead": "Use dict[T1, T2] to indicate a dictionary type",
"useListInstead": "Use list[T] to indicate a list type or T1 | T2 to indicate a union type",
"useTupleInstead": "Use tuple[T1, ..., Tn] to indicate a tuple type or T1 | T2 to indicate a union type",
"useTypeInstead": "Use type[T] instead",
"varianceMismatchForClass": "La variance de l'argument de type \"{typeVarName}\" est incompatible avec la classe de base \"{className}\"",
"varianceMismatchForTypeAlias": "La variance de l'argument de type \"{typeVarName}\" est incompatible avec \"{typeAliasParam}\""
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -815,10 +815,10 @@
"unhashableType": "Il tipo \"{type}\" non è hashable",
"uninitializedAbstractVariable": "La variabile di istanza \"{name}\" è definita nella classe di base astratta \"{classType}\" ma non è inizializzata",
"unreachableExcept": "\"{exceptionType}\" è una sottoclasse di \"{parentType}\"",
"useDictInstead": "Usare Dict[T1, T2] per indicare un tipo di dizionario",
"useListInstead": "Usare List[T] per indicare un tipo di list o Union[T1, T2] per indicare un tipo di unione",
"useTupleInstead": "Usare tuple[T1, ..., Tn] per indicare un tipo di tuple o Union[T1, T2] per indicare un tipo di unione",
"useTypeInstead": "In alternativa, usare Type[T]",
"useDictInstead": "Use dict[T1, T2] to indicate a dictionary type",
"useListInstead": "Use list[T] to indicate a list type or T1 | T2 to indicate a union type",
"useTupleInstead": "Use tuple[T1, ..., Tn] to indicate a tuple type or T1 | T2 to indicate a union type",
"useTypeInstead": "Use type[T] instead",
"varianceMismatchForClass": "La varianza dell'argomento tipo \"{typeVarName}\" non è compatibile con la classe di base \"{className}\"",
"varianceMismatchForTypeAlias": "La varianza dell'argomento tipo \"{typeVarName}\" non è compatibile con \"{typeAliasParam}\""
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -815,10 +815,10 @@
"unhashableType": "型 \"{type}\" はハッシュ可能ではありません",
"uninitializedAbstractVariable": "インスタンス変数 \"{name}\" は抽象基本クラス \"{classType}\" で定義されていますが、初期化されていません",
"unreachableExcept": "\"{exceptionType}\" は \"{parentType}\" のサブクラスです",
"useDictInstead": "辞書の種類を示すには、Dict[T1, T2] を使用します",
"useListInstead": "List[T] を使用して list 型を示すか、Union[T1, T2] を使用して union 型を示します",
"useTupleInstead": "tuple[T1, ..., Tn] を使用して tuple 型を示すか、Union[T1, T2] を使用して union 型を示します",
"useTypeInstead": "代わりに Type[T] を使用する",
"useDictInstead": "Use dict[T1, T2] to indicate a dictionary type",
"useListInstead": "Use list[T] to indicate a list type or T1 | T2 to indicate a union type",
"useTupleInstead": "Use tuple[T1, ..., Tn] to indicate a tuple type or T1 | T2 to indicate a union type",
"useTypeInstead": "Use type[T] instead",
"varianceMismatchForClass": "型引数 \"{typeVarName}\" の分散は、基底クラス \"{className}\" と互換性がありません",
"varianceMismatchForTypeAlias": "型引数 \"{typeVarName}\" の分散は \"{typeAliasParam}\" と互換性がありません"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -815,10 +815,10 @@
"unhashableType": "‘{type}’ 형식을 해시할 수 없습니다.",
"uninitializedAbstractVariable": "인스턴스 변수 \"{name}\"이(가) 추상 기본 클래스 \"{classType}\"에 정의되어 있지만 초기화되지 않았습니다.",
"unreachableExcept": "\"{exceptionType}\"은(는) \"{parentType}\"의 서브클래스입니다.",
"useDictInstead": "사전 형식을 나타내려면 Dict[T1, T2]를 사용하세요.",
"useListInstead": "List[T]를 사용하여 list 형식을 나타내거나 Union[T1, T2]를 사용하여 union 형식을 나타내세요.",
"useTupleInstead": "tuple[T1, ..., Tn]을 사용하여 tuple 형식을 나타내거나 Union[T1, T2]을 사용하여 union 형식을 나타냅니다.",
"useTypeInstead": "대신 Type[T] 사용",
"useDictInstead": "Use dict[T1, T2] to indicate a dictionary type",
"useListInstead": "Use list[T] to indicate a list type or T1 | T2 to indicate a union type",
"useTupleInstead": "Use tuple[T1, ..., Tn] to indicate a tuple type or T1 | T2 to indicate a union type",
"useTypeInstead": "Use type[T] instead",
"varianceMismatchForClass": "‘{typeVarName}’ 형식 인수의 차이는 ‘{className}’ 기본 클래스와 호환되지 않습니다.",
"varianceMismatchForTypeAlias": "‘{typeVarName}’ 형식 인수의 차이는 ‘{typeAliasParam}’와(과) 호환되지 않습니다."
},
Expand Down
Loading

0 comments on commit 36a58cd

Please sign in to comment.