Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull Pylance with Pyright 1.1.392 #9714

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions packages/pyright-internal/src/languageService/hoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,20 @@ export function getVariableTypeText(
}
}

// Handle the case where type is a function and was assigned to a variable.
if (type.category === TypeCategory.Function || type.category === TypeCategory.Overloaded) {
return getToolTipForType(type, label, name, evaluator, /* isProperty */ false, functionSignatureDisplay);
if (
type.category === TypeCategory.Function ||
type.category === TypeCategory.Overloaded ||
typeNode.parent?.nodeType === ParseNodeType.Call
) {
return getToolTipForType(
type,
label,
name,
evaluator,
/* isProperty */ false,
functionSignatureDisplay,
typeNode
);
}

const typeText = typeVarName ?? name + ': ' + evaluator.printType(getTypeForToolTip(evaluator, typeNode));
Expand Down
18 changes: 17 additions & 1 deletion packages/pyright-internal/src/languageService/tooltipUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* completion suggestions, etc.
*/

import { getBoundCallMethod } from '../analyzer/constructors';
import { Declaration, DeclarationType, VariableDeclaration } from '../analyzer/declaration';
import * as ParseTreeUtils from '../analyzer/parseTreeUtils';
import { SourceMapper } from '../analyzer/sourceMapper';
Expand Down Expand Up @@ -51,8 +52,23 @@ export function getToolTipForType(
name: string,
evaluator: TypeEvaluator,
isProperty: boolean,
functionSignatureDisplay: SignatureDisplayType
functionSignatureDisplay: SignatureDisplayType,
typeNode?: ExpressionNode
): string {
// Support __call__ method for class instances to show the signature of the method
if (type.category === TypeCategory.Class && isClassInstance(type) && typeNode) {
const callMethodResult = getBoundCallMethod(evaluator, typeNode, type);
if (
callMethodResult?.type.category === TypeCategory.Function ||
callMethodResult?.type.category === TypeCategory.Overloaded
) {
// narrow down specific overload if possible
const methodType = bindFunctionToClassOrObjectToolTip(evaluator, typeNode, type, callMethodResult.type);
if (methodType) {
type = methodType;
}
}
}
let signatureString = '';
if (isOverloaded(type)) {
signatureString = label.length > 0 ? `(${label})\n` : '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@
"parenthesizedContextManagerIllegal": "Parentheses within \"with\" statement requires Python 3.9 or newer",
"patternNeverMatches": "Vzor se nikdy nebude shodovat s typem předmětu {type}",
"positionArgAfterNamedArg": "Poziční argument se nemůže objevit za argumenty klíčového slova",
"positionArgAfterUnpackedDictArg": "Positional argument cannot appear after keyword argument unpacking",
"positionOnlyAfterArgs": "Oddělovač parametrů jen pro pozici není povolený za parametrem *.",
"positionOnlyAfterKeywordOnly": "Parametr / se musí zobrazit před parametrem *",
"positionOnlyAfterNon": "Parametr jen pro pozici není povolený za parametrem, který není jen pro pozici.",
Expand Down Expand Up @@ -815,10 +816,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": "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",
"useDictInstead": "Označte typ slovníku pomocí dict[T1, T2]",
"useListInstead": "Použijte list[T] k označení typu seznamu (list) nebo T1 | T2 k označení typu sjednocení (union).",
"useTupleInstead": "Použijte tuple[T1, ..., Tn] k označení typu řazené kolekce členů (tuple) nebo T1 | T2 k označení typu sjednocení (union).",
"useTypeInstead": "Místo toho použít type[T]",
"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 @@ -396,6 +396,7 @@
"parenthesizedContextManagerIllegal": "Parentheses within \"with\" statement requires Python 3.9 or newer",
"patternNeverMatches": "Das Muster wird für den Antragstellertyp \"{type}\" nie abgeglichen",
"positionArgAfterNamedArg": "Ein Positionsargument darf nicht nach Schlüsselwortargumenten stehen.",
"positionArgAfterUnpackedDictArg": "Positional argument cannot appear after keyword argument unpacking",
"positionOnlyAfterArgs": "Das Parametertrennzeichen \"Nur Position\" ist nach dem Parameter \"*\" nicht zulässig.",
"positionOnlyAfterKeywordOnly": "Der Parameter \"/\" muss vor dem Parameter \"*\" stehen.",
"positionOnlyAfterNon": "Der Parameter \"Nur Position\" ist nach einem Parameter, der nicht vom Typ \"Nur Position\" ist, nicht zulässig.",
Expand Down Expand Up @@ -815,10 +816,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": "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",
"useDictInstead": "Verwenden Sie dict[T1, T2], um einen Wörterbuchtyp anzugeben.",
"useListInstead": "Verwenden Sie list[T], um einen list-Typ anzugeben, oder T1 | T2, um einen union-Typ anzugeben.",
"useTupleInstead": "Verwenden Sie tuple[T1, ..., Tn], um einen tuple-Typ anzugeben, oder T1 | T2, um einen union-Typ anzugeben.",
"useTypeInstead": "Verwenden Sie stattdessen type[T].",
"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 @@ -396,6 +396,7 @@
"parenthesizedContextManagerIllegal": "Parentheses within \"with\" statement requires Python 3.9 or newer",
"patternNeverMatches": "El patrón nunca coincidirá para el tipo de asunto \"{type}\"",
"positionArgAfterNamedArg": "El argumento posicional no puede aparecer después de los argumentos de palabra clave",
"positionArgAfterUnpackedDictArg": "Positional argument cannot appear after keyword argument unpacking",
"positionOnlyAfterArgs": "No se permite el separador de parámetros de un solo puesto después del parámetro \"*\".",
"positionOnlyAfterKeywordOnly": "El parámetro \"/\" debe aparecer antes del parámetro \"*\".",
"positionOnlyAfterNon": "Parámetro de un solo puesto no permitido después del parámetro que no es de solo posición",
Expand Down Expand Up @@ -815,10 +816,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": "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",
"useDictInstead": "Utilice dict[T1, T2] para indicar un tipo de diccionario",
"useListInstead": "Utilice list[T] para indicar un tipo de list o T1 | T2 para indicar un tipo de union",
"useTupleInstead": "Utilice tuple[T1, ..., Tn] para indicar un tipo de tuple o T1 | T2 para indicar un tipo de union",
"useTypeInstead": "Utilice type[T] en su lugar",
"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 @@ -396,6 +396,7 @@
"parenthesizedContextManagerIllegal": "Parentheses within \"with\" statement requires Python 3.9 or newer",
"patternNeverMatches": "Le modèle ne sera jamais mis en correspondance pour le type d’objet « {type} »",
"positionArgAfterNamedArg": "L’argument positionnel ne peut pas apparaître après les arguments de mot clé",
"positionArgAfterUnpackedDictArg": "Positional argument cannot appear after keyword argument unpacking",
"positionOnlyAfterArgs": "Séparateur de paramètres de position seule non autorisé après le paramètre « * »",
"positionOnlyAfterKeywordOnly": "Le paramètre « / » doit apparaître avant le paramètre « * »",
"positionOnlyAfterNon": "Paramètre de position seule non autorisé après un paramètre qui n’est pas en position seule",
Expand Down Expand Up @@ -815,10 +816,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": "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",
"useDictInstead": "Utilisez dict[T1, T2] pour indiquer un type de dictionnaire",
"useListInstead": "Utiliser list[T] pour indiquer un type de liste ou T1 | T2 pour indiquer un type d’union",
"useTupleInstead": "Utiliser tuple[T1, ..., Tn] pour indiquer un type de tuple ou T1 | T2 pour indiquer un type d’union",
"useTypeInstead": "Utiliser type[T] à la place",
"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 @@ -396,6 +396,7 @@
"parenthesizedContextManagerIllegal": "Parentheses within \"with\" statement requires Python 3.9 or newer",
"patternNeverMatches": "Il criterio non verrà mai confrontato per il tipo di oggetto \"{type}\"",
"positionArgAfterNamedArg": "L'argomento posizionale non può essere visualizzato dopo gli argomenti della parola chiave",
"positionArgAfterUnpackedDictArg": "Positional argument cannot appear after keyword argument unpacking",
"positionOnlyAfterArgs": "Separatore di parametri di sola posizione non consentito dopo il parametro \"*\"",
"positionOnlyAfterKeywordOnly": "Il parametro \"/\" deve essere visualizzato prima del parametro \"*\"",
"positionOnlyAfterNon": "Il parametro di sola posizione non è consentito dopo un parametro che non è di sola posizione",
Expand Down Expand Up @@ -815,10 +816,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": "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",
"useDictInstead": "Usare dict[T1, T2] per indicare un tipo di dizionario",
"useListInstead": "Usare list[T] per indicare un tipo di list o T1 | T2 per indicare un tipo di union",
"useTupleInstead": "Usare tuple[T1, ..., Tn] per indicare un tipo di tuple o T1 | T2 per indicare un tipo di unione",
"useTypeInstead": "Usare invece type[T]",
"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 @@ -396,6 +396,7 @@
"parenthesizedContextManagerIllegal": "Parentheses within \"with\" statement requires Python 3.9 or newer",
"patternNeverMatches": "サブジェクトの種類 \"{type}\" のパターンは一致しません",
"positionArgAfterNamedArg": "キーワード引数の後に位置引数を指定することはできません",
"positionArgAfterUnpackedDictArg": "Positional argument cannot appear after keyword argument unpacking",
"positionOnlyAfterArgs": "\"*\" パラメーターの後に位置のみのパラメーターの区切り文字を使用することはできません",
"positionOnlyAfterKeywordOnly": "\"/\" パラメーターは 、\"*\" パラメーターの前に指定する必要があります",
"positionOnlyAfterNon": "位置のみのパラメーターの後に位置のみのパラメーターを指定することはできません",
Expand Down Expand Up @@ -815,10 +816,10 @@
"unhashableType": "型 \"{type}\" はハッシュ可能ではありません",
"uninitializedAbstractVariable": "インスタンス変数 \"{name}\" は抽象基本クラス \"{classType}\" で定義されていますが、初期化されていません",
"unreachableExcept": "\"{exceptionType}\" は \"{parentType}\" のサブクラスです",
"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",
"useDictInstead": "辞書の種類を示すには、dict[T1, T2] を使用します",
"useListInstead": "list[T] を使用して list 型を示すか、T1 | T2 を使用して union 型を示します",
"useTupleInstead": "tuple[T1, ..., Tn] を使用して tuple 型を示すか、T1 | T2 を使用して union 型を示します",
"useTypeInstead": "代わりに type[T] を使用する",
"varianceMismatchForClass": "型引数 \"{typeVarName}\" の分散は、基底クラス \"{className}\" と互換性がありません",
"varianceMismatchForTypeAlias": "型引数 \"{typeVarName}\" の分散は \"{typeAliasParam}\" と互換性がありません"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@
"parenthesizedContextManagerIllegal": "Parentheses within \"with\" statement requires Python 3.9 or newer",
"patternNeverMatches": "제목 형식 \"{type}\"에 대해 패턴이 일치하지 않습니다.",
"positionArgAfterNamedArg": "위치 인수는 키워드 인수 뒤에 나타날 수 없습니다.",
"positionArgAfterUnpackedDictArg": "Positional argument cannot appear after keyword argument unpacking",
"positionOnlyAfterArgs": "위치 전용 매개 변수 구분 기호는 \"*\" 매개 변수 뒤에 사용할 수 없습니다.",
"positionOnlyAfterKeywordOnly": "\"/\" 매개 변수는 \"*\" 매개 변수 앞에 나타나야 합니다.",
"positionOnlyAfterNon": "위치 전용이 아닌 매개 변수 다음에는 위치 전용 매개 변수를 사용할 수 없습니다.",
Expand Down Expand Up @@ -815,10 +816,10 @@
"unhashableType": "‘{type}’ 형식을 해시할 수 없습니다.",
"uninitializedAbstractVariable": "인스턴스 변수 \"{name}\"이(가) 추상 기본 클래스 \"{classType}\"에 정의되어 있지만 초기화되지 않았습니다.",
"unreachableExcept": "\"{exceptionType}\"은(는) \"{parentType}\"의 서브클래스입니다.",
"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",
"useDictInstead": "dict[T1, T2]를 사용하여 사전 형식을 나타냅니다.",
"useListInstead": "list[T]를 사용하여 list 형식을 나타내거나 T1 | T2를 사용하여 union 형식을 나타냅니다.",
"useTupleInstead": "tuple[T1, ..., Tn]을 사용하여 tuple 형식을 나타내거나 T1 | T2를 사용하여 union 형식을 나타냅니다.",
"useTypeInstead": "대신 type[T]를 사용합니다.",
"varianceMismatchForClass": "‘{typeVarName}’ 형식 인수의 차이는 ‘{className}’ 기본 클래스와 호환되지 않습니다.",
"varianceMismatchForTypeAlias": "‘{typeVarName}’ 형식 인수의 차이는 ‘{typeAliasParam}’와(과) 호환되지 않습니다."
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@
"parenthesizedContextManagerIllegal": "Parentheses within \"with\" statement requires Python 3.9 or newer",
"patternNeverMatches": "Wzorzec nigdy nie zostanie dopasowany do typu podmiotu „{type}”",
"positionArgAfterNamedArg": "Argument pozycyjny nie może występować po argumentach słów kluczowych",
"positionArgAfterUnpackedDictArg": "Positional argument cannot appear after keyword argument unpacking",
"positionOnlyAfterArgs": "Separator parametru tylko do pozycjonowania jest niedozwolony po parametrze „*”",
"positionOnlyAfterKeywordOnly": "Parametr „/” musi występować przed parametrem „*”.",
"positionOnlyAfterNon": "Parametr tylko do pozycjonowania jest niedozwolony po parametrze, który nie jest tylko do pozycjonowania",
Expand Down Expand Up @@ -815,10 +816,10 @@
"unhashableType": "Typ „{type}” nie jest wartością skrótu",
"uninitializedAbstractVariable": "zmienna wystąpienia „{name}” jest zdefiniowana w abstrakcyjnej klasie bazowej „{classType}” ale nie została zainicjowana",
"unreachableExcept": "Typ „{exceptionType}” jest podklasą typu „{parentType}”",
"useDictInstead": "Use dict[T1, T2] to indicate a dictionary type",
"useDictInstead": "Użyj funkcji dict[T1, T2], aby wskazać typ słownika",
"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",
"useTypeInstead": "Zamiast tego użyj funkcji type[T]",
"varianceMismatchForClass": "Wariancja argumentu typu „{typeVarName}” jest niezgodna z klasą bazową „{className}”",
"varianceMismatchForTypeAlias": "Wariancja argumentu typu „{typeVarName}” jest niezgodna z parametrem „{typeAliasParam}”"
},
Expand Down
Loading
Loading