diff --git a/packages/pyright-internal/src/languageService/hoverProvider.ts b/packages/pyright-internal/src/languageService/hoverProvider.ts index d429afa06e56..8a79703b4990 100644 --- a/packages/pyright-internal/src/languageService/hoverProvider.ts +++ b/packages/pyright-internal/src/languageService/hoverProvider.ts @@ -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)); diff --git a/packages/pyright-internal/src/languageService/tooltipUtils.ts b/packages/pyright-internal/src/languageService/tooltipUtils.ts index 78554d13bb97..c768fe5084f9 100644 --- a/packages/pyright-internal/src/languageService/tooltipUtils.ts +++ b/packages/pyright-internal/src/languageService/tooltipUtils.ts @@ -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'; @@ -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` : ''; diff --git a/packages/pyright-internal/src/localization/package.nls.cs.json b/packages/pyright-internal/src/localization/package.nls.cs.json index c51588478d6b..400c4ee1b551 100644 --- a/packages/pyright-internal/src/localization/package.nls.cs.json +++ b/packages/pyright-internal/src/localization/package.nls.cs.json @@ -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.", @@ -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}“" }, diff --git a/packages/pyright-internal/src/localization/package.nls.de.json b/packages/pyright-internal/src/localization/package.nls.de.json index aa2eed1997fd..e51a9aba3589 100644 --- a/packages/pyright-internal/src/localization/package.nls.de.json +++ b/packages/pyright-internal/src/localization/package.nls.de.json @@ -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.", @@ -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" }, diff --git a/packages/pyright-internal/src/localization/package.nls.es.json b/packages/pyright-internal/src/localization/package.nls.es.json index 7e7304b7fed4..931ca7d5f4dd 100644 --- a/packages/pyright-internal/src/localization/package.nls.es.json +++ b/packages/pyright-internal/src/localization/package.nls.es.json @@ -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", @@ -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}\"" }, diff --git a/packages/pyright-internal/src/localization/package.nls.fr.json b/packages/pyright-internal/src/localization/package.nls.fr.json index 3e87c7d4ba65..3170111939c8 100644 --- a/packages/pyright-internal/src/localization/package.nls.fr.json +++ b/packages/pyright-internal/src/localization/package.nls.fr.json @@ -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", @@ -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}\"" }, diff --git a/packages/pyright-internal/src/localization/package.nls.it.json b/packages/pyright-internal/src/localization/package.nls.it.json index e4dd0cd01cce..f694d8fd9a34 100644 --- a/packages/pyright-internal/src/localization/package.nls.it.json +++ b/packages/pyright-internal/src/localization/package.nls.it.json @@ -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", @@ -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}\"" }, diff --git a/packages/pyright-internal/src/localization/package.nls.ja.json b/packages/pyright-internal/src/localization/package.nls.ja.json index 6b5f413c3b84..8adc75186ebd 100644 --- a/packages/pyright-internal/src/localization/package.nls.ja.json +++ b/packages/pyright-internal/src/localization/package.nls.ja.json @@ -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": "位置のみのパラメーターの後に位置のみのパラメーターを指定することはできません", @@ -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}\" と互換性がありません" }, diff --git a/packages/pyright-internal/src/localization/package.nls.ko.json b/packages/pyright-internal/src/localization/package.nls.ko.json index 89c14dd75c0e..69879dced407 100644 --- a/packages/pyright-internal/src/localization/package.nls.ko.json +++ b/packages/pyright-internal/src/localization/package.nls.ko.json @@ -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": "위치 전용이 아닌 매개 변수 다음에는 위치 전용 매개 변수를 사용할 수 없습니다.", @@ -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}’와(과) 호환되지 않습니다." }, diff --git a/packages/pyright-internal/src/localization/package.nls.pl.json b/packages/pyright-internal/src/localization/package.nls.pl.json index 04338317f391..2a8ec133828c 100644 --- a/packages/pyright-internal/src/localization/package.nls.pl.json +++ b/packages/pyright-internal/src/localization/package.nls.pl.json @@ -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", @@ -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}”" }, diff --git a/packages/pyright-internal/src/localization/package.nls.pt-br.json b/packages/pyright-internal/src/localization/package.nls.pt-br.json index b7e286b99e08..20672375bbb5 100644 --- a/packages/pyright-internal/src/localization/package.nls.pt-br.json +++ b/packages/pyright-internal/src/localization/package.nls.pt-br.json @@ -396,6 +396,7 @@ "parenthesizedContextManagerIllegal": "Parentheses within \"with\" statement requires Python 3.9 or newer", "patternNeverMatches": "O padrão nunca será correspondido para o tipo de assunto \"{type}\"", "positionArgAfterNamedArg": "O argumento posicional não pode aparecer após argumentos de palavra-chave", + "positionArgAfterUnpackedDictArg": "Positional argument cannot appear after keyword argument unpacking", "positionOnlyAfterArgs": "Separador de parâmetro somente de posição não permitido após o parâmetro \"*\"", "positionOnlyAfterKeywordOnly": "O parâmetro \"/\" deve aparecer antes do parâmetro \"*\"", "positionOnlyAfterNon": "Parâmetro somente de posição não permitido após o parâmetro que não é somente posição", @@ -815,10 +816,10 @@ "unhashableType": "O tipo \"{type}\" não é pode fazer hash", "uninitializedAbstractVariable": "A variável de instância \"{name}\" está definida na classe base abstrata \"{classType}\", mas não foi inicializada", "unreachableExcept": "\"{exceptionType}\" é uma subclasse 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": "Usar dict[T1, T2] para indicar um tipo de dicionário", + "useListInstead": "Usar list[T] para indicar um tipo de list ou T1 | T2 para indicar um tipo de union", + "useTupleInstead": "Usar tuple[T1, ..., Tn] para indicar um tipo de tuple ou T1 | T2 para indicar um tipo de union", + "useTypeInstead": "Usar type[T] em vez disso", "varianceMismatchForClass": "A variação do argumento de tipo \"{typeVarName}\" é incompatível com a classe base \"{className}\"", "varianceMismatchForTypeAlias": "A variação do argumento de tipo \"{typeVarName}\" é incompatível com \"{typeAliasParam}\"" }, diff --git a/packages/pyright-internal/src/localization/package.nls.qps-ploc.json b/packages/pyright-internal/src/localization/package.nls.qps-ploc.json index ac439b754411..786aa525116b 100644 --- a/packages/pyright-internal/src/localization/package.nls.qps-ploc.json +++ b/packages/pyright-internal/src/localization/package.nls.qps-ploc.json @@ -396,6 +396,7 @@ "parenthesizedContextManagerIllegal": "[NBxCb][นั้Pærëñthësës withïñ \"with\" stætëmëñt rëqµïrës Pÿthøñ 3.9 ør ñëwërẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृนั้ढूँ]", "patternNeverMatches": "[lyG7p][นั้Pættërñ wïll ñëvër þë mætçhëð før sµþjëçt tÿpë \"{tÿpë}\"Ấğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्นั้ढूँ]", "positionArgAfterNamedArg": "[szCz2][นั้Pøsïtïøñæl ærgµmëñt çæññøt æppëær æftër këÿwørð ærgµmëñtsẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्นั้ढूँ]", + "positionArgAfterUnpackedDictArg": "[M8vOq][นั้Pøsïtïøñæl ærgµmëñt çæññøt æppëær æftër këÿwørð ærgµmëñt µñpæçkïñgẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृนั้ढूँ]", "positionOnlyAfterArgs": "[Vqb7c][นั้Pøsïtïøñ-øñlÿ pæræmëtër sëpærætør ñøt ælløwëð æftër \"*\" pæræmëtërẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृนั้ढूँ]", "positionOnlyAfterKeywordOnly": "[z1FIK][นั้\"/\" pæræmëtër mµst æppëær þëførë \"*\" pæræmëtërẤğ倪İЂҰक्र्तिृまẤğ倪İนั้ढूँ]", "positionOnlyAfterNon": "[iXb2r][นั้Pøsïtïøñ-øñlÿ pæræmëtër ñøt ælløwëð æftër pæræmëtër thæt ïs ñøt pøsïtïøñ-øñlÿẤğ倪İЂҰक्र्तिृまẤğ倪İЂҰक्र्तिृまẤğ倪นั้ढूँ]", diff --git a/packages/pyright-internal/src/localization/package.nls.ru.json b/packages/pyright-internal/src/localization/package.nls.ru.json index 09415445ee6f..b2bc76378fca 100644 --- a/packages/pyright-internal/src/localization/package.nls.ru.json +++ b/packages/pyright-internal/src/localization/package.nls.ru.json @@ -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": "Чисто позиционный параметр не разрешен после параметра, который не является чисто позиционным", @@ -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}\"" }, diff --git a/packages/pyright-internal/src/localization/package.nls.tr.json b/packages/pyright-internal/src/localization/package.nls.tr.json index eee88a62bbeb..ee975cad80a7 100644 --- a/packages/pyright-internal/src/localization/package.nls.tr.json +++ b/packages/pyright-internal/src/localization/package.nls.tr.json @@ -396,6 +396,7 @@ "parenthesizedContextManagerIllegal": "Parentheses within \"with\" statement requires Python 3.9 or newer", "patternNeverMatches": "Desen, \"{type}\" konu türü ile hiçbir zaman eşleşmez", "positionArgAfterNamedArg": "Konumsal bağımsız değişken anahtar sözcük bağımsız değişkenlerden sonra gelemez", + "positionArgAfterUnpackedDictArg": "Positional argument cannot appear after keyword argument unpacking", "positionOnlyAfterArgs": "\"*\" parametresinden sonra yalnızca konum parametre ayırıcısı kullanılamaz", "positionOnlyAfterKeywordOnly": "\"/\" parametresi \"*\" parametresinden önce gelmelidir", "positionOnlyAfterNon": "Yalnızca konum parametresi olmayan parametreden sonra yalnızca konum parametresine izin verilmez", @@ -815,10 +816,10 @@ "unhashableType": "\"{type}\" türü karmalanabilir değil", "uninitializedAbstractVariable": "\"{name}\" örnek değişkeni, \"{classType}\" soyut temel sınıfında tanımlandı ancak başlatılmadı", "unreachableExcept": "\"{exceptionType}\", \"{parentType}\" üst öğesinin bir alt sınıfı", - "useDictInstead": "Use dict[T1, T2] to indicate a dictionary type", + "useDictInstead": "Sözlük türünü belirtmek için dict[T1, T2] kullanın", "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": "Bunun yerine type[T] kullanın", "varianceMismatchForClass": "\"{typeVarName}\" tür bağımsız değişkeni \"{className}\" taban sınıfıyla uyumsuz", "varianceMismatchForTypeAlias": "\"{typeVarName}\" tür bağımsız değişkeninin varyansı, \"{typeAliasParam}\" ile uyumsuz" }, diff --git a/packages/pyright-internal/src/localization/package.nls.zh-cn.json b/packages/pyright-internal/src/localization/package.nls.zh-cn.json index 3dcf7192d256..55402a9d9bd2 100644 --- a/packages/pyright-internal/src/localization/package.nls.zh-cn.json +++ b/packages/pyright-internal/src/localization/package.nls.zh-cn.json @@ -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": "非仅位置参数后面不允许仅位置参数", @@ -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}\"不兼容" }, diff --git a/packages/pyright-internal/src/localization/package.nls.zh-tw.json b/packages/pyright-internal/src/localization/package.nls.zh-tw.json index 6ac4929d0728..21582b0ba3fa 100644 --- a/packages/pyright-internal/src/localization/package.nls.zh-tw.json +++ b/packages/pyright-internal/src/localization/package.nls.zh-tw.json @@ -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": "\"*\" 參數之後不允許 Position-only 參數分隔符號", "positionOnlyAfterKeywordOnly": "\"/\" 參數必須出現在 \"*\" 參數之前", "positionOnlyAfterNon": "非 Position-only 參數之後不允許 Position-only 參數", @@ -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}\" 不相容" }, diff --git a/packages/pyright-internal/src/tests/hoverProvider.test.ts b/packages/pyright-internal/src/tests/hoverProvider.test.ts index a2527dac2790..0629b813c95b 100644 --- a/packages/pyright-internal/src/tests/hoverProvider.test.ts +++ b/packages/pyright-internal/src/tests/hoverProvider.test.ts @@ -379,3 +379,62 @@ test('TypedDict doc string', async () => { marker: '```python\n(class) TypedDict\n```\n---\nA simple typed namespace. At runtime it is equivalent to a plain dict.', }); }); + +test('hover on class Foo and its __call__ method with overloads', async () => { + const code = ` +// @filename: test.py +//// from typing import overload +//// class Foo: +//// def __init__(self): +//// pass +//// +//// @overload +//// def __call__(self, a: int) -> int: pass +//// @overload +//// def __call__(self, a: str) -> str: pass +//// def __call__(self, a: int | str) -> int | str: +//// return a +//// +//// [|/*marker1*/foo|] = Foo() +//// [|/*marker2*/foo|](1) +//// [|/*marker3*/foo|]("hello") +//// [|/*marker4*/foo|]() + `; + + const state = parseAndGetTestState(code).state; + const marker1 = state.getMarkerByName('marker1'); + + state.openFile(marker1.fileName); + + state.verifyHover('markdown', { + marker1: '```python\n(variable) foo: Foo\n```', + marker2: '```python\n(variable) def foo(a: int) -> int\n```', + marker3: '```python\n(variable) def foo(a: str) -> str\n```', + marker4: '```python\n(variable)\ndef __call__(a: int) -> int: ...\ndef __call__(a: str) -> str: ...\n```', + }); +}); + +test('hover on __call__ method', async () => { + const code = ` +// @filename: test.py +//// class Foo: +//// def __init__(self): +//// pass +//// +//// def __call__(self, a: int) -> int: +//// return a +//// +//// [|/*marker1*/foo|] = Foo() +//// [|/*marker2*/foo|](1) + `; + + const state = parseAndGetTestState(code).state; + const marker1 = state.getMarkerByName('marker1'); + + state.openFile(marker1.fileName); + + state.verifyHover('markdown', { + marker1: '```python\n(variable) foo: Foo\n```', + marker2: '```python\n(variable) def foo(a: int) -> int\n```', + }); +});