Added consistent use of getTypeVarScopeId accessor function. No functional change.

This commit is contained in:
Eric Traut 2024-06-10 13:37:17 -07:00
parent 45fcebfe2c
commit 81d43e4c41
4 changed files with 9 additions and 8 deletions

View File

@ -89,9 +89,9 @@ export function synthesizeDataClassMethods(
const classTypeVar = synthesizeTypeVarForSelfCls(classType, /* isClsParam */ true);
const newType = FunctionType.createSynthesizedInstance('__new__', FunctionTypeFlags.ConstructorMethod);
newType.details.constructorTypeVarScopeId = classType.details.typeVarScopeId;
newType.details.constructorTypeVarScopeId = getTypeVarScopeId(classType);
const initType = FunctionType.createSynthesizedInstance('__init__');
initType.details.constructorTypeVarScopeId = classType.details.typeVarScopeId;
initType.details.constructorTypeVarScopeId = getTypeVarScopeId(classType);
// Generate both a __new__ and an __init__ method. The parameters of the
// __new__ method are based on field definitions for NamedTuple classes,

View File

@ -29,6 +29,7 @@ import { FunctionArgument, TypeEvaluator } from './typeEvaluatorTypes';
import {
computeMroLinearization,
convertToInstance,
getTypeVarScopeId,
isLiteralType,
isTupleClass,
isUnboundedTupleClass,
@ -138,7 +139,7 @@ export function createNamedTupleType(
const classTypeVar = synthesizeTypeVarForSelfCls(classType, /* isClsParam */ true);
const constructorType = FunctionType.createSynthesizedInstance('__new__', FunctionTypeFlags.ConstructorMethod);
constructorType.details.declaredReturnType = convertToInstance(classTypeVar);
constructorType.details.constructorTypeVarScopeId = classType.details.typeVarScopeId;
constructorType.details.constructorTypeVarScopeId = getTypeVarScopeId(classType);
if (ParseTreeUtils.isAssignmentToDefaultsFollowingNamedTuple(errorNode)) {
constructorType.details.flags |= FunctionTypeFlags.DisableDefaultChecks;
}
@ -377,7 +378,7 @@ export function createNamedTupleType(
FunctionType.addParameter(initType, selfParameter);
FunctionType.addDefaultParameters(initType);
initType.details.declaredReturnType = evaluator.getNoneType();
initType.details.constructorTypeVarScopeId = classType.details.typeVarScopeId;
initType.details.constructorTypeVarScopeId = getTypeVarScopeId(classType);
classFields.set('__new__', Symbol.createWithType(SymbolFlags.ClassMember, constructorType));
classFields.set('__init__', Symbol.createWithType(SymbolFlags.ClassMember, initType));

View File

@ -13072,7 +13072,7 @@ export function createTypeEvaluator(
});
FunctionType.addDefaultParameters(newType);
newType.details.declaredReturnType = ClassType.cloneAsInstance(classType);
newType.details.constructorTypeVarScopeId = classType.details.typeVarScopeId;
newType.details.constructorTypeVarScopeId = getTypeVarScopeId(classType);
ClassType.getSymbolTable(classType).set('__new__', Symbol.createWithType(SymbolFlags.ClassMember, newType));
}

View File

@ -252,7 +252,7 @@ export function synthesizeTypedDictClassMethods(
});
FunctionType.addDefaultParameters(newType);
newType.details.declaredReturnType = ClassType.cloneAsInstance(classType);
newType.details.constructorTypeVarScopeId = classType.details.typeVarScopeId;
newType.details.constructorTypeVarScopeId = getTypeVarScopeId(classType);
// Synthesize an __init__ method with two overrides.
const initOverride1 = FunctionType.createSynthesizedInstance('__init__', FunctionTypeFlags.Overloaded);
@ -263,7 +263,7 @@ export function synthesizeTypedDictClassMethods(
hasDeclaredType: true,
});
initOverride1.details.declaredReturnType = evaluator.getNoneType();
initOverride1.details.constructorTypeVarScopeId = classType.details.typeVarScopeId;
initOverride1.details.constructorTypeVarScopeId = getTypeVarScopeId(classType);
// The first parameter must be positional-only.
FunctionType.addParameter(initOverride1, {
@ -285,7 +285,7 @@ export function synthesizeTypedDictClassMethods(
hasDeclaredType: true,
});
initOverride2.details.declaredReturnType = evaluator.getNoneType();
initOverride2.details.constructorTypeVarScopeId = classType.details.typeVarScopeId;
initOverride2.details.constructorTypeVarScopeId = getTypeVarScopeId(classType);
// All parameters must be named, so insert an empty "*".
FunctionType.addKeywordOnlyParameterSeparator(initOverride2);