diff --git a/packages/pyright-internal/src/analyzer/typeEvaluator.ts b/packages/pyright-internal/src/analyzer/typeEvaluator.ts index f66c58f2c..1789b7cc0 100644 --- a/packages/pyright-internal/src/analyzer/typeEvaluator.ts +++ b/packages/pyright-internal/src/analyzer/typeEvaluator.ts @@ -27006,7 +27006,14 @@ export function createTypeEvaluator( const specializedFunction = applySolvedTypeVars(memberType, typeVarContext) as FunctionType; - return FunctionType.clone(specializedFunction, stripFirstParam, baseType, getTypeVarScopeId(baseType)); + // If this is a constructor method, provide the base type's TypeVar scope ID + // so any TypeVars in this type can be solved. + let baseTypeTypeVarScopeId: TypeVarScopeId | undefined; + if (FunctionType.isConstructorMethod(specializedFunction) || specializedFunction.details.name === '__init__') { + baseTypeTypeVarScopeId = getTypeVarScopeId(baseType); + } + + return FunctionType.clone(specializedFunction, stripFirstParam, baseType, baseTypeTypeVarScopeId); } function isFinalVariable(symbol: Symbol): boolean { diff --git a/packages/pyright-internal/src/analyzer/types.ts b/packages/pyright-internal/src/analyzer/types.ts index c86c99e24..9086f0e23 100644 --- a/packages/pyright-internal/src/analyzer/types.ts +++ b/packages/pyright-internal/src/analyzer/types.ts @@ -1658,10 +1658,7 @@ export namespace FunctionType { } newFunction.inferredReturnType = type.inferredReturnType; - - if (newFunction.preBoundFlags & FunctionTypeFlags.ConstructorMethod) { - newFunction.boundTypeVarScopeId = boundTypeVarScopeId ?? type.boundTypeVarScopeId; - } + newFunction.boundTypeVarScopeId = boundTypeVarScopeId ?? type.boundTypeVarScopeId; return newFunction; }