mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-19 04:07:36 +03:00
Fixed #155: Add missing declared type for "self" or "cls" parameters in methods so the hover provider reports the correct inferred type.
This commit is contained in:
parent
ed4f87a4c9
commit
6c25035b1d
@ -436,22 +436,21 @@ export class TypeAnalyzer extends ParseTreeWalker {
|
|||||||
parameters.forEach((param, index) => {
|
parameters.forEach((param, index) => {
|
||||||
const paramNode = node.parameters[index];
|
const paramNode = node.parameters[index];
|
||||||
if (paramNode.name) {
|
if (paramNode.name) {
|
||||||
|
const specializedParamType = TypeUtils.specializeType(param.type, undefined);
|
||||||
|
|
||||||
let declaration: Declaration | undefined;
|
let declaration: Declaration | undefined;
|
||||||
declaration = {
|
declaration = {
|
||||||
category: SymbolCategory.Parameter,
|
category: SymbolCategory.Parameter,
|
||||||
node: paramNode,
|
node: paramNode,
|
||||||
path: this._fileInfo.filePath,
|
path: this._fileInfo.filePath,
|
||||||
range: convertOffsetsToRange(paramNode.start, paramNode.end, this._fileInfo.lines),
|
range: convertOffsetsToRange(paramNode.start, paramNode.end, this._fileInfo.lines),
|
||||||
declaredType: paramNode.typeAnnotation ?
|
declaredType: specializedParamType
|
||||||
TypeUtils.specializeType(param.type, undefined) :
|
|
||||||
undefined
|
|
||||||
};
|
};
|
||||||
assert(paramNode !== undefined && paramNode.name !== undefined);
|
assert(paramNode !== undefined && paramNode.name !== undefined);
|
||||||
|
|
||||||
// If the type contains type variables, specialize them now
|
// If the type contains type variables, specialize them now
|
||||||
// so we convert them to a concrete type (or unknown if there
|
// so we convert them to a concrete type (or unknown if there
|
||||||
// are is no bound or contraints).
|
// is no bound or contraint).
|
||||||
const specializedParamType = TypeUtils.specializeType(param.type, undefined);
|
|
||||||
const variadicParamType = this._getVariadicParamType(param.category, specializedParamType);
|
const variadicParamType = this._getVariadicParamType(param.category, specializedParamType);
|
||||||
this._addTypeSourceToNameNode(paramNode.name, variadicParamType, declaration);
|
this._addTypeSourceToNameNode(paramNode.name, variadicParamType, declaration);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user