From 81d43e4c4179e8ecf04538f38ae18120a31a2779 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Mon, 10 Jun 2024 13:37:17 -0700 Subject: [PATCH] Added consistent use of `getTypeVarScopeId` accessor function. No functional change. --- packages/pyright-internal/src/analyzer/dataClasses.ts | 4 ++-- packages/pyright-internal/src/analyzer/namedTuples.ts | 5 +++-- packages/pyright-internal/src/analyzer/typeEvaluator.ts | 2 +- packages/pyright-internal/src/analyzer/typedDicts.ts | 6 +++--- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/pyright-internal/src/analyzer/dataClasses.ts b/packages/pyright-internal/src/analyzer/dataClasses.ts index 57357e7e2..6673c17e9 100644 --- a/packages/pyright-internal/src/analyzer/dataClasses.ts +++ b/packages/pyright-internal/src/analyzer/dataClasses.ts @@ -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, diff --git a/packages/pyright-internal/src/analyzer/namedTuples.ts b/packages/pyright-internal/src/analyzer/namedTuples.ts index 93b5216ac..2fc07cd9e 100644 --- a/packages/pyright-internal/src/analyzer/namedTuples.ts +++ b/packages/pyright-internal/src/analyzer/namedTuples.ts @@ -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)); diff --git a/packages/pyright-internal/src/analyzer/typeEvaluator.ts b/packages/pyright-internal/src/analyzer/typeEvaluator.ts index 444fd9502..cafaab6f7 100644 --- a/packages/pyright-internal/src/analyzer/typeEvaluator.ts +++ b/packages/pyright-internal/src/analyzer/typeEvaluator.ts @@ -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)); } diff --git a/packages/pyright-internal/src/analyzer/typedDicts.ts b/packages/pyright-internal/src/analyzer/typedDicts.ts index aa596f6bb..e678d32d3 100644 --- a/packages/pyright-internal/src/analyzer/typedDicts.ts +++ b/packages/pyright-internal/src/analyzer/typedDicts.ts @@ -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);