Modified typing data structures to increase monomorphism for performance reasons. (#8415)

This commit is contained in:
Eric Traut 2024-07-13 14:43:45 -07:00 committed by GitHub
parent 17bd81a7de
commit 496822d3d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
37 changed files with 2923 additions and 2749 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1411,15 +1411,15 @@ export function getCodeFlowEngine(
// can be narrowed to one of its constrained types based on isinstance type // can be narrowed to one of its constrained types based on isinstance type
// guard checks. // guard checks.
function narrowConstrainedTypeVar(flowNode: FlowNode, typeVar: TypeVarType): ClassType | undefined { function narrowConstrainedTypeVar(flowNode: FlowNode, typeVar: TypeVarType): ClassType | undefined {
assert(!typeVar.details.isParamSpec); assert(!typeVar.shared.isParamSpec);
assert(!typeVar.details.isVariadic); assert(!typeVar.shared.isVariadic);
assert(!typeVar.details.boundType); assert(!typeVar.shared.boundType);
assert(typeVar.details.constraints.length > 0); assert(typeVar.shared.constraints.length > 0);
const visitedFlowNodeMap = new Set<number>(); const visitedFlowNodeMap = new Set<number>();
const startingConstraints: ClassType[] = []; const startingConstraints: ClassType[] = [];
for (const constraint of typeVar.details.constraints) { for (const constraint of typeVar.shared.constraints) {
if (isClassInstance(constraint)) { if (isClassInstance(constraint)) {
startingConstraints.push(constraint); startingConstraints.push(constraint);
} else { } else {
@ -1604,8 +1604,8 @@ export function getCodeFlowEngine(
if ( if (
!subtype.props.condition.some( !subtype.props.condition.some(
(condition) => (condition) =>
condition.typeVar.details.constraints.length > 0 && condition.typeVar.shared.constraints.length > 0 &&
condition.typeVar.nameWithScope === typeVar.nameWithScope condition.typeVar.priv.nameWithScope === typeVar.priv.nameWithScope
) )
) { ) {
isCompatible = false; isCompatible = false;
@ -1749,15 +1749,15 @@ export function getCodeFlowEngine(
} }
function isFunctionNoReturn(functionType: FunctionType, isCallAwaited: boolean) { function isFunctionNoReturn(functionType: FunctionType, isCallAwaited: boolean) {
const returnType = functionType.details.declaredReturnType; const returnType = functionType.shared.declaredReturnType;
if (returnType) { if (returnType) {
if ( if (
isClassInstance(returnType) && isClassInstance(returnType) &&
ClassType.isBuiltIn(returnType, 'Coroutine') && ClassType.isBuiltIn(returnType, 'Coroutine') &&
returnType.typeArguments && returnType.priv.typeArguments &&
returnType.typeArguments.length >= 3 returnType.priv.typeArguments.length >= 3
) { ) {
if (isNever(returnType.typeArguments[2]) && isCallAwaited) { if (isNever(returnType.priv.typeArguments[2]) && isCallAwaited) {
return true; return true;
} }
} }
@ -1765,19 +1765,19 @@ export function getCodeFlowEngine(
return isNever(returnType); return isNever(returnType);
} else if (!inferNoReturnForUnannotatedFunctions) { } else if (!inferNoReturnForUnannotatedFunctions) {
return false; return false;
} else if (functionType.details.declaration) { } else if (functionType.shared.declaration) {
// If the function is a generator (i.e. it has yield statements) // If the function is a generator (i.e. it has yield statements)
// then it is not a "no return" call. Also, don't infer a "no // then it is not a "no return" call. Also, don't infer a "no
// return" type for abstract methods. // return" type for abstract methods.
if ( if (
!functionType.details.declaration.isGenerator && !functionType.shared.declaration.isGenerator &&
!FunctionType.isAbstractMethod(functionType) && !FunctionType.isAbstractMethod(functionType) &&
!FunctionType.isStubDefinition(functionType) && !FunctionType.isStubDefinition(functionType) &&
!FunctionType.isPyTypedDefinition(functionType) !FunctionType.isPyTypedDefinition(functionType)
) { ) {
// Check specifically for a common idiom where the only statement // Check specifically for a common idiom where the only statement
// (other than a possible docstring) is a "raise NotImplementedError". // (other than a possible docstring) is a "raise NotImplementedError".
const functionStatements = functionType.details.declaration.node.suite.statements; const functionStatements = functionType.shared.declaration.node.suite.statements;
let foundRaiseNotImplemented = false; let foundRaiseNotImplemented = false;
for (const statement of functionStatements) { for (const statement of functionStatements) {
@ -1816,11 +1816,11 @@ export function getCodeFlowEngine(
} }
function isAfterNodeReachable(evaluator: TypeEvaluator, functionType: FunctionType) { function isAfterNodeReachable(evaluator: TypeEvaluator, functionType: FunctionType) {
if (!functionType.details.declaration) { if (!functionType.shared.declaration) {
return true; return true;
} }
return evaluator.isAfterNodeReachable(functionType.details.declaration.node); return evaluator.isAfterNodeReachable(functionType.shared.declaration.node);
} }
// Performs a cursory analysis to determine whether the expression // Performs a cursory analysis to determine whether the expression
@ -1853,8 +1853,8 @@ export function getCodeFlowEngine(
const exitMethodName = isAsync ? '__aexit__' : '__exit__'; const exitMethodName = isAsync ? '__aexit__' : '__exit__';
const exitType = evaluator.getBoundMagicMethod(cmType, exitMethodName); const exitType = evaluator.getBoundMagicMethod(cmType, exitMethodName);
if (exitType && isFunction(exitType) && exitType.details.declaredReturnType) { if (exitType && isFunction(exitType) && exitType.shared.declaredReturnType) {
let returnType = exitType.details.declaredReturnType; let returnType = exitType.shared.declaredReturnType;
// If it's an __aexit__ method, its return type will typically be wrapped // If it's an __aexit__ method, its return type will typically be wrapped
// in a Coroutine, so we need to extract the return type from the third // in a Coroutine, so we need to extract the return type from the third
@ -1863,16 +1863,16 @@ export function getCodeFlowEngine(
if ( if (
isClassInstance(returnType) && isClassInstance(returnType) &&
ClassType.isBuiltIn(returnType, 'Coroutine') && ClassType.isBuiltIn(returnType, 'Coroutine') &&
returnType.typeArguments && returnType.priv.typeArguments &&
returnType.typeArguments.length >= 3 returnType.priv.typeArguments.length >= 3
) { ) {
returnType = returnType.typeArguments[2]; returnType = returnType.priv.typeArguments[2];
} }
} }
cmSwallowsExceptions = false; cmSwallowsExceptions = false;
if (isClassInstance(returnType) && ClassType.isBuiltIn(returnType, 'bool')) { if (isClassInstance(returnType) && ClassType.isBuiltIn(returnType, 'bool')) {
if (returnType.literalValue === undefined || returnType.literalValue === true) { if (returnType.priv.literalValue === undefined || returnType.priv.literalValue === true) {
cmSwallowsExceptions = true; cmSwallowsExceptions = true;
} }
} }

View File

@ -104,7 +104,7 @@ export function assignTypeToTypeVar(
// If the TypeVar doesn't have a scope ID, then it's being used // If the TypeVar doesn't have a scope ID, then it's being used
// outside of a valid TypeVar scope. This will be reported as a // outside of a valid TypeVar scope. This will be reported as a
// separate error. Just ignore this case to avoid redundant errors. // separate error. Just ignore this case to avoid redundant errors.
if (!destType.scopeId) { if (!destType.priv.scopeId) {
return true; return true;
} }
@ -119,7 +119,7 @@ export function assignTypeToTypeVar(
// Verify that we are solving for the scope associated with this // Verify that we are solving for the scope associated with this
// type variable. // type variable.
if (!typeVarContext.hasSolveForScope(destType.scopeId)) { if (!typeVarContext.hasSolveForScope(destType.priv.scopeId)) {
// Handle Any as a source. // Handle Any as a source.
if (isAnyOrUnknown(srcType) || (isClass(srcType) && ClassType.derivesFromAnyOrUnknown(srcType))) { if (isAnyOrUnknown(srcType) || (isClass(srcType) && ClassType.derivesFromAnyOrUnknown(srcType))) {
return true; return true;
@ -128,9 +128,9 @@ export function assignTypeToTypeVar(
// Handle a type[Any] as a source. // Handle a type[Any] as a source.
if (isClassInstance(srcType) && ClassType.isBuiltIn(srcType, 'type')) { if (isClassInstance(srcType) && ClassType.isBuiltIn(srcType, 'type')) {
if ( if (
!srcType.typeArguments || !srcType.priv.typeArguments ||
srcType.typeArguments.length < 1 || srcType.priv.typeArguments.length < 1 ||
isAnyOrUnknown(srcType.typeArguments[0]) isAnyOrUnknown(srcType.priv.typeArguments[0])
) { ) {
if (TypeBase.isInstantiable(destType)) { if (TypeBase.isInstantiable(destType)) {
return true; return true;
@ -140,7 +140,7 @@ export function assignTypeToTypeVar(
// Is this the equivalent of an "Unknown" for a ParamSpec? // Is this the equivalent of an "Unknown" for a ParamSpec?
if ( if (
destType.details.isParamSpec && destType.shared.isParamSpec &&
isFunction(srcType) && isFunction(srcType) &&
FunctionType.isParamSpecValue(srcType) && FunctionType.isParamSpecValue(srcType) &&
FunctionType.isGradualCallableForm(srcType) FunctionType.isGradualCallableForm(srcType)
@ -164,7 +164,7 @@ export function assignTypeToTypeVar(
// Emit an error unless this is a synthesized type variable used // Emit an error unless this is a synthesized type variable used
// for pseudo-generic classes. // for pseudo-generic classes.
if (!destType.details.isSynthesized || destType.details.isSynthesizedSelf) { if (!destType.shared.isSynthesized || destType.shared.isSynthesizedSelf) {
diag?.addMessage( diag?.addMessage(
LocAddendum.typeAssignmentMismatch().format(evaluator.printSrcDestTypes(srcType, destType)) LocAddendum.typeAssignmentMismatch().format(evaluator.printSrcDestTypes(srcType, destType))
); );
@ -174,7 +174,7 @@ export function assignTypeToTypeVar(
// An in-scope placeholder TypeVar can always be assigned to itself, // An in-scope placeholder TypeVar can always be assigned to itself,
// but we won't record this in the typeVarContext. // but we won't record this in the typeVarContext.
if (isTypeSame(destType, srcType) && destType.isInScopePlaceholder) { if (isTypeSame(destType, srcType) && destType.priv.isInScopePlaceholder) {
return true; return true;
} }
@ -190,11 +190,11 @@ export function assignTypeToTypeVar(
); );
} }
if (destType.details.isParamSpec) { if (destType.shared.isParamSpec) {
return assignTypeToParamSpec(evaluator, destType, srcType, diag, typeVarContext, recursionCount); return assignTypeToParamSpec(evaluator, destType, srcType, diag, typeVarContext, recursionCount);
} }
if (destType.details.isVariadic && !destType.isVariadicInUnion) { if (destType.shared.isVariadic && !destType.priv.isVariadicInUnion) {
if (!isUnpacked(srcType)) { if (!isUnpacked(srcType)) {
const tupleClassType = evaluator.getTupleClassType(); const tupleClassType = evaluator.getTupleClassType();
if (tupleClassType && isInstantiableClass(tupleClassType)) { if (tupleClassType && isInstantiableClass(tupleClassType)) {
@ -217,10 +217,10 @@ export function assignTypeToTypeVar(
// we need to treat it as a union of the unpacked TypeVarTuple. // we need to treat it as a union of the unpacked TypeVarTuple.
if ( if (
isTypeVar(srcType) && isTypeVar(srcType) &&
srcType.details.isVariadic && srcType.shared.isVariadic &&
srcType.isVariadicUnpacked && srcType.priv.isVariadicUnpacked &&
!srcType.isVariadicInUnion && !srcType.priv.isVariadicInUnion &&
!destType.details.isVariadic !destType.shared.isVariadic
) { ) {
srcType = TypeVarType.cloneForUnpacked(srcType, /* isInUnion */ true); srcType = TypeVarType.cloneForUnpacked(srcType, /* isInUnion */ true);
} }
@ -229,7 +229,7 @@ export function assignTypeToTypeVar(
// because type narrowing isn't used in this case. For example, if the // because type narrowing isn't used in this case. For example, if the
// source type is "Literal[1]" and the constraint list includes the type // source type is "Literal[1]" and the constraint list includes the type
// "float", the resulting type is float. // "float", the resulting type is float.
if (destType.details.constraints.length > 0) { if (destType.shared.constraints.length > 0) {
return assignTypeToConstrainedTypeVar( return assignTypeToConstrainedTypeVar(
evaluator, evaluator,
destType, destType,
@ -246,8 +246,8 @@ export function assignTypeToTypeVar(
const curEntry = typeVarContext.getPrimarySignature().getTypeVar(destType); const curEntry = typeVarContext.getPrimarySignature().getTypeVar(destType);
let curWideTypeBound = curEntry?.wideBound; let curWideTypeBound = curEntry?.wideBound;
if (!curWideTypeBound && !destType.details.isSynthesizedSelf) { if (!curWideTypeBound && !destType.shared.isSynthesizedSelf) {
curWideTypeBound = destType.details.boundType; curWideTypeBound = destType.shared.boundType;
} }
let curNarrowTypeBound = curEntry?.narrowBound; let curNarrowTypeBound = curEntry?.narrowBound;
let newNarrowTypeBound = curNarrowTypeBound; let newNarrowTypeBound = curNarrowTypeBound;
@ -259,7 +259,7 @@ export function assignTypeToTypeVar(
// If the source is a class that is missing type arguments, fill // If the source is a class that is missing type arguments, fill
// in missing type arguments with Unknown. // in missing type arguments with Unknown.
if ((flags & AssignTypeFlags.AllowUnspecifiedTypeArguments) === 0) { if ((flags & AssignTypeFlags.AllowUnspecifiedTypeArguments) === 0) {
if (isClass(adjSrcType) && adjSrcType.includeSubclasses) { if (isClass(adjSrcType) && adjSrcType.priv.includeSubclasses) {
adjSrcType = specializeWithDefaultTypeArgs(adjSrcType); adjSrcType = specializeWithDefaultTypeArgs(adjSrcType);
} }
} }
@ -493,8 +493,8 @@ export function assignTypeToTypeVar(
// is still a valid solution to the TypeVar. // is still a valid solution to the TypeVar.
if ( if (
isUnion(curSolvedNarrowTypeBound) && isUnion(curSolvedNarrowTypeBound) &&
curSolvedNarrowTypeBound.subtypes.length > maxSubtypesForInferredType && curSolvedNarrowTypeBound.priv.subtypes.length > maxSubtypesForInferredType &&
(destType as TypeVarType).details.boundType !== undefined && (destType as TypeVarType).shared.boundType !== undefined &&
isClassInstance(objectType) isClassInstance(objectType)
) { ) {
newNarrowTypeBound = combineTypes([curSolvedNarrowTypeBound, objectType], { newNarrowTypeBound = combineTypes([curSolvedNarrowTypeBound, objectType], {
@ -579,7 +579,7 @@ export function assignTypeToTypeVar(
} }
// If there's a bound type, make sure the source is assignable to it. // If there's a bound type, make sure the source is assignable to it.
if (destType.details.boundType) { if (destType.shared.boundType) {
const updatedType = (newNarrowTypeBound || newWideTypeBound)!; const updatedType = (newNarrowTypeBound || newWideTypeBound)!;
// If the dest is a Type[T] but the source is not a valid Type, // If the dest is a Type[T] but the source is not a valid Type,
@ -592,13 +592,13 @@ export function assignTypeToTypeVar(
// In general, bound types cannot be generic, but the "Self" type is an // In general, bound types cannot be generic, but the "Self" type is an
// exception. In this case, we need to use the original TypeVarContext // exception. In this case, we need to use the original TypeVarContext
// to solve for the generic type variable(s) in the bound type. // to solve for the generic type variable(s) in the bound type.
const effectiveTypeVarContext = destType.details.isSynthesizedSelf const effectiveTypeVarContext = destType.shared.isSynthesizedSelf
? typeVarContext ? typeVarContext
: new TypeVarContext(destType.scopeId); : new TypeVarContext(destType.priv.scopeId);
if ( if (
!evaluator.assignType( !evaluator.assignType(
destType.details.boundType, destType.shared.boundType,
evaluator.makeTopLevelTypeVarsConcrete(updatedType), evaluator.makeTopLevelTypeVarsConcrete(updatedType),
diag?.createAddendum(), diag?.createAddendum(),
effectiveTypeVarContext, effectiveTypeVarContext,
@ -609,11 +609,11 @@ export function assignTypeToTypeVar(
) { ) {
// Avoid adding a message that will confuse users if the TypeVar was // Avoid adding a message that will confuse users if the TypeVar was
// synthesized for internal purposes. // synthesized for internal purposes.
if (!destType.details.isSynthesized) { if (!destType.shared.isSynthesized) {
diag?.addMessage( diag?.addMessage(
LocAddendum.typeBound().format({ LocAddendum.typeBound().format({
sourceType: evaluator.printType(updatedType), sourceType: evaluator.printType(updatedType),
destType: evaluator.printType(destType.details.boundType), destType: evaluator.printType(destType.shared.boundType),
name: TypeVarType.getReadableName(destType), name: TypeVarType.getReadableName(destType),
}) })
); );
@ -712,7 +712,7 @@ function assignTypeToConstrainedTypeVar(
destType, destType,
concreteSrcType, concreteSrcType,
/* diag */ undefined, /* diag */ undefined,
new TypeVarContext(destType.scopeId), new TypeVarContext(destType.priv.scopeId),
/* srcTypeVarContext */ undefined, /* srcTypeVarContext */ undefined,
AssignTypeFlags.Default, AssignTypeFlags.Default,
recursionCount recursionCount
@ -743,7 +743,7 @@ function assignTypeToConstrainedTypeVar(
} }
let constraintIndexUsed: number | undefined; let constraintIndexUsed: number | undefined;
destType.details.constraints.forEach((constraint, i) => { destType.shared.constraints.forEach((constraint, i) => {
const adjustedConstraint = TypeBase.isInstantiable(destType) const adjustedConstraint = TypeBase.isInstantiable(destType)
? convertToInstantiable(constraint) ? convertToInstantiable(constraint)
: constraint; : constraint;
@ -810,7 +810,7 @@ function assignTypeToConstrainedTypeVar(
// If the type is a union, see if the entire union is assignable to one // If the type is a union, see if the entire union is assignable to one
// of the constraints. // of the constraints.
if (!constrainedType && isUnion(concreteSrcType)) { if (!constrainedType && isUnion(concreteSrcType)) {
constrainedType = destType.details.constraints.find((constraint) => { constrainedType = destType.shared.constraints.find((constraint) => {
const adjustedConstraint = TypeBase.isInstantiable(destType) const adjustedConstraint = TypeBase.isInstantiable(destType)
? convertToInstantiable(constraint) ? convertToInstantiable(constraint)
: constraint; : constraint;
@ -834,7 +834,7 @@ function assignTypeToConstrainedTypeVar(
diag?.addMessage( diag?.addMessage(
LocAddendum.typeConstrainedTypeVar().format({ LocAddendum.typeConstrainedTypeVar().format({
type: evaluator.printType(srcType), type: evaluator.printType(srcType),
name: destType.details.name, name: destType.shared.name,
}) })
); );
return false; return false;
@ -911,20 +911,20 @@ function assignTypeToParamSpec(
const adjSrcType = isFunction(srcType) ? convertParamSpecValueToType(srcType) : srcType; const adjSrcType = isFunction(srcType) ? convertParamSpecValueToType(srcType) : srcType;
typeVarContext.doForEachSignature((signatureContext) => { typeVarContext.doForEachSignature((signatureContext) => {
if (isTypeVar(adjSrcType) && adjSrcType.details.isParamSpec) { if (isTypeVar(adjSrcType) && adjSrcType.shared.isParamSpec) {
const existingType = signatureContext.getParamSpecType(destType); const existingType = signatureContext.getParamSpecType(destType);
if (existingType) { if (existingType) {
const existingTypeParamSpec = FunctionType.getParamSpecFromArgsKwargs(existingType); const existingTypeParamSpec = FunctionType.getParamSpecFromArgsKwargs(existingType);
const existingTypeWithoutArgsKwargs = FunctionType.cloneRemoveParamSpecArgsKwargs(existingType); const existingTypeWithoutArgsKwargs = FunctionType.cloneRemoveParamSpecArgsKwargs(existingType);
if (existingTypeWithoutArgsKwargs.details.parameters.length === 0 && existingTypeParamSpec) { if (existingTypeWithoutArgsKwargs.shared.parameters.length === 0 && existingTypeParamSpec) {
// If there's an existing entry that matches, that's fine. // If there's an existing entry that matches, that's fine.
if (isTypeSame(existingTypeParamSpec, adjSrcType, {}, recursionCount)) { if (isTypeSame(existingTypeParamSpec, adjSrcType, {}, recursionCount)) {
return; return;
} }
} }
} else { } else {
if (!typeVarContext.isLocked() && typeVarContext.hasSolveForScope(destType.scopeId)) { if (!typeVarContext.isLocked() && typeVarContext.hasSolveForScope(destType.priv.scopeId)) {
signatureContext.setTypeVarType(destType, convertTypeToParamSpecValue(adjSrcType)); signatureContext.setTypeVarType(destType, convertTypeToParamSpecValue(adjSrcType));
} }
return; return;
@ -983,7 +983,7 @@ function assignTypeToParamSpec(
} }
if (updateContextWithNewFunction) { if (updateContextWithNewFunction) {
if (!typeVarContext.isLocked() && typeVarContext.hasSolveForScope(destType.scopeId)) { if (!typeVarContext.isLocked() && typeVarContext.hasSolveForScope(destType.priv.scopeId)) {
signatureContext.setTypeVarType(destType, newFunction); signatureContext.setTypeVarType(destType, newFunction);
} }
return; return;
@ -995,7 +995,7 @@ function assignTypeToParamSpec(
diag?.addMessage( diag?.addMessage(
LocAddendum.typeParamSpec().format({ LocAddendum.typeParamSpec().format({
type: evaluator.printType(adjSrcType), type: evaluator.printType(adjSrcType),
name: destType.details.name, name: destType.shared.name,
}) })
); );
@ -1027,14 +1027,14 @@ export function addConstraintsForExpectedType(
usageOffset: number | undefined = undefined usageOffset: number | undefined = undefined
): boolean { ): boolean {
if (isAny(expectedType)) { if (isAny(expectedType)) {
type.details.typeParameters.forEach((typeParam) => { type.shared.typeParameters.forEach((typeParam) => {
updateTypeVarType(evaluator, typeVarContext, typeParam, expectedType, expectedType); updateTypeVarType(evaluator, typeVarContext, typeParam, expectedType, expectedType);
}); });
return true; return true;
} }
if (isTypeVar(expectedType) && expectedType.details.isSynthesizedSelf && expectedType.details.boundType) { if (isTypeVar(expectedType) && expectedType.shared.isSynthesizedSelf && expectedType.shared.boundType) {
expectedType = expectedType.details.boundType; expectedType = expectedType.shared.boundType;
} }
if (!isClass(expectedType)) { if (!isClass(expectedType)) {
@ -1042,7 +1042,7 @@ export function addConstraintsForExpectedType(
} }
// If the expected type is generic (but not specialized), we can't proceed. // If the expected type is generic (but not specialized), we can't proceed.
const expectedTypeArgs = expectedType.typeArguments; const expectedTypeArgs = expectedType.priv.typeArguments;
if (!expectedTypeArgs) { if (!expectedTypeArgs) {
return evaluator.assignType( return evaluator.assignType(
type, type,
@ -1108,14 +1108,14 @@ export function addConstraintsForExpectedType(
const expectedTypeScopeId = getTypeVarScopeId(expectedType); const expectedTypeScopeId = getTypeVarScopeId(expectedType);
const synthExpectedTypeArgs = ClassType.getTypeParameters(expectedType).map((typeParam, index) => { const synthExpectedTypeArgs = ClassType.getTypeParameters(expectedType).map((typeParam, index) => {
const typeVar = TypeVarType.createInstance(`__dest${index}`); const typeVar = TypeVarType.createInstance(`__dest${index}`);
typeVar.details.isSynthesized = true; typeVar.shared.isSynthesized = true;
if (typeParam.details.isParamSpec) { if (typeParam.shared.isParamSpec) {
typeVar.details.isParamSpec = true; typeVar.shared.isParamSpec = true;
} }
// Use invariance here so we set the narrow and wide values on the TypeVar. // Use invariance here so we set the narrow and wide values on the TypeVar.
typeVar.details.declaredVariance = Variance.Invariant; typeVar.shared.declaredVariance = Variance.Invariant;
typeVar.scopeId = expectedTypeScopeId; typeVar.priv.scopeId = expectedTypeScopeId;
return typeVar; return typeVar;
}); });
const genericExpectedType = ClassType.cloneForSpecialization( const genericExpectedType = ClassType.cloneForSpecialization(
@ -1127,11 +1127,11 @@ export function addConstraintsForExpectedType(
// For each type param in the target type, create a placeholder type variable. // For each type param in the target type, create a placeholder type variable.
const typeArgs = ClassType.getTypeParameters(type).map((typeParam, index) => { const typeArgs = ClassType.getTypeParameters(type).map((typeParam, index) => {
const typeVar = TypeVarType.createInstance(`__source${index}`); const typeVar = TypeVarType.createInstance(`__source${index}`);
typeVar.details.isSynthesized = true; typeVar.shared.isSynthesized = true;
typeVar.details.synthesizedIndex = index; typeVar.shared.synthesizedIndex = index;
typeVar.details.isExemptFromBoundCheck = true; typeVar.shared.isExemptFromBoundCheck = true;
if (typeParam.details.isParamSpec) { if (typeParam.shared.isParamSpec) {
typeVar.details.isParamSpec = true; typeVar.shared.isParamSpec = true;
} }
return TypeVarType.cloneAsInScopePlaceholder(typeVar); return TypeVarType.cloneAsInScopePlaceholder(typeVar);
}); });
@ -1157,18 +1157,18 @@ export function addConstraintsForExpectedType(
// If the resulting type is a union, try to find a matching type var and move // If the resulting type is a union, try to find a matching type var and move
// the remaining subtypes to the "otherSubtypes" array. // the remaining subtypes to the "otherSubtypes" array.
if (synthTypeVar) { if (synthTypeVar) {
if (typeVar.details.isParamSpec && isFunction(synthTypeVar)) { if (typeVar.shared.isParamSpec && isFunction(synthTypeVar)) {
synthTypeVar = convertParamSpecValueToType(synthTypeVar); synthTypeVar = convertParamSpecValueToType(synthTypeVar);
} }
if (isUnion(synthTypeVar)) { if (isUnion(synthTypeVar)) {
let foundSynthTypeVar: TypeVarType | undefined; let foundSynthTypeVar: TypeVarType | undefined;
sortTypes(synthTypeVar.subtypes).forEach((subtype) => { sortTypes(synthTypeVar.priv.subtypes).forEach((subtype) => {
if ( if (
isTypeVar(subtype) && isTypeVar(subtype) &&
subtype.details.isSynthesized && subtype.shared.isSynthesized &&
subtype.details.synthesizedIndex !== undefined && subtype.shared.synthesizedIndex !== undefined &&
!foundSynthTypeVar !foundSynthTypeVar
) { ) {
foundSynthTypeVar = subtype; foundSynthTypeVar = subtype;
@ -1188,11 +1188,11 @@ export function addConstraintsForExpectedType(
if ( if (
synthTypeVar && synthTypeVar &&
isTypeVar(synthTypeVar) && isTypeVar(synthTypeVar) &&
synthTypeVar.details.isSynthesized && synthTypeVar.shared.isSynthesized &&
synthTypeVar.details.synthesizedIndex !== undefined synthTypeVar.shared.synthesizedIndex !== undefined
) { ) {
const targetTypeVar = const targetTypeVar =
ClassType.getTypeParameters(specializedType)[synthTypeVar.details.synthesizedIndex]; ClassType.getTypeParameters(specializedType)[synthTypeVar.shared.synthesizedIndex];
if (index < expectedTypeArgs.length) { if (index < expectedTypeArgs.length) {
let typeArgValue: Type | undefined = transformPossibleRecursiveTypeAlias(expectedTypeArgs[index]); let typeArgValue: Type | undefined = transformPossibleRecursiveTypeAlias(expectedTypeArgs[index]);
@ -1251,9 +1251,9 @@ function widenTypeForVariadicTypeVar(evaluator: TypeEvaluator, type1: Type, type
// If the two unpacked tuples are not the same length, we can't combine them. // If the two unpacked tuples are not the same length, we can't combine them.
if ( if (
!type1.tupleTypeArguments || !type1.priv.tupleTypeArguments ||
!type2.tupleTypeArguments || !type2.priv.tupleTypeArguments ||
type1.tupleTypeArguments.length !== type2.tupleTypeArguments.length type1.priv.tupleTypeArguments.length !== type2.priv.tupleTypeArguments.length
) { ) {
return undefined; return undefined;
} }
@ -1271,12 +1271,12 @@ function widenTypeForVariadicTypeVar(evaluator: TypeEvaluator, type1: Type, type
// If the provided type is an unpacked tuple, this function strips the // If the provided type is an unpacked tuple, this function strips the
// literals from types of the corresponding elements. // literals from types of the corresponding elements.
function stripLiteralValueForUnpackedTuple(evaluator: TypeEvaluator, type: Type): Type { function stripLiteralValueForUnpackedTuple(evaluator: TypeEvaluator, type: Type): Type {
if (!isUnpackedClass(type) || !type.tupleTypeArguments) { if (!isUnpackedClass(type) || !type.priv.tupleTypeArguments) {
return type; return type;
} }
let strippedLiteral = false; let strippedLiteral = false;
const tupleTypeArgs: TupleTypeArgument[] = type.tupleTypeArguments.map((arg) => { const tupleTypeArgs: TupleTypeArgument[] = type.priv.tupleTypeArguments.map((arg) => {
const strippedType = evaluator.stripLiteralValue(arg.type); const strippedType = evaluator.stripLiteralValue(arg.type);
if (strippedType !== arg.type) { if (strippedType !== arg.type) {
@ -1317,7 +1317,7 @@ function logTypeVarSignatureContext(evaluator: TypeEvaluator, context: TypeVarSi
let loggedConstraint = false; let loggedConstraint = false;
context.getTypeVars().forEach((entry) => { context.getTypeVars().forEach((entry) => {
const typeVarName = `${indent}${entry.typeVar.details.name}`; const typeVarName = `${indent}${entry.typeVar.shared.name}`;
const narrowBound = entry.narrowBoundNoLiterals ?? entry.narrowBound; const narrowBound = entry.narrowBoundNoLiterals ?? entry.narrowBound;
const wideBound = entry.wideBound; const wideBound = entry.wideBound;

View File

@ -46,7 +46,7 @@ import {
import { TypeVarContext } from './typeVarContext'; import { TypeVarContext } from './typeVarContext';
export function hasConstructorTransform(classType: ClassType): boolean { export function hasConstructorTransform(classType: ClassType): boolean {
if (classType.details.fullName === 'functools.partial') { if (classType.shared.fullName === 'functools.partial') {
return true; return true;
} }
@ -61,7 +61,7 @@ export function applyConstructorTransform(
result: FunctionResult, result: FunctionResult,
signatureTracker: UniqueSignatureTracker | undefined signatureTracker: UniqueSignatureTracker | undefined
): FunctionResult { ): FunctionResult {
if (classType.details.fullName === 'functools.partial') { if (classType.shared.fullName === 'functools.partial') {
return applyPartialTransform(evaluator, errorNode, argList, result, signatureTracker); return applyPartialTransform(evaluator, errorNode, argList, result, signatureTracker);
} }
@ -78,7 +78,7 @@ function applyPartialTransform(
signatureTracker: UniqueSignatureTracker | undefined signatureTracker: UniqueSignatureTracker | undefined
): FunctionResult { ): FunctionResult {
// We assume that the normal return result is a functools.partial class instance. // We assume that the normal return result is a functools.partial class instance.
if (!isClassInstance(result.returnType) || result.returnType.details.fullName !== 'functools.partial') { if (!isClassInstance(result.returnType) || result.returnType.shared.fullName !== 'functools.partial') {
return result; return result;
} }
@ -88,7 +88,7 @@ function applyPartialTransform(
} }
const callMemberType = evaluator.getTypeOfMember(callMemberResult); const callMemberType = evaluator.getTypeOfMember(callMemberResult);
if (!isFunction(callMemberType) || callMemberType.details.parameters.length < 1) { if (!isFunction(callMemberType) || callMemberType.shared.parameters.length < 1) {
return result; return result;
} }
@ -180,7 +180,7 @@ function applyPartialTransform(
evaluator.addDiagnostic( evaluator.addDiagnostic(
DiagnosticRule.reportCallIssue, DiagnosticRule.reportCallIssue,
LocMessage.noOverload().format({ LocMessage.noOverload().format({
name: origFunctionType.overloads[0].details.name, name: origFunctionType.priv.overloads[0].shared.name,
}), }),
errorNode errorNode
); );
@ -199,7 +199,7 @@ function applyPartialTransform(
synthesizedCallType = OverloadedFunctionType.create( synthesizedCallType = OverloadedFunctionType.create(
// Set the "overloaded" flag for each of the __call__ overloads. // Set the "overloaded" flag for each of the __call__ overloads.
applicableOverloads.map((overload) => applicableOverloads.map((overload) =>
FunctionType.cloneWithNewFlags(overload, overload.details.flags | FunctionTypeFlags.Overloaded) FunctionType.cloneWithNewFlags(overload, overload.shared.flags | FunctionTypeFlags.Overloaded)
) )
); );
} }
@ -269,7 +269,7 @@ function applyPartialTransformToFunction(
LocMessage.argAssignmentParamFunction().format({ LocMessage.argAssignmentParamFunction().format({
argType: evaluator.printType(argTypeResult.type), argType: evaluator.printType(argTypeResult.type),
paramType: evaluator.printType(paramType), paramType: evaluator.printType(paramType),
functionName: origFunctionType.details.name, functionName: origFunctionType.shared.name,
paramName: paramListDetails.params[paramListDetails.argsIndex].param.name ?? '', paramName: paramListDetails.params[paramListDetails.argsIndex].param.name ?? '',
}), }),
arg.valueExpression ?? errorNode arg.valueExpression ?? errorNode
@ -315,7 +315,7 @@ function applyPartialTransformToFunction(
LocMessage.argAssignmentParamFunction().format({ LocMessage.argAssignmentParamFunction().format({
argType: evaluator.printType(argTypeResult.type), argType: evaluator.printType(argTypeResult.type),
paramType: evaluator.printType(paramType), paramType: evaluator.printType(paramType),
functionName: origFunctionType.details.name, functionName: origFunctionType.shared.name,
paramName, paramName,
}), }),
arg.valueExpression ?? errorNode arg.valueExpression ?? errorNode
@ -364,7 +364,7 @@ function applyPartialTransformToFunction(
LocMessage.argAssignmentParamFunction().format({ LocMessage.argAssignmentParamFunction().format({
argType: evaluator.printType(argTypeResult.type), argType: evaluator.printType(argTypeResult.type),
paramType: evaluator.printType(paramType), paramType: evaluator.printType(paramType),
functionName: origFunctionType.details.name, functionName: origFunctionType.shared.name,
paramName: paramListDetails.params[paramListDetails.kwargsIndex].param.name ?? '', paramName: paramListDetails.params[paramListDetails.kwargsIndex].param.name ?? '',
}), }),
arg.valueExpression ?? errorNode arg.valueExpression ?? errorNode
@ -404,7 +404,7 @@ function applyPartialTransformToFunction(
LocMessage.argAssignmentParamFunction().format({ LocMessage.argAssignmentParamFunction().format({
argType: evaluator.printType(argTypeResult.type), argType: evaluator.printType(argTypeResult.type),
paramType: evaluator.printType(paramType), paramType: evaluator.printType(paramType),
functionName: origFunctionType.details.name, functionName: origFunctionType.shared.name,
paramName, paramName,
}), }),
arg.valueExpression ?? errorNode arg.valueExpression ?? errorNode
@ -426,7 +426,7 @@ function applyPartialTransformToFunction(
// Create a new parameter list that omits parameters that have been // Create a new parameter list that omits parameters that have been
// populated already. // populated already.
const updatedParamList: FunctionParam[] = specializedFunctionType.details.parameters.map((param, index) => { const updatedParamList: FunctionParam[] = specializedFunctionType.shared.parameters.map((param, index) => {
const specializedParam: FunctionParam = { ...param }; const specializedParam: FunctionParam = { ...param };
specializedParam.type = FunctionType.getEffectiveParameterType(specializedFunctionType, index); specializedParam.type = FunctionType.getEffectiveParameterType(specializedFunctionType, index);
@ -460,25 +460,25 @@ function applyPartialTransformToFunction(
// Create a new __call__ method that uses the remaining parameters. // Create a new __call__ method that uses the remaining parameters.
const newCallMemberType = FunctionType.createInstance( const newCallMemberType = FunctionType.createInstance(
partialCallMemberType.details.name, partialCallMemberType.shared.name,
partialCallMemberType.details.fullName, partialCallMemberType.shared.fullName,
partialCallMemberType.details.moduleName, partialCallMemberType.shared.moduleName,
partialCallMemberType.details.flags, partialCallMemberType.shared.flags,
specializedFunctionType.details.docString specializedFunctionType.shared.docString
); );
if (partialCallMemberType.details.parameters.length > 0) { if (partialCallMemberType.shared.parameters.length > 0) {
FunctionType.addParameter(newCallMemberType, partialCallMemberType.details.parameters[0]); FunctionType.addParameter(newCallMemberType, partialCallMemberType.shared.parameters[0]);
} }
newParamList.forEach((param) => { newParamList.forEach((param) => {
FunctionType.addParameter(newCallMemberType, param); FunctionType.addParameter(newCallMemberType, param);
}); });
newCallMemberType.details.declaredReturnType = specializedFunctionType.details.declaredReturnType newCallMemberType.shared.declaredReturnType = specializedFunctionType.shared.declaredReturnType
? FunctionType.getEffectiveReturnType(specializedFunctionType) ? FunctionType.getEffectiveReturnType(specializedFunctionType)
: specializedFunctionType.inferredReturnType; : specializedFunctionType.priv.inferredReturnType;
newCallMemberType.details.declaration = partialCallMemberType.details.declaration; newCallMemberType.shared.declaration = partialCallMemberType.shared.declaration;
newCallMemberType.details.typeVarScopeId = specializedFunctionType.details.typeVarScopeId; newCallMemberType.shared.typeVarScopeId = specializedFunctionType.shared.typeVarScopeId;
return { returnType: newCallMemberType, isTypeIncomplete: false, argumentErrors }; return { returnType: newCallMemberType, isTypeIncomplete: false, argumentErrors };
} }

View File

@ -324,8 +324,8 @@ function validateNewAndInitMethods(
// type and rely on the __init__ method to supply the type arguments instead. // type and rely on the __init__ method to supply the type arguments instead.
let initMethodBindToType = newMethodReturnType; let initMethodBindToType = newMethodReturnType;
if ( if (
initMethodBindToType.typeArguments && initMethodBindToType.priv.typeArguments &&
initMethodBindToType.typeArguments.some((typeArg) => isUnknown(typeArg)) initMethodBindToType.priv.typeArguments.some((typeArg) => isUnknown(typeArg))
) { ) {
initMethodBindToType = ClassType.cloneAsInstance(type); initMethodBindToType = ClassType.cloneAsInstance(type);
} }
@ -479,10 +479,10 @@ function validateNewMethod(
if (newReturnType) { if (newReturnType) {
// Special-case the 'tuple' type specialization to use the homogenous // Special-case the 'tuple' type specialization to use the homogenous
// arbitrary-length form. // arbitrary-length form.
if (isClassInstance(newReturnType) && isTupleClass(newReturnType) && !newReturnType.tupleTypeArguments) { if (isClassInstance(newReturnType) && isTupleClass(newReturnType) && !newReturnType.priv.tupleTypeArguments) {
if (newReturnType.typeArguments && newReturnType.typeArguments.length === 1) { if (newReturnType.priv.typeArguments && newReturnType.priv.typeArguments.length === 1) {
newReturnType = specializeTupleClass(newReturnType, [ newReturnType = specializeTupleClass(newReturnType, [
{ type: newReturnType.typeArguments[0], isUnbounded: true }, { type: newReturnType.priv.typeArguments[0], isUnbounded: true },
]); ]);
} }
@ -539,7 +539,7 @@ function validateInitMethod(
if ( if (
isClassInstance(expectedSubType) && isClassInstance(expectedSubType) &&
ClassType.isSameGenericClass(type, expectedSubType) && ClassType.isSameGenericClass(type, expectedSubType) &&
type.typeArguments type.priv.typeArguments
) { ) {
return undefined; return undefined;
} }
@ -617,7 +617,7 @@ function validateInitMethod(
} }
if (!returnType) { if (!returnType) {
const typeVarContext = type.typeArguments const typeVarContext = type.priv.typeArguments
? buildTypeVarContextFromSpecializedClass(type) ? buildTypeVarContextFromSpecializedClass(type)
: new TypeVarContext(getTypeVarScopeId(type)); : new TypeVarContext(getTypeVarScopeId(type));
@ -675,13 +675,13 @@ function validateFallbackConstructorCall(
if (argList.length > 0 && argList.some((arg) => arg.argumentCategory === ArgumentCategory.Simple)) { if (argList.length > 0 && argList.some((arg) => arg.argumentCategory === ArgumentCategory.Simple)) {
evaluator.addDiagnostic( evaluator.addDiagnostic(
DiagnosticRule.reportCallIssue, DiagnosticRule.reportCallIssue,
LocMessage.constructorNoArgs().format({ type: type.aliasName || type.details.name }), LocMessage.constructorNoArgs().format({ type: type.priv.aliasName || type.shared.name }),
errorNode errorNode
); );
reportedErrors = true; reportedErrors = true;
} }
if (!inferenceContext && type.typeArguments) { if (!inferenceContext && type.priv.typeArguments) {
// If there was no expected type but the type was already specialized, // If there was no expected type but the type was already specialized,
// assume that we're constructing an instance of the specialized type. // assume that we're constructing an instance of the specialized type.
return { return {
@ -760,7 +760,7 @@ function validateMetaclassCall(
// If the return type is unannotated, don't use the inferred return type. // If the return type is unannotated, don't use the inferred return type.
const callType = metaclassCallMethodInfo.type; const callType = metaclassCallMethodInfo.type;
if (isFunction(callType) && !callType.details.declaredReturnType) { if (isFunction(callType) && !callType.shared.declaredReturnType) {
return undefined; return undefined;
} }
@ -806,7 +806,7 @@ function applyExpectedTypeForConstructor(
// If this isn't a generic type or it's a type that has already been // If this isn't a generic type or it's a type that has already been
// explicitly specialized, the expected type isn't applicable. // explicitly specialized, the expected type isn't applicable.
if (type.details.typeParameters.length === 0 || type.typeArguments) { if (type.shared.typeParameters.length === 0 || type.priv.typeArguments) {
return applySolvedTypeVars(ClassType.cloneAsInstance(type), typeVarContext, { applyInScopePlaceholders: true }); return applySolvedTypeVars(ClassType.cloneAsInstance(type), typeVarContext, { applyInScopePlaceholders: true });
} }
@ -822,7 +822,7 @@ function applyExpectedTypeForConstructor(
// If the expected type didn't provide TypeVar values, remaining // If the expected type didn't provide TypeVar values, remaining
// unsolved TypeVars should be considered Unknown unless they were // unsolved TypeVars should be considered Unknown unless they were
// provided explicitly in the constructor call. // provided explicitly in the constructor call.
if (type.typeArguments) { if (type.priv.typeArguments) {
unsolvedTypeVarsAreUnknown = false; unsolvedTypeVarsAreUnknown = false;
} }
} }
@ -843,9 +843,9 @@ function applyExpectedTypeForTupleConstructor(type: ClassType, inferenceContext:
inferenceContext && inferenceContext &&
isClassInstance(inferenceContext.expectedType) && isClassInstance(inferenceContext.expectedType) &&
isTupleClass(inferenceContext.expectedType) && isTupleClass(inferenceContext.expectedType) &&
inferenceContext.expectedType.tupleTypeArguments inferenceContext.expectedType.priv.tupleTypeArguments
) { ) {
specializedType = specializeTupleClass(type, inferenceContext.expectedType.tupleTypeArguments); specializedType = specializeTupleClass(type, inferenceContext.expectedType.priv.tupleTypeArguments);
} }
return specializedType; return specializedType;
@ -901,7 +901,7 @@ function createFunctionFromMetaclassCall(
classType: ClassType, classType: ClassType,
recursionCount: number recursionCount: number
): FunctionType | OverloadedFunctionType | undefined { ): FunctionType | OverloadedFunctionType | undefined {
const metaclass = classType.details.effectiveMetaclass; const metaclass = classType.shared.effectiveMetaclass;
if (!metaclass || !isClass(metaclass)) { if (!metaclass || !isClass(metaclass)) {
return undefined; return undefined;
} }
@ -943,7 +943,7 @@ function createFunctionFromMetaclassCall(
// any of them returns something other than the instance of the class being // any of them returns something other than the instance of the class being
// constructed. // constructed.
doForEachSignature(boundCallType, (signature) => { doForEachSignature(boundCallType, (signature) => {
if (signature.details.declaredReturnType) { if (signature.shared.declaredReturnType) {
const returnType = FunctionType.getEffectiveReturnType(signature); const returnType = FunctionType.getEffectiveReturnType(signature);
if (returnType && shouldSkipNewAndInitEvaluation(evaluator, classType, returnType)) { if (returnType && shouldSkipNewAndInitEvaluation(evaluator, classType, returnType)) {
useMetaclassCall = true; useMetaclassCall = true;
@ -978,14 +978,14 @@ function createFunctionFromNewMethod(
// If there are no parameters that include class-scoped type parameters, // If there are no parameters that include class-scoped type parameters,
// self-specialize the class because the type arguments for the class // self-specialize the class because the type arguments for the class
// can't be solved if there are no parameters to supply them. // can't be solved if there are no parameters to supply them.
const hasParametersWithTypeVars = newSubtype.details.parameters.some((param, index) => { const hasParametersWithTypeVars = newSubtype.shared.parameters.some((param, index) => {
if (index === 0 || !param.name) { if (index === 0 || !param.name) {
return false; return false;
} }
const paramType = FunctionType.getEffectiveParameterType(newSubtype, index); const paramType = FunctionType.getEffectiveParameterType(newSubtype, index);
const typeVars = getTypeVarArgumentsRecursive(paramType); const typeVars = getTypeVarArgumentsRecursive(paramType);
return typeVars.some((typeVar) => typeVar.scopeId === getTypeVarScopeId(classType)); return typeVars.some((typeVar) => typeVar.priv.scopeId === getTypeVarScopeId(classType));
}); });
const boundNew = evaluator.bindFunctionToClassOrObject( const boundNew = evaluator.bindFunctionToClassOrObject(
@ -1003,14 +1003,14 @@ function createFunctionFromNewMethod(
} }
const convertedNew = FunctionType.clone(boundNew); const convertedNew = FunctionType.clone(boundNew);
convertedNew.details.typeVarScopeId = newSubtype.details.typeVarScopeId; convertedNew.shared.typeVarScopeId = newSubtype.shared.typeVarScopeId;
if (!convertedNew.details.docString && classType.details.docString) { if (!convertedNew.shared.docString && classType.shared.docString) {
convertedNew.details.docString = classType.details.docString; convertedNew.shared.docString = classType.shared.docString;
} }
convertedNew.details.flags &= ~(FunctionTypeFlags.StaticMethod | FunctionTypeFlags.ConstructorMethod); convertedNew.shared.flags &= ~(FunctionTypeFlags.StaticMethod | FunctionTypeFlags.ConstructorMethod);
convertedNew.constructorTypeVarScopeId = getTypeVarScopeId(classType); convertedNew.priv.constructorTypeVarScopeId = getTypeVarScopeId(classType);
return convertedNew; return convertedNew;
}; };
@ -1024,7 +1024,7 @@ function createFunctionFromNewMethod(
} }
const newOverloads: FunctionType[] = []; const newOverloads: FunctionType[] = [];
newType.overloads.forEach((overload) => { newType.priv.overloads.forEach((overload) => {
const converted = convertNewToConstructor(overload); const converted = convertNewToConstructor(overload);
if (converted) { if (converted) {
newOverloads.push(converted); newOverloads.push(converted);
@ -1045,16 +1045,16 @@ function createFunctionFromNewMethod(
function createFunctionFromObjectNewMethod(classType: ClassType) { function createFunctionFromObjectNewMethod(classType: ClassType) {
// Return a fallback constructor based on the object.__new__ method. // Return a fallback constructor based on the object.__new__ method.
const constructorFunction = FunctionType.createSynthesizedInstance('__new__', FunctionTypeFlags.None); const constructorFunction = FunctionType.createSynthesizedInstance('__new__', FunctionTypeFlags.None);
constructorFunction.details.declaredReturnType = ClassType.cloneAsInstance(classType); constructorFunction.shared.declaredReturnType = ClassType.cloneAsInstance(classType);
// If this is type[T] or a protocol, we don't know what parameters are accepted // If this is type[T] or a protocol, we don't know what parameters are accepted
// by the constructor, so add the default parameters. // by the constructor, so add the default parameters.
if (classType.includeSubclasses || ClassType.isProtocolClass(classType)) { if (classType.priv.includeSubclasses || ClassType.isProtocolClass(classType)) {
FunctionType.addDefaultParameters(constructorFunction); FunctionType.addDefaultParameters(constructorFunction);
} }
if (!constructorFunction.details.docString && classType.details.docString) { if (!constructorFunction.shared.docString && classType.shared.docString) {
constructorFunction.details.docString = classType.details.docString; constructorFunction.shared.docString = classType.shared.docString;
} }
return constructorFunction; return constructorFunction;
@ -1104,14 +1104,14 @@ function createFunctionFromInitMethod(
// If this is a generic type, self-specialize the class (i.e. fill in // If this is a generic type, self-specialize the class (i.e. fill in
// its own type parameters as type arguments). // its own type parameters as type arguments).
if (objectType.details.typeParameters.length > 0 && !objectType.typeArguments) { if (objectType.shared.typeParameters.length > 0 && !objectType.priv.typeArguments) {
const typeVarContext = new TypeVarContext(getTypeVarScopeIds(objectType)); const typeVarContext = new TypeVarContext(getTypeVarScopeIds(objectType));
// If a TypeVar is not used in any of the parameter types, it should take // If a TypeVar is not used in any of the parameter types, it should take
// on its default value (typically Unknown) in the resulting specialized type. // on its default value (typically Unknown) in the resulting specialized type.
const typeVarsInParams: TypeVarType[] = []; const typeVarsInParams: TypeVarType[] = [];
convertedInit.details.parameters.forEach((param, index) => { convertedInit.shared.parameters.forEach((param, index) => {
const paramType = FunctionType.getEffectiveParameterType(convertedInit, index); const paramType = FunctionType.getEffectiveParameterType(convertedInit, index);
addTypeVarsToListIfUnique(typeVarsInParams, getTypeVarArgumentsRecursive(paramType)); addTypeVarsToListIfUnique(typeVarsInParams, getTypeVarArgumentsRecursive(paramType));
}); });
@ -1131,18 +1131,18 @@ function createFunctionFromInitMethod(
} }
} }
convertedInit.details.declaredReturnType = boundInit.strippedFirstParamType ?? returnType; convertedInit.shared.declaredReturnType = boundInit.priv.strippedFirstParamType ?? returnType;
if (convertedInit.specializedTypes) { if (convertedInit.priv.specializedTypes) {
convertedInit.specializedTypes.returnType = returnType; convertedInit.priv.specializedTypes.returnType = returnType;
} }
if (!convertedInit.details.docString && classType.details.docString) { if (!convertedInit.shared.docString && classType.shared.docString) {
convertedInit.details.docString = classType.details.docString; convertedInit.shared.docString = classType.shared.docString;
} }
convertedInit.details.flags &= ~FunctionTypeFlags.StaticMethod; convertedInit.shared.flags &= ~FunctionTypeFlags.StaticMethod;
convertedInit.constructorTypeVarScopeId = getTypeVarScopeId(classType); convertedInit.priv.constructorTypeVarScopeId = getTypeVarScopeId(classType);
return convertedInit; return convertedInit;
} }
@ -1156,7 +1156,7 @@ function createFunctionFromInitMethod(
} }
const initOverloads: FunctionType[] = []; const initOverloads: FunctionType[] = [];
initType.overloads.forEach((overload) => { initType.priv.overloads.forEach((overload) => {
const converted = convertInitToConstructor(overload); const converted = convertInitToConstructor(overload);
if (converted) { if (converted) {
initOverloads.push(converted); initOverloads.push(converted);
@ -1234,7 +1234,7 @@ function isDefaultNewMethod(newMethod?: Type): boolean {
return false; return false;
} }
const params = newMethod.details.parameters; const params = newMethod.shared.parameters;
if (params.length !== 2) { if (params.length !== 2) {
return false; return false;
} }
@ -1243,8 +1243,8 @@ function isDefaultNewMethod(newMethod?: Type): boolean {
return false; return false;
} }
const returnType = newMethod.details.declaredReturnType ?? newMethod.inferredReturnType; const returnType = newMethod.shared.declaredReturnType ?? newMethod.priv.inferredReturnType;
if (!returnType || !isTypeVar(returnType) || !returnType.details.isSynthesizedSelf) { if (!returnType || !isTypeVar(returnType) || !returnType.shared.isSynthesizedSelf) {
return false; return false;
} }

View File

@ -90,9 +90,9 @@ export function synthesizeDataClassMethods(
const classTypeVar = synthesizeTypeVarForSelfCls(classType, /* isClsParam */ true); const classTypeVar = synthesizeTypeVarForSelfCls(classType, /* isClsParam */ true);
const newType = FunctionType.createSynthesizedInstance('__new__', FunctionTypeFlags.ConstructorMethod); const newType = FunctionType.createSynthesizedInstance('__new__', FunctionTypeFlags.ConstructorMethod);
newType.constructorTypeVarScopeId = getTypeVarScopeId(classType); newType.priv.constructorTypeVarScopeId = getTypeVarScopeId(classType);
const initType = FunctionType.createSynthesizedInstance('__init__'); const initType = FunctionType.createSynthesizedInstance('__init__');
initType.constructorTypeVarScopeId = getTypeVarScopeId(classType); initType.priv.constructorTypeVarScopeId = getTypeVarScopeId(classType);
// Generate both a __new__ and an __init__ method. The parameters of the // Generate both a __new__ and an __init__ method. The parameters of the
// __new__ method are based on field definitions for NamedTuple classes, // __new__ method are based on field definitions for NamedTuple classes,
@ -105,7 +105,7 @@ export function synthesizeDataClassMethods(
if (!isNamedTuple) { if (!isNamedTuple) {
FunctionType.addDefaultParameters(newType); FunctionType.addDefaultParameters(newType);
} }
newType.details.declaredReturnType = convertToInstance(classTypeVar); newType.shared.declaredReturnType = convertToInstance(classTypeVar);
const selfParam = FunctionParam.create( const selfParam = FunctionParam.create(
ParameterCategory.Simple, ParameterCategory.Simple,
@ -117,7 +117,7 @@ export function synthesizeDataClassMethods(
if (isNamedTuple) { if (isNamedTuple) {
FunctionType.addDefaultParameters(initType); FunctionType.addDefaultParameters(initType);
} }
initType.details.declaredReturnType = evaluator.getNoneType(); initType.shared.declaredReturnType = evaluator.getNoneType();
// Maintain a list of all dataclass entries (including // Maintain a list of all dataclass entries (including
// those from inherited classes) plus a list of only those // those from inherited classes) plus a list of only those
@ -230,7 +230,7 @@ export function synthesizeDataClassMethods(
!isNamedTuple && !isNamedTuple &&
isDataclassFieldConstructor( isDataclassFieldConstructor(
callType, callType,
classType.details.dataClassBehaviors?.fieldDescriptorNames || [] classType.shared.dataClassBehaviors?.fieldDescriptorNames || []
) )
) { ) {
const initArg = statement.rightExpression.arguments.find((arg) => arg.name?.value === 'init'); const initArg = statement.rightExpression.arguments.find((arg) => arg.name?.value === 'init');
@ -290,7 +290,7 @@ export function synthesizeDataClassMethods(
ClassType.isBuiltIn(valueType, 'str') && ClassType.isBuiltIn(valueType, 'str') &&
isLiteralType(valueType) isLiteralType(valueType)
) { ) {
aliasName = valueType.literalValue as string; aliasName = valueType.priv.literalValue as string;
} }
} }
@ -455,7 +455,7 @@ export function synthesizeDataClassMethods(
if ( if (
isDataclassFieldConstructor( isDataclassFieldConstructor(
callType, callType,
classType.details.dataClassBehaviors?.fieldDescriptorNames || [] classType.shared.dataClassBehaviors?.fieldDescriptorNames || []
) )
) { ) {
evaluator.addDiagnostic( evaluator.addDiagnostic(
@ -469,7 +469,7 @@ export function synthesizeDataClassMethods(
}); });
if (!isNamedTuple) { if (!isNamedTuple) {
classType.details.dataClassEntries = localDataClassEntries; classType.shared.dataClassEntries = localDataClassEntries;
} }
// Now that the dataClassEntries field has been set with a complete list // Now that the dataClassEntries field has been set with a complete list
@ -586,7 +586,7 @@ export function synthesizeDataClassMethods(
operatorMethod, operatorMethod,
FunctionParam.create(ParameterCategory.Simple, paramType, FunctionParamFlags.TypeDeclared, 'other') FunctionParam.create(ParameterCategory.Simple, paramType, FunctionParamFlags.TypeDeclared, 'other')
); );
operatorMethod.details.declaredReturnType = evaluator.getBuiltInObject(node, 'bool'); operatorMethod.shared.declaredReturnType = evaluator.getBuiltInObject(node, 'bool');
// If a method of this name already exists, don't override it. // If a method of this name already exists, don't override it.
if (!symbolTable.get(operator)) { if (!symbolTable.get(operator)) {
symbolTable.set(operator, Symbol.createWithType(SymbolFlags.ClassMember, operatorMethod)); symbolTable.set(operator, Symbol.createWithType(SymbolFlags.ClassMember, operatorMethod));
@ -622,7 +622,7 @@ export function synthesizeDataClassMethods(
if (synthesizeHashFunction) { if (synthesizeHashFunction) {
const hashMethod = FunctionType.createSynthesizedInstance('__hash__'); const hashMethod = FunctionType.createSynthesizedInstance('__hash__');
FunctionType.addParameter(hashMethod, selfParam); FunctionType.addParameter(hashMethod, selfParam);
hashMethod.details.declaredReturnType = evaluator.getBuiltInObject(node, 'int'); hashMethod.shared.declaredReturnType = evaluator.getBuiltInObject(node, 'int');
symbolTable.set( symbolTable.set(
'__hash__', '__hash__',
Symbol.createWithType(SymbolFlags.ClassMember | SymbolFlags.IgnoredForOverrideChecks, hashMethod) Symbol.createWithType(SymbolFlags.ClassMember | SymbolFlags.IgnoredForOverrideChecks, hashMethod)
@ -655,8 +655,8 @@ export function synthesizeDataClassMethods(
); );
} }
if (ClassType.isDataClassGenerateSlots(classType) && classType.details.localSlotsNames === undefined) { if (ClassType.isDataClassGenerateSlots(classType) && classType.shared.localSlotsNames === undefined) {
classType.details.localSlotsNames = localDataClassEntries.map((entry) => entry.name); classType.shared.localSlotsNames = localDataClassEntries.map((entry) => entry.name);
} }
// Should we synthesize a __slots__ symbol? // Should we synthesize a __slots__ symbol?
@ -730,24 +730,24 @@ function getDefaultArgValueForFieldSpecifier(
} }
if (callTarget) { if (callTarget) {
const initParam = callTarget.details.parameters.find((p) => p.name === paramName); const initParam = callTarget.shared.parameters.find((p) => p.name === paramName);
if (initParam) { if (initParam) {
// Is the parameter type a literal bool? // Is the parameter type a literal bool?
if ( if (
FunctionParam.isTypeDeclared(initParam) && FunctionParam.isTypeDeclared(initParam) &&
isClass(initParam.type) && isClass(initParam.type) &&
typeof initParam.type.literalValue === 'boolean' typeof initParam.type.priv.literalValue === 'boolean'
) { ) {
return initParam.type.literalValue; return initParam.type.priv.literalValue;
} }
// Is the default argument value a literal bool? // Is the default argument value a literal bool?
if ( if (
initParam.defaultType && initParam.defaultType &&
isClass(initParam.defaultType) && isClass(initParam.defaultType) &&
typeof initParam.defaultType.literalValue === 'boolean' typeof initParam.defaultType.priv.literalValue === 'boolean'
) { ) {
return initParam.defaultType.literalValue; return initParam.defaultType.priv.literalValue;
} }
} }
} }
@ -775,10 +775,10 @@ function getConverterInputType(
// Create synthesized function of the form Callable[[T], fieldType] which // Create synthesized function of the form Callable[[T], fieldType] which
// will be used to check compatibility of the provided converter. // will be used to check compatibility of the provided converter.
const typeVar = TypeVarType.createInstance('__converterInput'); const typeVar = TypeVarType.createInstance('__converterInput');
typeVar.scopeId = getScopeIdForNode(converterNode); typeVar.priv.scopeId = getScopeIdForNode(converterNode);
const targetFunction = FunctionType.createSynthesizedInstance(''); const targetFunction = FunctionType.createSynthesizedInstance('');
targetFunction.details.typeVarScopeId = typeVar.scopeId; targetFunction.shared.typeVarScopeId = typeVar.priv.scopeId;
targetFunction.details.declaredReturnType = fieldType; targetFunction.shared.declaredReturnType = fieldType;
FunctionType.addParameter( FunctionType.addParameter(
targetFunction, targetFunction,
FunctionParam.create( FunctionParam.create(
@ -808,7 +808,7 @@ function getConverterInputType(
signature = applySolvedTypeVars(signature, returnTypeVarContext) as FunctionType; signature = applySolvedTypeVars(signature, returnTypeVarContext) as FunctionType;
} }
const inputTypeVarContext = new TypeVarContext(typeVar.scopeId); const inputTypeVarContext = new TypeVarContext(typeVar.priv.scopeId);
if (evaluator.assignType(targetFunction, signature, diagAddendum, inputTypeVarContext)) { if (evaluator.assignType(targetFunction, signature, diagAddendum, inputTypeVarContext)) {
const overloadSolution = applySolvedTypeVars(typeVar, inputTypeVarContext, { const overloadSolution = applySolvedTypeVars(typeVar, inputTypeVarContext, {
@ -838,7 +838,7 @@ function getConverterInputType(
evaluator.addDiagnostic( evaluator.addDiagnostic(
DiagnosticRule.reportGeneralTypeIssues, DiagnosticRule.reportGeneralTypeIssues,
LocMessage.dataClassConverterOverloads().format({ LocMessage.dataClassConverterOverloads().format({
funcName: converterType.overloads[0].details.name || '<anonymous function>', funcName: converterType.priv.overloads[0].shared.name || '<anonymous function>',
fieldType: evaluator.printType(fieldType), fieldType: evaluator.printType(fieldType),
fieldName: fieldName, fieldName: fieldName,
}) + diagAddendum.getString(), }) + diagAddendum.getString(),
@ -869,7 +869,7 @@ function getConverterAsFunction(
// choose the first of the two subtypes, which typically corresponds // choose the first of the two subtypes, which typically corresponds
// to the __init__ method (rather than the __new__ method). // to the __init__ method (rather than the __new__ method).
if (isUnion(fromConstructor)) { if (isUnion(fromConstructor)) {
fromConstructor = fromConstructor.subtypes[0]; fromConstructor = fromConstructor.priv.subtypes[0];
} }
if (isFunction(fromConstructor) || isOverloadedFunction(fromConstructor)) { if (isFunction(fromConstructor) || isOverloadedFunction(fromConstructor)) {
@ -908,7 +908,7 @@ function getDescriptorForConverterField(
/* declaredMetaclass */ undefined, /* declaredMetaclass */ undefined,
isInstantiableClass(typeMetaclass) ? typeMetaclass : UnknownType.create() isInstantiableClass(typeMetaclass) ? typeMetaclass : UnknownType.create()
); );
descriptorClass.details.baseClasses.push(evaluator.getBuiltInType(dataclassNode, 'object')); descriptorClass.shared.baseClasses.push(evaluator.getBuiltInType(dataclassNode, 'object'));
computeMroLinearization(descriptorClass); computeMroLinearization(descriptorClass);
const fields = ClassType.getSymbolTable(descriptorClass); const fields = ClassType.getSymbolTable(descriptorClass);
@ -927,7 +927,7 @@ function getDescriptorForConverterField(
setFunction, setFunction,
FunctionParam.create(ParameterCategory.Simple, setType, FunctionParamFlags.TypeDeclared, 'value') FunctionParam.create(ParameterCategory.Simple, setType, FunctionParamFlags.TypeDeclared, 'value')
); );
setFunction.details.declaredReturnType = evaluator.getNoneType(); setFunction.shared.declaredReturnType = evaluator.getNoneType();
const setSymbol = Symbol.createWithType(SymbolFlags.ClassMember, setFunction); const setSymbol = Symbol.createWithType(SymbolFlags.ClassMember, setFunction);
fields.set('__set__', setSymbol); fields.set('__set__', setSymbol);
@ -944,7 +944,7 @@ function getDescriptorForConverterField(
getFunction, getFunction,
FunctionParam.create(ParameterCategory.Simple, AnyType.create(), FunctionParamFlags.TypeDeclared, 'objtype') FunctionParam.create(ParameterCategory.Simple, AnyType.create(), FunctionParamFlags.TypeDeclared, 'objtype')
); );
getFunction.details.declaredReturnType = getType; getFunction.shared.declaredReturnType = getType;
const getSymbol = Symbol.createWithType(SymbolFlags.ClassMember, getFunction); const getSymbol = Symbol.createWithType(SymbolFlags.ClassMember, getFunction);
fields.set('__get__', getSymbol); fields.set('__get__', getSymbol);
@ -1018,11 +1018,11 @@ function isDataclassFieldConstructor(type: Type, fieldDescriptorNames: string[])
let callName: string | undefined; let callName: string | undefined;
if (isFunction(type)) { if (isFunction(type)) {
callName = type.details.fullName; callName = type.shared.fullName;
} else if (isOverloadedFunction(type)) { } else if (isOverloadedFunction(type)) {
callName = type.overloads[0].details.fullName; callName = type.priv.overloads[0].shared.fullName;
} else if (isInstantiableClass(type)) { } else if (isInstantiableClass(type)) {
callName = type.details.fullName; callName = type.shared.fullName;
} }
if (!callName) { if (!callName) {
@ -1153,8 +1153,8 @@ export function validateDataClassTransformDecorator(
if ( if (
!isClassInstance(valueType) || !isClassInstance(valueType) ||
!ClassType.isBuiltIn(valueType, 'tuple') || !ClassType.isBuiltIn(valueType, 'tuple') ||
!valueType.tupleTypeArguments || !valueType.priv.tupleTypeArguments ||
valueType.tupleTypeArguments.some( valueType.priv.tupleTypeArguments.some(
(entry) => (entry) =>
!isInstantiableClass(entry.type) && !isInstantiableClass(entry.type) &&
!isFunction(entry.type) && !isFunction(entry.type) &&
@ -1171,11 +1171,11 @@ export function validateDataClassTransformDecorator(
return; return;
} }
valueType.tupleTypeArguments.forEach((arg) => { valueType.priv.tupleTypeArguments.forEach((arg) => {
if (isInstantiableClass(arg.type) || isFunction(arg.type)) { if (isInstantiableClass(arg.type) || isFunction(arg.type)) {
behaviors.fieldDescriptorNames.push(arg.type.details.fullName); behaviors.fieldDescriptorNames.push(arg.type.shared.fullName);
} else if (isOverloadedFunction(arg.type)) { } else if (isOverloadedFunction(arg.type)) {
behaviors.fieldDescriptorNames.push(arg.type.overloads[0].details.fullName); behaviors.fieldDescriptorNames.push(arg.type.priv.overloads[0].shared.fullName);
} }
}); });
break; break;
@ -1203,19 +1203,20 @@ export function getDataclassDecoratorBehaviors(type: Type): DataClassBehaviors |
// dataclass_transform decorator. If more than one have such a decorator, // dataclass_transform decorator. If more than one have such a decorator,
// only the first one will be honored, as per PEP 681. // only the first one will be honored, as per PEP 681.
functionType = functionType =
type.overloads.find((overload) => !!overload.details.decoratorDataClassBehaviors) ?? type.overloads[0]; type.priv.overloads.find((overload) => !!overload.shared.decoratorDataClassBehaviors) ??
type.priv.overloads[0];
} }
if (!functionType) { if (!functionType) {
return undefined; return undefined;
} }
if (functionType.details.decoratorDataClassBehaviors) { if (functionType.shared.decoratorDataClassBehaviors) {
return functionType.details.decoratorDataClassBehaviors; return functionType.shared.decoratorDataClassBehaviors;
} }
// Is this the built-in dataclass? If so, return the default behaviors. // Is this the built-in dataclass? If so, return the default behaviors.
if (functionType.details.fullName === 'dataclasses.dataclass') { if (functionType.shared.fullName === 'dataclasses.dataclass') {
return { return {
fieldDescriptorNames: ['dataclasses.field', 'dataclasses.Field'], fieldDescriptorNames: ['dataclasses.field', 'dataclasses.Field'],
}; };
@ -1267,16 +1268,16 @@ function applyDataClassBehaviorOverrideValue(
behaviors.frozen = argValue; behaviors.frozen = argValue;
} }
classType.details.baseClasses.forEach((baseClass) => { classType.shared.baseClasses.forEach((baseClass) => {
if (isInstantiableClass(baseClass) && ClassType.isDataClass(baseClass)) { if (isInstantiableClass(baseClass) && ClassType.isDataClass(baseClass)) {
if (ClassType.isDataClassFrozen(baseClass)) { if (ClassType.isDataClassFrozen(baseClass)) {
hasFrozenBaseClass = true; hasFrozenBaseClass = true;
} else if ( } else if (
!baseClass.details.classDataClassTransform && !baseClass.shared.classDataClassTransform &&
!( !(
baseClass.details.declaredMetaclass && baseClass.shared.declaredMetaclass &&
isInstantiableClass(baseClass.details.declaredMetaclass) && isInstantiableClass(baseClass.shared.declaredMetaclass) &&
!!baseClass.details.declaredMetaclass.details.classDataClassTransform !!baseClass.shared.declaredMetaclass.shared.classDataClassTransform
) )
) { ) {
// If this base class is unfrozen and isn't the class that directly // If this base class is unfrozen and isn't the class that directly
@ -1325,7 +1326,7 @@ function applyDataClassBehaviorOverrideValue(
if (argValue === true) { if (argValue === true) {
behaviors.generateSlots = true; behaviors.generateSlots = true;
if (classType.details.localSlotsNames) { if (classType.shared.localSlotsNames) {
evaluator.addDiagnostic( evaluator.addDiagnostic(
DiagnosticRule.reportGeneralTypeIssues, DiagnosticRule.reportGeneralTypeIssues,
LocMessage.dataClassSlotsOverwrite(), LocMessage.dataClassSlotsOverwrite(),
@ -1361,7 +1362,7 @@ export function applyDataClassClassBehaviorOverrides(
// Instead, it comes from the default. // Instead, it comes from the default.
behaviors.frozen = behaviors.frozenDefault; behaviors.frozen = behaviors.frozenDefault;
classType.details.dataClassBehaviors = behaviors; classType.shared.dataClassBehaviors = behaviors;
args.forEach((arg) => { args.forEach((arg) => {
if (arg.valueExpression && arg.name) { if (arg.valueExpression && arg.name) {

View File

@ -123,7 +123,7 @@ export function getFunctionInfoFromDecorators(
} }
} else { } else {
if (ClassType.isBuiltIn(decoratorType, 'deprecated')) { if (ClassType.isBuiltIn(decoratorType, 'deprecated')) {
deprecationMessage = decoratorType.deprecatedInstanceMessage; deprecationMessage = decoratorType.priv.deprecatedInstanceMessage;
} }
} }
} }
@ -159,8 +159,8 @@ export function applyFunctionDecorator(
(isFunction(decoratorType) && FunctionType.isBuiltIn(decoratorType, 'overload')) (isFunction(decoratorType) && FunctionType.isBuiltIn(decoratorType, 'overload'))
) { ) {
if (isFunction(inputFunctionType)) { if (isFunction(inputFunctionType)) {
inputFunctionType.details.flags |= FunctionTypeFlags.Overloaded; inputFunctionType.shared.flags |= FunctionTypeFlags.Overloaded;
undecoratedType.details.flags |= FunctionTypeFlags.Overloaded; undecoratedType.shared.flags |= FunctionTypeFlags.Overloaded;
return inputFunctionType; return inputFunctionType;
} }
} }
@ -173,10 +173,10 @@ export function applyFunctionDecorator(
if (isFunction(decoratorCallType)) { if (isFunction(decoratorCallType)) {
if ( if (
decoratorCallType.details.name === '__dataclass_transform__' || decoratorCallType.shared.name === '__dataclass_transform__' ||
FunctionType.isBuiltIn(decoratorCallType, 'dataclass_transform') FunctionType.isBuiltIn(decoratorCallType, 'dataclass_transform')
) { ) {
undecoratedType.details.decoratorDataClassBehaviors = validateDataClassTransformDecorator( undecoratedType.shared.decoratorDataClassBehaviors = validateDataClassTransformDecorator(
evaluator, evaluator,
decoratorNode.expression decoratorNode.expression
); );
@ -194,7 +194,7 @@ export function applyFunctionDecorator(
} }
if (FunctionType.isBuiltIn(decoratorType, 'type_check_only')) { if (FunctionType.isBuiltIn(decoratorType, 'type_check_only')) {
undecoratedType.details.flags |= FunctionTypeFlags.TypeCheckOnly; undecoratedType.shared.flags |= FunctionTypeFlags.TypeCheckOnly;
return inputFunctionType; return inputFunctionType;
} }
@ -226,25 +226,25 @@ export function applyFunctionDecorator(
} }
} else if (isInstantiableClass(decoratorType)) { } else if (isInstantiableClass(decoratorType)) {
if (ClassType.isBuiltIn(decoratorType)) { if (ClassType.isBuiltIn(decoratorType)) {
switch (decoratorType.details.name) { switch (decoratorType.shared.name) {
case 'classmethod': case 'classmethod':
case 'staticmethod': { case 'staticmethod': {
const requiredFlag = const requiredFlag =
decoratorType.details.name === 'classmethod' decoratorType.shared.name === 'classmethod'
? FunctionTypeFlags.ClassMethod ? FunctionTypeFlags.ClassMethod
: FunctionTypeFlags.StaticMethod; : FunctionTypeFlags.StaticMethod;
// If the function isn't currently a class method or static method // If the function isn't currently a class method or static method
// (which can happen if the function was wrapped in a decorator), // (which can happen if the function was wrapped in a decorator),
// add the appropriate flag. // add the appropriate flag.
if (isFunction(inputFunctionType) && (inputFunctionType.details.flags & requiredFlag) === 0) { if (isFunction(inputFunctionType) && (inputFunctionType.shared.flags & requiredFlag) === 0) {
const newFunction = FunctionType.clone(inputFunctionType); const newFunction = FunctionType.clone(inputFunctionType);
newFunction.details.flags &= ~( newFunction.shared.flags &= ~(
FunctionTypeFlags.ConstructorMethod | FunctionTypeFlags.ConstructorMethod |
FunctionTypeFlags.StaticMethod | FunctionTypeFlags.StaticMethod |
FunctionTypeFlags.ClassMethod FunctionTypeFlags.ClassMethod
); );
newFunction.details.flags |= requiredFlag; newFunction.shared.flags |= requiredFlag;
return newFunction; return newFunction;
} }
@ -279,13 +279,13 @@ export function applyFunctionDecorator(
// Copy the overload flag from the input function type. // Copy the overload flag from the input function type.
if (FunctionType.isOverloaded(inputFunctionType)) { if (FunctionType.isOverloaded(inputFunctionType)) {
returnType.details.flags |= FunctionTypeFlags.Overloaded; returnType.shared.flags |= FunctionTypeFlags.Overloaded;
} }
// Copy the docstrings from the input function type if the // Copy the docstrings from the input function type if the
// decorator didn't have its own docstring. // decorator didn't have its own docstring.
if (!returnType.details.docString) { if (!returnType.shared.docString) {
returnType.details.docString = inputFunctionType.details.docString; returnType.shared.docString = inputFunctionType.shared.docString;
} }
} }
@ -313,10 +313,10 @@ export function applyClassDecorator(
if (isFunction(decoratorCallType)) { if (isFunction(decoratorCallType)) {
if ( if (
decoratorCallType.details.name === '__dataclass_transform__' || decoratorCallType.shared.name === '__dataclass_transform__' ||
FunctionType.isBuiltIn(decoratorCallType, 'dataclass_transform') FunctionType.isBuiltIn(decoratorCallType, 'dataclass_transform')
) { ) {
originalClassType.details.classDataClassTransform = validateDataClassTransformDecorator( originalClassType.shared.classDataClassTransform = validateDataClassTransformDecorator(
evaluator, evaluator,
decoratorNode.expression decoratorNode.expression
); );
@ -338,7 +338,7 @@ export function applyClassDecorator(
} }
} else if (isFunction(decoratorType)) { } else if (isFunction(decoratorType)) {
if (FunctionType.isBuiltIn(decoratorType, 'final')) { if (FunctionType.isBuiltIn(decoratorType, 'final')) {
originalClassType.details.flags |= ClassTypeFlags.Final; originalClassType.shared.flags |= ClassTypeFlags.Final;
// Don't call getTypeOfDecorator for final. We'll hard-code its // Don't call getTypeOfDecorator for final. We'll hard-code its
// behavior because its function definition results in a cyclical // behavior because its function definition results in a cyclical
@ -347,12 +347,12 @@ export function applyClassDecorator(
} }
if (FunctionType.isBuiltIn(decoratorType, 'type_check_only')) { if (FunctionType.isBuiltIn(decoratorType, 'type_check_only')) {
originalClassType.details.flags |= ClassTypeFlags.TypeCheckOnly; originalClassType.shared.flags |= ClassTypeFlags.TypeCheckOnly;
return inputClassType; return inputClassType;
} }
if (FunctionType.isBuiltIn(decoratorType, 'runtime_checkable')) { if (FunctionType.isBuiltIn(decoratorType, 'runtime_checkable')) {
originalClassType.details.flags |= ClassTypeFlags.RuntimeCheckable; originalClassType.shared.flags |= ClassTypeFlags.RuntimeCheckable;
// Don't call getTypeOfDecorator for runtime_checkable. It appears // Don't call getTypeOfDecorator for runtime_checkable. It appears
// frequently in stubs, and it's a waste of time to validate its // frequently in stubs, and it's a waste of time to validate its
@ -382,7 +382,7 @@ export function applyClassDecorator(
} }
} else if (isClassInstance(decoratorType)) { } else if (isClassInstance(decoratorType)) {
if (ClassType.isBuiltIn(decoratorType, 'deprecated')) { if (ClassType.isBuiltIn(decoratorType, 'deprecated')) {
originalClassType.details.deprecatedMessage = decoratorType.deprecatedInstanceMessage; originalClassType.shared.deprecatedMessage = decoratorType.priv.deprecatedInstanceMessage;
return inputClassType; return inputClassType;
} }
} }
@ -438,9 +438,9 @@ function getTypeOfDecorator(evaluator: TypeEvaluator, node: DecoratorNode, funct
// If the return type is a function that has no annotations // If the return type is a function that has no annotations
// and just *args and **kwargs parameters, assume that it // and just *args and **kwargs parameters, assume that it
// preserves the type of the input function. // preserves the type of the input function.
if (isFunction(returnType) && !returnType.details.declaredReturnType) { if (isFunction(returnType) && !returnType.shared.declaredReturnType) {
if ( if (
!returnType.details.parameters.some((param, index) => { !returnType.shared.parameters.some((param, index) => {
// Don't allow * or / separators or params with declared types. // Don't allow * or / separators or params with declared types.
if (!param.name || FunctionParam.isTypeDeclared(param)) { if (!param.name || FunctionParam.isTypeDeclared(param)) {
return true; return true;
@ -465,8 +465,8 @@ function getTypeOfDecorator(evaluator: TypeEvaluator, node: DecoratorNode, funct
if (isPartlyUnknown(returnType)) { if (isPartlyUnknown(returnType)) {
if (isFunction(decoratorTypeResult.type)) { if (isFunction(decoratorTypeResult.type)) {
if ( if (
!decoratorTypeResult.type.details.parameters.find((param) => FunctionParam.isTypeDeclared(param)) && !decoratorTypeResult.type.shared.parameters.find((param) => FunctionParam.isTypeDeclared(param)) &&
decoratorTypeResult.type.details.declaredReturnType === undefined decoratorTypeResult.type.shared.declaredReturnType === undefined
) { ) {
return functionOrClassType; return functionOrClassType;
} }
@ -517,7 +517,7 @@ export function addOverloadsToFunctionType(evaluator: TypeEvaluator, node: Funct
} else if (isOverloadedFunction(prevDeclDeclTypeInfo.decoratedType)) { } else if (isOverloadedFunction(prevDeclDeclTypeInfo.decoratedType)) {
// If the previous declaration was itself an overloaded function, // If the previous declaration was itself an overloaded function,
// copy the entries from it. // copy the entries from it.
appendArray(overloadedTypes, prevDeclDeclTypeInfo.decoratedType.overloads); appendArray(overloadedTypes, prevDeclDeclTypeInfo.decoratedType.priv.overloads);
} }
} }
} }
@ -531,10 +531,10 @@ export function addOverloadsToFunctionType(evaluator: TypeEvaluator, node: Funct
// Apply the implementation's docstring to any overloads that don't // Apply the implementation's docstring to any overloads that don't
// have their own docstrings. // have their own docstrings.
const implementation = overloadedTypes.find((signature) => !FunctionType.isOverloaded(signature)); const implementation = overloadedTypes.find((signature) => !FunctionType.isOverloaded(signature));
if (implementation?.details.docString) { if (implementation?.shared.docString) {
overloadedTypes = overloadedTypes.map((overload) => { overloadedTypes = overloadedTypes.map((overload) => {
if (FunctionType.isOverloaded(overload) && !overload.details.docString) { if (FunctionType.isOverloaded(overload) && !overload.shared.docString) {
return FunctionType.cloneWithDocString(overload, implementation.details.docString); return FunctionType.cloneWithDocString(overload, implementation.shared.docString);
} }
return overload; return overload;
}); });
@ -543,12 +543,12 @@ export function addOverloadsToFunctionType(evaluator: TypeEvaluator, node: Funct
// PEP 702 indicates that if the implementation of an overloaded // PEP 702 indicates that if the implementation of an overloaded
// function is marked deprecated, all of the overloads should be // function is marked deprecated, all of the overloads should be
// treated as deprecated as well. // treated as deprecated as well.
if (implementation && implementation.details.deprecatedMessage !== undefined) { if (implementation && implementation.shared.deprecatedMessage !== undefined) {
overloadedTypes = overloadedTypes.map((overload) => { overloadedTypes = overloadedTypes.map((overload) => {
if (FunctionType.isOverloaded(overload) && overload.details.deprecatedMessage === undefined) { if (FunctionType.isOverloaded(overload) && overload.shared.deprecatedMessage === undefined) {
return FunctionType.cloneWithDeprecatedMessage( return FunctionType.cloneWithDeprecatedMessage(
overload, overload,
implementation.details.deprecatedMessage implementation.shared.deprecatedMessage
); );
} }
return overload; return overload;

View File

@ -39,7 +39,7 @@ import {
// Determines whether the class is an Enum metaclass or a subclass thereof. // Determines whether the class is an Enum metaclass or a subclass thereof.
export function isEnumMetaclass(classType: ClassType) { export function isEnumMetaclass(classType: ClassType) {
return classType.details.mro.some( return classType.shared.mro.some(
(mroClass) => isClass(mroClass) && ClassType.isBuiltIn(mroClass, ['EnumMeta', 'EnumType']) (mroClass) => isClass(mroClass) && ClassType.isBuiltIn(mroClass, ['EnumMeta', 'EnumType'])
); );
} }
@ -97,9 +97,9 @@ export function createEnumType(
ClassTypeFlags.EnumClass | ClassTypeFlags.ValidTypeAliasClass, ClassTypeFlags.EnumClass | ClassTypeFlags.ValidTypeAliasClass,
getTypeSourceId(errorNode), getTypeSourceId(errorNode),
/* declaredMetaclass */ undefined, /* declaredMetaclass */ undefined,
enumClass.details.effectiveMetaclass enumClass.shared.effectiveMetaclass
); );
classType.details.baseClasses.push(enumClass); classType.shared.baseClasses.push(enumClass);
computeMroLinearization(classType); computeMroLinearization(classType);
const classFields = ClassType.getSymbolTable(classType); const classFields = ClassType.getSymbolTable(classType);
@ -152,12 +152,7 @@ export function createEnumType(
const valueType = ClassType.cloneWithLiteral(ClassType.cloneAsInstance(intClassType), index + 1); const valueType = ClassType.cloneWithLiteral(ClassType.cloneAsInstance(intClassType), index + 1);
const enumLiteral = new EnumLiteral( const enumLiteral = new EnumLiteral(classType.shared.fullName, classType.shared.name, entryName, valueType);
classType.details.fullName,
classType.details.name,
entryName,
valueType
);
const newSymbol = Symbol.createWithType( const newSymbol = Symbol.createWithType(
SymbolFlags.ClassMember, SymbolFlags.ClassMember,
@ -225,12 +220,7 @@ export function createEnumType(
const entryName = nameNode.strings[0].value; const entryName = nameNode.strings[0].value;
const enumLiteral = new EnumLiteral( const enumLiteral = new EnumLiteral(classType.shared.fullName, classType.shared.name, entryName, valueType);
classType.details.fullName,
classType.details.name,
entryName,
valueType
);
const newSymbol = Symbol.createWithType( const newSymbol = Symbol.createWithType(
SymbolFlags.ClassMember, SymbolFlags.ClassMember,
@ -265,12 +255,7 @@ export function createEnumType(
} }
const entryName = nameNode.strings[0].value; const entryName = nameNode.strings[0].value;
const enumLiteral = new EnumLiteral( const enumLiteral = new EnumLiteral(classType.shared.fullName, classType.shared.name, entryName, valueType);
classType.details.fullName,
classType.details.name,
entryName,
valueType
);
const newSymbol = Symbol.createWithType( const newSymbol = Symbol.createWithType(
SymbolFlags.ClassMember, SymbolFlags.ClassMember,
@ -391,7 +376,7 @@ export function transformTypeForEnumMember(
aliasedEnumType && aliasedEnumType &&
isClassInstance(aliasedEnumType) && isClassInstance(aliasedEnumType) &&
ClassType.isSameGenericClass(aliasedEnumType, ClassType.cloneAsInstance(memberInfo.classType)) && ClassType.isSameGenericClass(aliasedEnumType, ClassType.cloneAsInstance(memberInfo.classType)) &&
aliasedEnumType.literalValue !== undefined aliasedEnumType.priv.literalValue !== undefined
) { ) {
return aliasedEnumType; return aliasedEnumType;
} }
@ -461,10 +446,10 @@ export function transformTypeForEnumMember(
// Handle the Python 3.11 "enum.member()" and "enum.nonmember()" features. // Handle the Python 3.11 "enum.member()" and "enum.nonmember()" features.
if (assignedType && isClassInstance(assignedType) && ClassType.isBuiltIn(assignedType)) { if (assignedType && isClassInstance(assignedType) && ClassType.isBuiltIn(assignedType)) {
if (assignedType.details.fullName === 'enum.nonmember') { if (assignedType.shared.fullName === 'enum.nonmember') {
const nonMemberType = const nonMemberType =
assignedType.typeArguments && assignedType.typeArguments.length > 0 assignedType.priv.typeArguments && assignedType.priv.typeArguments.length > 0
? assignedType.typeArguments[0] ? assignedType.priv.typeArguments[0]
: UnknownType.create(); : UnknownType.create();
// If the type of the nonmember is declared and the assigned value has // If the type of the nonmember is declared and the assigned value has
@ -476,10 +461,10 @@ export function transformTypeForEnumMember(
return nonMemberType; return nonMemberType;
} }
if (assignedType.details.fullName === 'enum.member') { if (assignedType.shared.fullName === 'enum.member') {
valueType = valueType =
assignedType.typeArguments && assignedType.typeArguments.length > 0 assignedType.priv.typeArguments && assignedType.priv.typeArguments.length > 0
? assignedType.typeArguments[0] ? assignedType.priv.typeArguments[0]
: UnknownType.create(); : UnknownType.create();
isMemberOfEnumeration = true; isMemberOfEnumeration = true;
} }
@ -490,8 +475,8 @@ export function transformTypeForEnumMember(
} }
const enumLiteral = new EnumLiteral( const enumLiteral = new EnumLiteral(
memberInfo.classType.details.fullName, memberInfo.classType.shared.fullName,
memberInfo.classType.details.name, memberInfo.classType.shared.name,
memberName, memberName,
valueType valueType
); );
@ -562,7 +547,7 @@ export function getTypeOfEnumMember(
} }
// Handle the special case of 'name' and 'value' members within an enum. // Handle the special case of 'name' and 'value' members within an enum.
const literalValue = classType.literalValue; const literalValue = classType.priv.literalValue;
if (memberName === 'name' || memberName === '_name_') { if (memberName === 'name' || memberName === '_name_') {
// Does the class explicitly override this member? Or it it using the // Does the class explicitly override this member? Or it it using the
@ -593,7 +578,7 @@ export function getTypeOfEnumMember(
return { return {
type: combineTypes( type: combineTypes(
literalValues.map((literalClass) => { literalValues.map((literalClass) => {
const literalValue = literalClass.literalValue; const literalValue = literalClass.priv.literalValue;
assert(literalValue instanceof EnumLiteral); assert(literalValue instanceof EnumLiteral);
return makeNameType(literalValue); return makeNameType(literalValue);
}) })
@ -620,7 +605,7 @@ export function getTypeOfEnumMember(
// This occurs, for example, in the django TextChoices class. If we // This occurs, for example, in the django TextChoices class. If we
// detect a custom metaclass, we'll use the declared type of _value_ // detect a custom metaclass, we'll use the declared type of _value_
// if it is declared. // if it is declared.
const metaclass = classType.details.effectiveMetaclass; const metaclass = classType.shared.effectiveMetaclass;
if (metaclass && isClass(metaclass) && !ClassType.isBuiltIn(metaclass)) { if (metaclass && isClass(metaclass) && !ClassType.isBuiltIn(metaclass)) {
return { type: valueType ?? AnyType.create(), isIncomplete }; return { type: valueType ?? AnyType.create(), isIncomplete };
} }
@ -664,7 +649,7 @@ export function getTypeOfEnumMember(
return { return {
type: combineTypes( type: combineTypes(
literalValues.map((literalClass) => { literalValues.map((literalClass) => {
const literalValue = literalClass.literalValue; const literalValue = literalClass.priv.literalValue;
assert(literalValue instanceof EnumLiteral); assert(literalValue instanceof EnumLiteral);
return literalValue.itemType; return literalValue.itemType;
}) })
@ -700,8 +685,8 @@ export function getEnumAutoValueType(evaluator: TypeEvaluator, node: ExpressionN
isClass(memberInfo.classType) && isClass(memberInfo.classType) &&
!ClassType.isBuiltIn(memberInfo.classType, 'Enum') !ClassType.isBuiltIn(memberInfo.classType, 'Enum')
) { ) {
if (memberInfo.type.details.declaredReturnType) { if (memberInfo.type.shared.declaredReturnType) {
return memberInfo.type.details.declaredReturnType; return memberInfo.type.shared.declaredReturnType;
} }
} }
} }

View File

@ -34,7 +34,7 @@ export function applyFunctionTransform(
result: FunctionResult result: FunctionResult
): FunctionResult { ): FunctionResult {
if (isFunction(functionType)) { if (isFunction(functionType)) {
if (functionType.details.fullName === 'functools.total_ordering') { if (functionType.shared.fullName === 'functools.total_ordering') {
return applyTotalOrderingTransform(evaluator, errorNode, argList, result); return applyTotalOrderingTransform(evaluator, errorNode, argList, result);
} }
} }
@ -55,7 +55,7 @@ function applyTotalOrderingTransform(
// This function is meant to apply to a concrete instantiable class. // This function is meant to apply to a concrete instantiable class.
const classType = argList[0].typeResult?.type; const classType = argList[0].typeResult?.type;
if (!classType || !isInstantiableClass(classType) || classType.includeSubclasses) { if (!classType || !isInstantiableClass(classType) || classType.priv.includeSubclasses) {
return result; return result;
} }
@ -88,10 +88,10 @@ function applyTotalOrderingTransform(
const firstMemberType = evaluator.getTypeOfMember(firstMemberFound); const firstMemberType = evaluator.getTypeOfMember(firstMemberFound);
if ( if (
isFunction(firstMemberType) && isFunction(firstMemberType) &&
firstMemberType.details.parameters.length >= 2 && firstMemberType.shared.parameters.length >= 2 &&
FunctionParam.isTypeDeclared(firstMemberType.details.parameters[1]) FunctionParam.isTypeDeclared(firstMemberType.shared.parameters[1])
) { ) {
operandType = firstMemberType.details.parameters[1].type; operandType = firstMemberType.shared.parameters[1].type;
} }
// If there was no provided operand type, fall back to object. // If there was no provided operand type, fall back to object.
@ -127,7 +127,7 @@ function applyTotalOrderingTransform(
const methodToAdd = FunctionType.createSynthesizedInstance(methodName); const methodToAdd = FunctionType.createSynthesizedInstance(methodName);
FunctionType.addParameter(methodToAdd, selfParam); FunctionType.addParameter(methodToAdd, selfParam);
FunctionType.addParameter(methodToAdd, objParam); FunctionType.addParameter(methodToAdd, objParam);
methodToAdd.details.declaredReturnType = boolType; methodToAdd.shared.declaredReturnType = boolType;
ClassType.getSymbolTable(classType).set( ClassType.getSymbolTable(classType).set(
methodName, methodName,

View File

@ -108,9 +108,9 @@ export function createNamedTupleType(
isClassInstance(defaultsArgType) && isClassInstance(defaultsArgType) &&
isTupleClass(defaultsArgType) && isTupleClass(defaultsArgType) &&
!isUnboundedTupleClass(defaultsArgType) && !isUnboundedTupleClass(defaultsArgType) &&
defaultsArgType.tupleTypeArguments defaultsArgType.priv.tupleTypeArguments
) { ) {
defaultArgCount = defaultsArgType.tupleTypeArguments.length; defaultArgCount = defaultsArgType.priv.tupleTypeArguments.length;
} else { } else {
defaultArgCount = undefined; defaultArgCount = undefined;
} }
@ -126,10 +126,10 @@ export function createNamedTupleType(
ClassTypeFlags.ReadOnlyInstanceVariables | ClassTypeFlags.ValidTypeAliasClass, ClassTypeFlags.ReadOnlyInstanceVariables | ClassTypeFlags.ValidTypeAliasClass,
ParseTreeUtils.getTypeSourceId(errorNode), ParseTreeUtils.getTypeSourceId(errorNode),
/* declaredMetaclass */ undefined, /* declaredMetaclass */ undefined,
isInstantiableClass(namedTupleType) ? namedTupleType.details.effectiveMetaclass : UnknownType.create() isInstantiableClass(namedTupleType) ? namedTupleType.shared.effectiveMetaclass : UnknownType.create()
); );
classType.details.baseClasses.push(namedTupleType); classType.shared.baseClasses.push(namedTupleType);
classType.details.typeVarScopeId = ParseTreeUtils.getScopeIdForNode(errorNode); classType.shared.typeVarScopeId = ParseTreeUtils.getScopeIdForNode(errorNode);
const classFields = ClassType.getSymbolTable(classType); const classFields = ClassType.getSymbolTable(classType);
classFields.set( classFields.set(
@ -139,12 +139,12 @@ export function createNamedTupleType(
const classTypeVar = synthesizeTypeVarForSelfCls(classType, /* isClsParam */ true); const classTypeVar = synthesizeTypeVarForSelfCls(classType, /* isClsParam */ true);
const constructorType = FunctionType.createSynthesizedInstance('__new__', FunctionTypeFlags.ConstructorMethod); const constructorType = FunctionType.createSynthesizedInstance('__new__', FunctionTypeFlags.ConstructorMethod);
constructorType.details.declaredReturnType = convertToInstance(classTypeVar); constructorType.shared.declaredReturnType = convertToInstance(classTypeVar);
constructorType.constructorTypeVarScopeId = getTypeVarScopeId(classType); constructorType.priv.constructorTypeVarScopeId = getTypeVarScopeId(classType);
if (ParseTreeUtils.isAssignmentToDefaultsFollowingNamedTuple(errorNode)) { if (ParseTreeUtils.isAssignmentToDefaultsFollowingNamedTuple(errorNode)) {
constructorType.details.flags |= FunctionTypeFlags.DisableDefaultChecks; constructorType.shared.flags |= FunctionTypeFlags.DisableDefaultChecks;
} }
constructorType.details.typeVarScopeId = classType.details.typeVarScopeId; constructorType.shared.typeVarScopeId = classType.shared.typeVarScopeId;
FunctionType.addParameter( FunctionType.addParameter(
constructorType, constructorType,
FunctionParam.create(ParameterCategory.Simple, classTypeVar, FunctionParamFlags.TypeDeclared, 'cls') FunctionParam.create(ParameterCategory.Simple, classTypeVar, FunctionParamFlags.TypeDeclared, 'cls')
@ -275,7 +275,7 @@ export function createNamedTupleType(
ClassType.isBuiltIn(nameTypeResult.type, 'str') && ClassType.isBuiltIn(nameTypeResult.type, 'str') &&
isLiteralType(nameTypeResult.type) isLiteralType(nameTypeResult.type)
) { ) {
entryName = nameTypeResult.type.literalValue as string; entryName = nameTypeResult.type.priv.literalValue as string;
if (!entryName) { if (!entryName) {
evaluator.addDiagnostic( evaluator.addDiagnostic(
@ -366,7 +366,7 @@ export function createNamedTupleType(
} }
if (addGenericGetAttribute) { if (addGenericGetAttribute) {
constructorType.details.parameters = []; constructorType.shared.parameters = [];
FunctionType.addDefaultParameters(constructorType); FunctionType.addDefaultParameters(constructorType);
entryTypes.push(AnyType.create(/* isEllipsis */ false)); entryTypes.push(AnyType.create(/* isEllipsis */ false));
entryTypes.push(AnyType.create(/* isEllipsis */ true)); entryTypes.push(AnyType.create(/* isEllipsis */ true));
@ -376,20 +376,20 @@ export function createNamedTupleType(
const initType = FunctionType.createSynthesizedInstance('__init__'); const initType = FunctionType.createSynthesizedInstance('__init__');
FunctionType.addParameter(initType, selfParameter); FunctionType.addParameter(initType, selfParameter);
FunctionType.addDefaultParameters(initType); FunctionType.addDefaultParameters(initType);
initType.details.declaredReturnType = evaluator.getNoneType(); initType.shared.declaredReturnType = evaluator.getNoneType();
initType.constructorTypeVarScopeId = getTypeVarScopeId(classType); initType.priv.constructorTypeVarScopeId = getTypeVarScopeId(classType);
classFields.set('__new__', Symbol.createWithType(SymbolFlags.ClassMember, constructorType)); classFields.set('__new__', Symbol.createWithType(SymbolFlags.ClassMember, constructorType));
classFields.set('__init__', Symbol.createWithType(SymbolFlags.ClassMember, initType)); classFields.set('__init__', Symbol.createWithType(SymbolFlags.ClassMember, initType));
const lenType = FunctionType.createSynthesizedInstance('__len__'); const lenType = FunctionType.createSynthesizedInstance('__len__');
lenType.details.declaredReturnType = evaluator.getBuiltInObject(errorNode, 'int'); lenType.shared.declaredReturnType = evaluator.getBuiltInObject(errorNode, 'int');
FunctionType.addParameter(lenType, selfParameter); FunctionType.addParameter(lenType, selfParameter);
classFields.set('__len__', Symbol.createWithType(SymbolFlags.ClassMember, lenType)); classFields.set('__len__', Symbol.createWithType(SymbolFlags.ClassMember, lenType));
if (addGenericGetAttribute) { if (addGenericGetAttribute) {
const getAttribType = FunctionType.createSynthesizedInstance('__getattribute__'); const getAttribType = FunctionType.createSynthesizedInstance('__getattribute__');
getAttribType.details.declaredReturnType = AnyType.create(); getAttribType.shared.declaredReturnType = AnyType.create();
FunctionType.addParameter(getAttribType, selfParameter); FunctionType.addParameter(getAttribType, selfParameter);
FunctionType.addParameter( FunctionType.addParameter(
getAttribType, getAttribType,
@ -435,7 +435,7 @@ export function updateNamedTupleBaseClass(
): boolean { ): boolean {
let isUpdateNeeded = false; let isUpdateNeeded = false;
classType.details.baseClasses = classType.details.baseClasses.map((baseClass) => { classType.shared.baseClasses = classType.shared.baseClasses.map((baseClass) => {
if (!isInstantiableClass(baseClass) || !ClassType.isBuiltIn(baseClass, 'NamedTuple')) { if (!isInstantiableClass(baseClass) || !ClassType.isBuiltIn(baseClass, 'NamedTuple')) {
return baseClass; return baseClass;
} }
@ -459,9 +459,9 @@ export function updateNamedTupleBaseClass(
/* typeArguments */ undefined, /* typeArguments */ undefined,
isTypeArgumentExplicit isTypeArgumentExplicit
); );
clonedNamedTupleClass.details = { ...clonedNamedTupleClass.details }; clonedNamedTupleClass.shared = { ...clonedNamedTupleClass.shared };
clonedNamedTupleClass.details.baseClasses = clonedNamedTupleClass.details.baseClasses.map( clonedNamedTupleClass.shared.baseClasses = clonedNamedTupleClass.shared.baseClasses.map(
(namedTupleBaseClass) => { (namedTupleBaseClass) => {
if (!isInstantiableClass(namedTupleBaseClass) || !ClassType.isBuiltIn(namedTupleBaseClass, 'tuple')) { if (!isInstantiableClass(namedTupleBaseClass) || !ClassType.isBuiltIn(namedTupleBaseClass, 'tuple')) {
return namedTupleBaseClass; return namedTupleBaseClass;

View File

@ -271,8 +271,8 @@ export function validateBinaryOperation(
return ClassType.cloneWithLiteral( return ClassType.cloneWithLiteral(
leftClassSubtype, leftClassSubtype,
((leftClassSubtype.literalValue as string) + ((leftClassSubtype.priv.literalValue as string) +
rightClassSubtype.literalValue) as string rightClassSubtype.priv.literalValue) as string
); );
}); });
}); });
@ -293,10 +293,10 @@ export function validateBinaryOperation(
const leftClassSubtype = leftSubtype as ClassType; const leftClassSubtype = leftSubtype as ClassType;
const rightClassSubtype = rightSubtype as ClassType; const rightClassSubtype = rightSubtype as ClassType;
const leftLiteralValue = BigInt( const leftLiteralValue = BigInt(
leftClassSubtype.literalValue as number | bigint leftClassSubtype.priv.literalValue as number | bigint
); );
const rightLiteralValue = BigInt( const rightLiteralValue = BigInt(
rightClassSubtype.literalValue as number | bigint rightClassSubtype.priv.literalValue as number | bigint
); );
let newValue: number | bigint | undefined; let newValue: number | bigint | undefined;
@ -371,10 +371,10 @@ export function validateBinaryOperation(
operator === OperatorType.Add && operator === OperatorType.Add &&
isClassInstance(leftSubtypeExpanded) && isClassInstance(leftSubtypeExpanded) &&
isTupleClass(leftSubtypeExpanded) && isTupleClass(leftSubtypeExpanded) &&
leftSubtypeExpanded.tupleTypeArguments && leftSubtypeExpanded.priv.tupleTypeArguments &&
isClassInstance(rightSubtypeExpanded) && isClassInstance(rightSubtypeExpanded) &&
isTupleClass(rightSubtypeExpanded) && isTupleClass(rightSubtypeExpanded) &&
rightSubtypeExpanded.tupleTypeArguments && rightSubtypeExpanded.priv.tupleTypeArguments &&
tupleClassType && tupleClassType &&
isInstantiableClass(tupleClassType) isInstantiableClass(tupleClassType)
) { ) {
@ -389,8 +389,8 @@ export function validateBinaryOperation(
) { ) {
return ClassType.cloneAsInstance( return ClassType.cloneAsInstance(
specializeTupleClass(tupleClassType, [ specializeTupleClass(tupleClassType, [
...leftSubtypeExpanded.tupleTypeArguments, ...leftSubtypeExpanded.priv.tupleTypeArguments,
...rightSubtypeExpanded.tupleTypeArguments, ...rightSubtypeExpanded.priv.tupleTypeArguments,
]) ])
); );
} }
@ -543,8 +543,8 @@ export function getTypeOfBinaryOperation(
inferenceContext && inferenceContext &&
isClassInstance(inferenceContext.expectedType) && isClassInstance(inferenceContext.expectedType) &&
ClassType.isBuiltIn(inferenceContext.expectedType, 'list') && ClassType.isBuiltIn(inferenceContext.expectedType, 'list') &&
inferenceContext.expectedType.typeArguments && inferenceContext.expectedType.priv.typeArguments &&
inferenceContext.expectedType.typeArguments.length >= 1 && inferenceContext.expectedType.priv.typeArguments.length >= 1 &&
node.leftExpression.nodeType === ParseNodeType.List node.leftExpression.nodeType === ParseNodeType.List
) { ) {
expectedLeftOperandType = inferenceContext.expectedType; expectedLeftOperandType = inferenceContext.expectedType;
@ -570,7 +570,7 @@ export function getTypeOfBinaryOperation(
return false; return false;
} }
return ClassType.isTypedDictClass(subtype) || subtype.details.typeParameters.length > 0; return ClassType.isTypedDictClass(subtype) || subtype.shared.typeParameters.length > 0;
}) })
) { ) {
expectedOperandType = leftType; expectedOperandType = leftType;
@ -684,7 +684,7 @@ export function getTypeOfBinaryOperation(
if (stringNode && otherNode && otherType) { if (stringNode && otherNode && otherType) {
let isAllowed = true; let isAllowed = true;
if (isClass(otherType)) { if (isClass(otherType)) {
if (!otherType.isTypeArgumentExplicit || isClassInstance(otherType)) { if (!otherType.priv.isTypeArgumentExplicit || isClassInstance(otherType)) {
isAllowed = false; isAllowed = false;
} }
} }
@ -999,14 +999,17 @@ export function getTypeOfUnaryOperation(
} else if (node.operator === OperatorType.Subtract) { } else if (node.operator === OperatorType.Subtract) {
type = mapSubtypes(exprType, (subtype) => { type = mapSubtypes(exprType, (subtype) => {
const classSubtype = subtype as ClassType; const classSubtype = subtype as ClassType;
return ClassType.cloneWithLiteral(classSubtype, -(classSubtype.literalValue as number | bigint)); return ClassType.cloneWithLiteral(
classSubtype,
-(classSubtype.priv.literalValue as number | bigint)
);
}); });
} }
} else if (literalClassName === 'bool') { } else if (literalClassName === 'bool') {
if (node.operator === OperatorType.Not) { if (node.operator === OperatorType.Not) {
type = mapSubtypes(exprType, (subtype) => { type = mapSubtypes(exprType, (subtype) => {
const classSubtype = subtype as ClassType; const classSubtype = subtype as ClassType;
return ClassType.cloneWithLiteral(classSubtype, !(classSubtype.literalValue as boolean)); return ClassType.cloneWithLiteral(classSubtype, !(classSubtype.priv.literalValue as boolean));
}); });
} }
} }
@ -1134,7 +1137,7 @@ function customMetaclassSupportsMethod(type: Type, methodName: string): boolean
return false; return false;
} }
const metaclass = type.details.effectiveMetaclass; const metaclass = type.shared.effectiveMetaclass;
if (!metaclass || !isInstantiableClass(metaclass)) { if (!metaclass || !isInstantiableClass(metaclass)) {
return false; return false;
} }

View File

@ -680,7 +680,7 @@ export class PackageTypeVerifier {
} }
private _reportMissingClassDocstring(symbolInfo: SymbolInfo, type: ClassType, report: PackageTypeReport) { private _reportMissingClassDocstring(symbolInfo: SymbolInfo, type: ClassType, report: PackageTypeReport) {
if (type.details.docString) { if (type.shared.docString) {
return; return;
} }
@ -701,7 +701,7 @@ export class PackageTypeVerifier {
declFileUri: Uri | undefined, declFileUri: Uri | undefined,
report: PackageTypeReport report: PackageTypeReport
) { ) {
if (type.details.parameters.find((param) => param.defaultType && isEllipsisType(param.defaultType))) { if (type.shared.parameters.find((param) => param.defaultType && isEllipsisType(param.defaultType))) {
if (symbolInfo) { if (symbolInfo) {
this._addSymbolWarning( this._addSymbolWarning(
symbolInfo, symbolInfo,
@ -714,7 +714,7 @@ export class PackageTypeVerifier {
report.missingDefaultParamCount++; report.missingDefaultParamCount++;
} }
if (type.details.docString) { if (type.shared.docString) {
return; return;
} }
@ -827,7 +827,7 @@ export class PackageTypeVerifier {
} }
case TypeCategory.OverloadedFunction: { case TypeCategory.OverloadedFunction: {
for (const overload of type.overloads) { for (const overload of type.priv.overloads) {
knownStatus = this._updateKnownStatusIfWorse( knownStatus = this._updateKnownStatusIfWorse(
knownStatus, knownStatus,
this._getSymbolTypeKnownStatus( this._getSymbolTypeKnownStatus(
@ -844,7 +844,7 @@ export class PackageTypeVerifier {
} }
case TypeCategory.Function: { case TypeCategory.Function: {
if (!this._shouldIgnoreType(report, type.details.fullName)) { if (!this._shouldIgnoreType(report, type.shared.fullName)) {
knownStatus = this._updateKnownStatusIfWorse( knownStatus = this._updateKnownStatusIfWorse(
knownStatus, knownStatus,
this._getFunctionTypeKnownStatus( this._getFunctionTypeKnownStatus(
@ -866,9 +866,9 @@ export class PackageTypeVerifier {
// Properties require special handling. // Properties require special handling.
if (TypeBase.isInstance(type) && ClassType.isPropertyClass(type)) { if (TypeBase.isInstance(type) && ClassType.isPropertyClass(type)) {
const propMethodInfo: [string, (c: ClassType) => FunctionType | undefined][] = [ const propMethodInfo: [string, (c: ClassType) => FunctionType | undefined][] = [
['fget', (c) => c.fgetInfo?.methodType], ['fget', (c) => c.priv.fgetInfo?.methodType],
['fset', (c) => c.fsetInfo?.methodType], ['fset', (c) => c.priv.fsetInfo?.methodType],
['fdel', (c) => c.fdelInfo?.methodType], ['fdel', (c) => c.priv.fdelInfo?.methodType],
]; ];
const propertyClass = type; const propertyClass = type;
@ -888,7 +888,7 @@ export class PackageTypeVerifier {
// static. Otherwise we'll incorrectly report that "self" is not annotated. // static. Otherwise we'll incorrectly report that "self" is not annotated.
accessType = FunctionType.cloneWithNewFlags( accessType = FunctionType.cloneWithNewFlags(
accessType, accessType,
accessType.details.flags & ~FunctionTypeFlags.StaticMethod accessType.shared.flags & ~FunctionTypeFlags.StaticMethod
); );
} }
@ -908,7 +908,7 @@ export class PackageTypeVerifier {
break; break;
} }
if (!this._shouldIgnoreType(report, type.details.fullName)) { if (!this._shouldIgnoreType(report, type.shared.fullName)) {
// Don't bother type-checking built-in types. // Don't bother type-checking built-in types.
if (!ClassType.isBuiltIn(type)) { if (!ClassType.isBuiltIn(type)) {
const symbolInfo = this._getSymbolForClass(report, type, publicSymbols); const symbolInfo = this._getSymbolForClass(report, type, publicSymbols);
@ -917,12 +917,12 @@ export class PackageTypeVerifier {
} }
// Analyze type arguments if present to make sure they are known. // Analyze type arguments if present to make sure they are known.
if (type.typeArguments) { if (type.priv.typeArguments) {
type.typeArguments!.forEach((typeArg, index) => { type.priv.typeArguments!.forEach((typeArg, index) => {
if (isUnknown(typeArg)) { if (isUnknown(typeArg)) {
this._addSymbolError( this._addSymbolError(
symbolInfo, symbolInfo,
`Type argument ${index + 1} for class "${type.details.name}" has unknown type`, `Type argument ${index + 1} for class "${type.shared.name}" has unknown type`,
declRange, declRange,
declFileUri declFileUri
); );
@ -933,7 +933,7 @@ export class PackageTypeVerifier {
this._addSymbolError( this._addSymbolError(
symbolInfo, symbolInfo,
`Type argument ${index + 1} for class "${ `Type argument ${index + 1} for class "${
type.details.name type.shared.name
}" has partially unknown type` + diag.getString(), }" has partially unknown type` + diag.getString(),
declRange, declRange,
declFileUri declFileUri
@ -947,7 +947,7 @@ export class PackageTypeVerifier {
} }
case TypeCategory.Module: { case TypeCategory.Module: {
if (!this._shouldIgnoreType(report, type.moduleName)) { if (!this._shouldIgnoreType(report, type.priv.moduleName)) {
const moduleSymbol = this._getSymbolForModule(report, type, publicSymbols); const moduleSymbol = this._getSymbolForModule(report, type, publicSymbols);
if (moduleSymbol.typeKnownStatus !== TypeKnownStatus.Known) { if (moduleSymbol.typeKnownStatus !== TypeKnownStatus.Known) {
this._addSymbolError( this._addSymbolError(
@ -982,11 +982,11 @@ export class PackageTypeVerifier {
let knownStatus = TypeKnownStatus.Known; let knownStatus = TypeKnownStatus.Known;
// If the file path wasn't provided, try to get it from the type. // If the file path wasn't provided, try to get it from the type.
if (type.details.declaration && !declFileUri) { if (type.shared.declaration && !declFileUri) {
declFileUri = type.details.declaration.uri; declFileUri = type.shared.declaration.uri;
} }
type.details.parameters.forEach((param, index) => { type.shared.parameters.forEach((param, index) => {
// Skip nameless parameters like "*" and "/". // Skip nameless parameters like "*" and "/".
if (param.name) { if (param.name) {
if (!FunctionParam.isTypeDeclared(param)) { if (!FunctionParam.isTypeDeclared(param)) {
@ -1055,8 +1055,8 @@ export class PackageTypeVerifier {
} }
}); });
if (type.details.declaredReturnType) { if (type.shared.declaredReturnType) {
if (isUnknown(type.details.declaredReturnType)) { if (isUnknown(type.shared.declaredReturnType)) {
if (symbolInfo) { if (symbolInfo) {
this._addSymbolError( this._addSymbolError(
symbolInfo, symbolInfo,
@ -1070,15 +1070,13 @@ export class PackageTypeVerifier {
const extraInfo = new DiagnosticAddendum(); const extraInfo = new DiagnosticAddendum();
const returnTypeKnownStatus = this._getTypeKnownStatus( const returnTypeKnownStatus = this._getTypeKnownStatus(
report, report,
type.details.declaredReturnType, type.shared.declaredReturnType,
publicSymbols, publicSymbols,
extraInfo.createAddendum() extraInfo.createAddendum()
); );
if (returnTypeKnownStatus !== TypeKnownStatus.Known) { if (returnTypeKnownStatus !== TypeKnownStatus.Known) {
extraInfo.addMessage( extraInfo.addMessage(`Return type is "${this._program.printType(type.shared.declaredReturnType)}"`);
`Return type is "${this._program.printType(type.details.declaredReturnType)}"`
);
if (symbolInfo) { if (symbolInfo) {
this._addSymbolError( this._addSymbolError(
@ -1100,7 +1098,7 @@ export class PackageTypeVerifier {
} }
} else { } else {
// Init methods have an implied return type. // Init methods have an implied return type.
if (type.details.name !== '__init__') { if (type.shared.name !== '__init__') {
if (symbolInfo) { if (symbolInfo) {
this._addSymbolError( this._addSymbolError(
symbolInfo, symbolInfo,
@ -1123,7 +1121,7 @@ export class PackageTypeVerifier {
private _getSymbolForClass(report: PackageTypeReport, type: ClassType, publicSymbols: PublicSymbolSet): SymbolInfo { private _getSymbolForClass(report: PackageTypeReport, type: ClassType, publicSymbols: PublicSymbolSet): SymbolInfo {
// See if this type is already analyzed. // See if this type is already analyzed.
const cachedType = report.symbols.get(type.details.fullName); const cachedType = report.symbols.get(type.shared.fullName);
if (cachedType) { if (cachedType) {
cachedType.referenceCount++; cachedType.referenceCount++;
return cachedType; return cachedType;
@ -1131,10 +1129,10 @@ export class PackageTypeVerifier {
const symbolInfo: SymbolInfo = { const symbolInfo: SymbolInfo = {
category: SymbolCategory.Class, category: SymbolCategory.Class,
name: type.details.name, name: type.shared.name,
fullName: type.details.fullName, fullName: type.shared.fullName,
fileUri: type.details.fileUri, fileUri: type.shared.fileUri,
isExported: publicSymbols.has(type.details.fullName), isExported: publicSymbols.has(type.shared.fullName),
typeKnownStatus: TypeKnownStatus.Known, typeKnownStatus: TypeKnownStatus.Known,
referenceCount: 1, referenceCount: 1,
diagnostics: [], diagnostics: [],
@ -1148,7 +1146,7 @@ export class PackageTypeVerifier {
const symbolTableTypeKnownStatus = this._getTypeKnownStatusForSymbolTable( const symbolTableTypeKnownStatus = this._getTypeKnownStatusForSymbolTable(
report, report,
type.details.fullName, type.shared.fullName,
ClassType.getSymbolTable(type), ClassType.getSymbolTable(type),
ScopeType.Class, ScopeType.Class,
publicSymbols, publicSymbols,
@ -1157,7 +1155,7 @@ export class PackageTypeVerifier {
// see if we can find a same-named symbol in a parent class with // see if we can find a same-named symbol in a parent class with
// a type declaration. // a type declaration.
if (!symbol.hasTypedDeclarations()) { if (!symbol.hasTypedDeclarations()) {
for (const mroClass of type.details.mro.slice(1)) { for (const mroClass of type.shared.mro.slice(1)) {
if (isClass(mroClass)) { if (isClass(mroClass)) {
const overrideSymbol = ClassType.getSymbolTable(mroClass).get(name); const overrideSymbol = ClassType.getSymbolTable(mroClass).get(name);
if (overrideSymbol && overrideSymbol.hasTypedDeclarations()) { if (overrideSymbol && overrideSymbol.hasTypedDeclarations()) {
@ -1177,8 +1175,8 @@ export class PackageTypeVerifier {
); );
// Add information for the metaclass. // Add information for the metaclass.
if (type.details.effectiveMetaclass) { if (type.shared.effectiveMetaclass) {
if (!isInstantiableClass(type.details.effectiveMetaclass)) { if (!isInstantiableClass(type.shared.effectiveMetaclass)) {
this._addSymbolError(symbolInfo, `Type of metaclass unknown`, getEmptyRange(), Uri.empty()); this._addSymbolError(symbolInfo, `Type of metaclass unknown`, getEmptyRange(), Uri.empty());
symbolInfo.typeKnownStatus = this._updateKnownStatusIfWorse( symbolInfo.typeKnownStatus = this._updateKnownStatusIfWorse(
symbolInfo.typeKnownStatus, symbolInfo.typeKnownStatus,
@ -1188,7 +1186,7 @@ export class PackageTypeVerifier {
const diag = new DiagnosticAddendum(); const diag = new DiagnosticAddendum();
const metaclassKnownStatus = this._getTypeKnownStatus( const metaclassKnownStatus = this._getTypeKnownStatus(
report, report,
type.details.effectiveMetaclass, type.shared.effectiveMetaclass,
publicSymbols, publicSymbols,
diag diag
); );
@ -1196,8 +1194,7 @@ export class PackageTypeVerifier {
if (metaclassKnownStatus !== TypeKnownStatus.Known) { if (metaclassKnownStatus !== TypeKnownStatus.Known) {
this._addSymbolError( this._addSymbolError(
symbolInfo, symbolInfo,
`Type of metaclass "${type.details.effectiveMetaclass}" is partially unknown` + `Type of metaclass "${type.shared.effectiveMetaclass}" is partially unknown` + diag.getString(),
diag.getString(),
getEmptyRange(), getEmptyRange(),
Uri.empty() Uri.empty()
); );
@ -1210,7 +1207,7 @@ export class PackageTypeVerifier {
} }
// Add information for base classes. // Add information for base classes.
type.details.baseClasses.forEach((baseClass) => { type.shared.baseClasses.forEach((baseClass) => {
if (!isInstantiableClass(baseClass)) { if (!isInstantiableClass(baseClass)) {
this._addSymbolError(symbolInfo, `Type of base class unknown`, getEmptyRange(), Uri.empty()); this._addSymbolError(symbolInfo, `Type of base class unknown`, getEmptyRange(), Uri.empty());
symbolInfo.typeKnownStatus = this._updateKnownStatusIfWorse( symbolInfo.typeKnownStatus = this._updateKnownStatusIfWorse(
@ -1230,7 +1227,7 @@ export class PackageTypeVerifier {
if (baseClassTypeStatus !== TypeKnownStatus.Known) { if (baseClassTypeStatus !== TypeKnownStatus.Known) {
this._addSymbolError( this._addSymbolError(
symbolInfo, symbolInfo,
`Type of base class "${baseClass.details.fullName}" is partially unknown` + diag.getString(), `Type of base class "${baseClass.shared.fullName}" is partially unknown` + diag.getString(),
getEmptyRange(), getEmptyRange(),
Uri.empty() Uri.empty()
); );
@ -1252,7 +1249,7 @@ export class PackageTypeVerifier {
publicSymbols: PublicSymbolSet publicSymbols: PublicSymbolSet
): SymbolInfo { ): SymbolInfo {
// See if this type is already analyzed. // See if this type is already analyzed.
const cachedType = report.symbols.get(type.moduleName); const cachedType = report.symbols.get(type.priv.moduleName);
if (cachedType) { if (cachedType) {
cachedType.referenceCount++; cachedType.referenceCount++;
return cachedType; return cachedType;
@ -1260,10 +1257,10 @@ export class PackageTypeVerifier {
const symbolInfo: SymbolInfo = { const symbolInfo: SymbolInfo = {
category: SymbolCategory.Module, category: SymbolCategory.Module,
name: type.moduleName, name: type.priv.moduleName,
fullName: type.moduleName, fullName: type.priv.moduleName,
fileUri: type.fileUri, fileUri: type.priv.fileUri,
isExported: publicSymbols.has(type.moduleName), isExported: publicSymbols.has(type.priv.moduleName),
typeKnownStatus: TypeKnownStatus.Known, typeKnownStatus: TypeKnownStatus.Known,
referenceCount: 1, referenceCount: 1,
diagnostics: [], diagnostics: [],
@ -1271,14 +1268,14 @@ export class PackageTypeVerifier {
}; };
// Add the symbol for the module if the name isn't relative. // Add the symbol for the module if the name isn't relative.
if (!type.moduleName.startsWith('.')) { if (!type.priv.moduleName.startsWith('.')) {
this._addSymbol(report, symbolInfo); this._addSymbol(report, symbolInfo);
} }
const symbolTableTypeKnownStatus = this._getTypeKnownStatusForSymbolTable( const symbolTableTypeKnownStatus = this._getTypeKnownStatusForSymbolTable(
report, report,
type.moduleName, type.priv.moduleName,
type.fields, type.priv.fields,
ScopeType.Module, ScopeType.Module,
publicSymbols publicSymbols
); );
@ -1342,7 +1339,7 @@ export class PackageTypeVerifier {
} }
case TypeCategory.OverloadedFunction: { case TypeCategory.OverloadedFunction: {
for (const overload of type.overloads) { for (const overload of type.priv.overloads) {
knownStatus = this._updateKnownStatusIfWorse( knownStatus = this._updateKnownStatusIfWorse(
knownStatus, knownStatus,
this._getTypeKnownStatus(report, overload, publicSymbols, diag.createAddendum()) this._getTypeKnownStatus(report, overload, publicSymbols, diag.createAddendum())
@ -1353,7 +1350,7 @@ export class PackageTypeVerifier {
} }
case TypeCategory.Function: { case TypeCategory.Function: {
if (!this._shouldIgnoreType(report, type.details.fullName)) { if (!this._shouldIgnoreType(report, type.shared.fullName)) {
knownStatus = this._updateKnownStatusIfWorse( knownStatus = this._updateKnownStatusIfWorse(
knownStatus, knownStatus,
this._getFunctionTypeKnownStatus( this._getFunctionTypeKnownStatus(
@ -1372,7 +1369,7 @@ export class PackageTypeVerifier {
} }
case TypeCategory.Class: { case TypeCategory.Class: {
if (!this._shouldIgnoreType(report, type.details.fullName)) { if (!this._shouldIgnoreType(report, type.shared.fullName)) {
// Don't bother type-checking built-in types. // Don't bother type-checking built-in types.
if (!ClassType.isBuiltIn(type)) { if (!ClassType.isBuiltIn(type)) {
const symbolInfo = this._getSymbolForClass(report, type, publicSymbols); const symbolInfo = this._getSymbolForClass(report, type, publicSymbols);
@ -1381,16 +1378,16 @@ export class PackageTypeVerifier {
} }
// Analyze type arguments if present to make sure they are known. // Analyze type arguments if present to make sure they are known.
if (type.typeArguments) { if (type.priv.typeArguments) {
type.typeArguments!.forEach((typeArg, index) => { type.priv.typeArguments!.forEach((typeArg, index) => {
if (isUnknown(typeArg)) { if (isUnknown(typeArg)) {
diag.addMessage( diag.addMessage(
`Type argument ${index + 1} for class "${type.details.name}" has unknown type` `Type argument ${index + 1} for class "${type.shared.name}" has unknown type`
); );
knownStatus = this._updateKnownStatusIfWorse(knownStatus, TypeKnownStatus.Unknown); knownStatus = this._updateKnownStatusIfWorse(knownStatus, TypeKnownStatus.Unknown);
} else if (isPartlyUnknown(typeArg)) { } else if (isPartlyUnknown(typeArg)) {
diag.addMessage( diag.addMessage(
`Type argument ${index + 1} for class "${type.details.name}" has partially unknown type` `Type argument ${index + 1} for class "${type.shared.name}" has partially unknown type`
); );
knownStatus = this._updateKnownStatusIfWorse(knownStatus, TypeKnownStatus.PartiallyUnknown); knownStatus = this._updateKnownStatusIfWorse(knownStatus, TypeKnownStatus.PartiallyUnknown);
} }
@ -1401,7 +1398,7 @@ export class PackageTypeVerifier {
} }
case TypeCategory.Module: { case TypeCategory.Module: {
if (!this._shouldIgnoreType(report, type.moduleName)) { if (!this._shouldIgnoreType(report, type.priv.moduleName)) {
const moduleSymbol = this._getSymbolForModule(report, type, publicSymbols); const moduleSymbol = this._getSymbolForModule(report, type, publicSymbols);
knownStatus = this._updateKnownStatusIfWorse(knownStatus, moduleSymbol.typeKnownStatus); knownStatus = this._updateKnownStatusIfWorse(knownStatus, moduleSymbol.typeKnownStatus);
} }

View File

@ -32,7 +32,7 @@ export function isTypedKwargs(param: FunctionParam): boolean {
isClassInstance(param.type) && isClassInstance(param.type) &&
isUnpackedClass(param.type) && isUnpackedClass(param.type) &&
ClassType.isTypedDictClass(param.type) && ClassType.isTypedDictClass(param.type) &&
!!param.type.details.typedDictEntries !!param.type.shared.typedDictEntries
); );
} }
@ -72,7 +72,7 @@ export interface ParameterListDetails {
} }
export function firstParametersExcludingSelf(type: FunctionType): FunctionParam | undefined { export function firstParametersExcludingSelf(type: FunctionType): FunctionParam | undefined {
return type.details.parameters.find((p) => !(isTypeVar(p.type) && p.type.details.isSynthesizedSelf)); return type.shared.parameters.find((p) => !(isTypeVar(p.type) && p.type.shared.isSynthesizedSelf));
} }
// Examines the input parameters within a function signature and creates a // Examines the input parameters within a function signature and creates a
@ -88,13 +88,13 @@ export function getParameterListDetails(type: FunctionType): ParameterListDetail
hasUnpackedTypedDict: false, hasUnpackedTypedDict: false,
}; };
let positionOnlyIndex = type.details.parameters.findIndex((p) => isPositionOnlySeparator(p)); let positionOnlyIndex = type.shared.parameters.findIndex((p) => isPositionOnlySeparator(p));
// Handle the old (pre Python 3.8) way of specifying positional-only // Handle the old (pre Python 3.8) way of specifying positional-only
// parameters by naming them with "__". // parameters by naming them with "__".
if (positionOnlyIndex < 0) { if (positionOnlyIndex < 0) {
for (let i = 0; i < type.details.parameters.length; i++) { for (let i = 0; i < type.shared.parameters.length; i++) {
const p = type.details.parameters[i]; const p = type.shared.parameters[i];
if (p.category !== ParameterCategory.Simple) { if (p.category !== ParameterCategory.Simple) {
break; break;
} }
@ -117,7 +117,7 @@ export function getParameterListDetails(type: FunctionType): ParameterListDetail
} }
for (let i = 0; i < positionOnlyIndex; i++) { for (let i = 0; i < positionOnlyIndex; i++) {
if (type.details.parameters[i].defaultType) { if (type.shared.parameters[i].defaultType) {
break; break;
} }
@ -157,14 +157,14 @@ export function getParameterListDetails(type: FunctionType): ParameterListDetail
} }
}; };
type.details.parameters.forEach((param, index) => { type.shared.parameters.forEach((param, index) => {
if (param.category === ParameterCategory.ArgsList) { if (param.category === ParameterCategory.ArgsList) {
// If this is an unpacked tuple, expand the entries. // If this is an unpacked tuple, expand the entries.
const paramType = FunctionType.getEffectiveParameterType(type, index); const paramType = FunctionType.getEffectiveParameterType(type, index);
if (param.name && isUnpackedClass(paramType) && paramType.tupleTypeArguments) { if (param.name && isUnpackedClass(paramType) && paramType.priv.tupleTypeArguments) {
const addToPositionalOnly = index < result.positionOnlyParamCount; const addToPositionalOnly = index < result.positionOnlyParamCount;
paramType.tupleTypeArguments.forEach((tupleArg, tupleIndex) => { paramType.priv.tupleTypeArguments.forEach((tupleArg, tupleIndex) => {
const category = const category =
isVariadicTypeVar(tupleArg.type) || tupleArg.isUnbounded isVariadicTypeVar(tupleArg.type) || tupleArg.isUnbounded
? ParameterCategory.ArgsList ? ParameterCategory.ArgsList
@ -237,13 +237,13 @@ export function getParameterListDetails(type: FunctionType): ParameterListDetail
const paramType = FunctionType.getEffectiveParameterType(type, index); const paramType = FunctionType.getEffectiveParameterType(type, index);
// Is this an unpacked TypedDict? If so, expand the entries. // Is this an unpacked TypedDict? If so, expand the entries.
if (isClassInstance(paramType) && isUnpackedClass(paramType) && paramType.details.typedDictEntries) { if (isClassInstance(paramType) && isUnpackedClass(paramType) && paramType.shared.typedDictEntries) {
if (result.firstKeywordOnlyIndex === undefined) { if (result.firstKeywordOnlyIndex === undefined) {
result.firstKeywordOnlyIndex = result.params.length; result.firstKeywordOnlyIndex = result.params.length;
} }
const typedDictType = paramType; const typedDictType = paramType;
paramType.details.typedDictEntries.knownItems.forEach((entry, name) => { paramType.shared.typedDictEntries.knownItems.forEach((entry, name) => {
const specializedParamType = partiallySpecializeType(entry.valueType, typedDictType); const specializedParamType = partiallySpecializeType(entry.valueType, typedDictType);
addVirtualParameter( addVirtualParameter(
@ -259,16 +259,16 @@ export function getParameterListDetails(type: FunctionType): ParameterListDetail
); );
}); });
if (paramType.details.typedDictEntries.extraItems) { if (paramType.shared.typedDictEntries.extraItems) {
addVirtualParameter( addVirtualParameter(
FunctionParam.create( FunctionParam.create(
ParameterCategory.KwargsDict, ParameterCategory.KwargsDict,
paramType.details.typedDictEntries.extraItems.valueType, paramType.shared.typedDictEntries.extraItems.valueType,
FunctionParamFlags.TypeDeclared, FunctionParamFlags.TypeDeclared,
'kwargs' 'kwargs'
), ),
index, index,
paramType.details.typedDictEntries.extraItems.valueType paramType.shared.typedDictEntries.extraItems.valueType
); );
result.kwargsIndex = result.params.length - 1; result.kwargsIndex = result.params.length - 1;
@ -296,8 +296,8 @@ export function getParameterListDetails(type: FunctionType): ParameterListDetail
param, param,
index, index,
/* typeOverride */ undefined, /* typeOverride */ undefined,
type.specializedTypes?.parameterDefaultArgs type.priv.specializedTypes?.parameterDefaultArgs
? type.specializedTypes?.parameterDefaultArgs[index] ? type.priv.specializedTypes?.parameterDefaultArgs[index]
: undefined : undefined
); );
} }
@ -323,7 +323,7 @@ export function isParamSpecArgsArgument(paramSpec: TypeVarType, argType: Type) {
doForEachSubtype(argType, (argSubtype) => { doForEachSubtype(argType, (argSubtype) => {
if ( if (
isParamSpec(argSubtype) && isParamSpec(argSubtype) &&
argSubtype.paramSpecAccess === 'args' && argSubtype.priv.paramSpecAccess === 'args' &&
isTypeSame(argSubtype, paramSpec, { ignoreTypeFlags: true }) isTypeSame(argSubtype, paramSpec, { ignoreTypeFlags: true })
) { ) {
return; return;
@ -331,10 +331,10 @@ export function isParamSpecArgsArgument(paramSpec: TypeVarType, argType: Type) {
if ( if (
isClassInstance(argSubtype) && isClassInstance(argSubtype) &&
argSubtype.tupleTypeArguments && argSubtype.priv.tupleTypeArguments &&
argSubtype.tupleTypeArguments.length === 1 && argSubtype.priv.tupleTypeArguments.length === 1 &&
argSubtype.tupleTypeArguments[0].isUnbounded && argSubtype.priv.tupleTypeArguments[0].isUnbounded &&
isAnyOrUnknown(argSubtype.tupleTypeArguments[0].type) isAnyOrUnknown(argSubtype.priv.tupleTypeArguments[0].type)
) { ) {
return; return;
} }
@ -357,7 +357,7 @@ export function isParamSpecKwargsArgument(paramSpec: TypeVarType, argType: Type)
doForEachSubtype(argType, (argSubtype) => { doForEachSubtype(argType, (argSubtype) => {
if ( if (
isParamSpec(argSubtype) && isParamSpec(argSubtype) &&
argSubtype.paramSpecAccess === 'kwargs' && argSubtype.priv.paramSpecAccess === 'kwargs' &&
isTypeSame(argSubtype, paramSpec, { ignoreTypeFlags: true }) isTypeSame(argSubtype, paramSpec, { ignoreTypeFlags: true })
) { ) {
return; return;
@ -366,11 +366,11 @@ export function isParamSpecKwargsArgument(paramSpec: TypeVarType, argType: Type)
if ( if (
isClassInstance(argSubtype) && isClassInstance(argSubtype) &&
ClassType.isBuiltIn(argSubtype, 'dict') && ClassType.isBuiltIn(argSubtype, 'dict') &&
argSubtype.typeArguments && argSubtype.priv.typeArguments &&
argSubtype.typeArguments.length === 2 && argSubtype.priv.typeArguments.length === 2 &&
isClassInstance(argSubtype.typeArguments[0]) && isClassInstance(argSubtype.priv.typeArguments[0]) &&
ClassType.isBuiltIn(argSubtype.typeArguments[0], 'str') && ClassType.isBuiltIn(argSubtype.priv.typeArguments[0], 'str') &&
isAnyOrUnknown(argSubtype.typeArguments[1]) isAnyOrUnknown(argSubtype.priv.typeArguments[1])
) { ) {
return; return;
} }

View File

@ -229,8 +229,10 @@ function narrowTypeBasedOnSequencePattern(
canNarrowTuple = false; canNarrowTuple = false;
} }
if (isClassInstance(entry.subtype) && entry.subtype.tupleTypeArguments) { if (isClassInstance(entry.subtype) && entry.subtype.priv.tupleTypeArguments) {
const unboundedIndex = entry.subtype.tupleTypeArguments.findIndex((typeArg) => typeArg.isUnbounded); const unboundedIndex = entry.subtype.priv.tupleTypeArguments.findIndex(
(typeArg) => typeArg.isUnbounded
);
if (unboundedIndex >= 0) { if (unboundedIndex >= 0) {
// If the pattern includes a "star" entry that aligns exactly with // If the pattern includes a "star" entry that aligns exactly with
@ -270,13 +272,13 @@ function narrowTypeBasedOnSequencePattern(
if (index === pattern.starEntryIndex) { if (index === pattern.starEntryIndex) {
if ( if (
isClassInstance(narrowedEntryType) && isClassInstance(narrowedEntryType) &&
narrowedEntryType.tupleTypeArguments && narrowedEntryType.priv.tupleTypeArguments &&
!isUnboundedTupleClass(narrowedEntryType) && !isUnboundedTupleClass(narrowedEntryType) &&
narrowedEntryType.tupleTypeArguments narrowedEntryType.priv.tupleTypeArguments
) { ) {
appendArray( appendArray(
narrowedEntryTypes, narrowedEntryTypes,
narrowedEntryType.tupleTypeArguments.map((t) => t.type) narrowedEntryType.priv.tupleTypeArguments.map((t) => t.type)
); );
} else { } else {
narrowedEntryTypes.push(narrowedEntryType); narrowedEntryTypes.push(narrowedEntryType);
@ -451,10 +453,14 @@ function narrowTypeBasedOnMappingPattern(
const keyType = evaluator.getTypeOfExpression(keyPattern.expression).type; const keyType = evaluator.getTypeOfExpression(keyPattern.expression).type;
// The key type must be a str literal. // The key type must be a str literal.
if (!isClassInstance(keyType) || !ClassType.isBuiltIn(keyType, 'str') || keyType.literalValue === undefined) { if (
!isClassInstance(keyType) ||
!ClassType.isBuiltIn(keyType, 'str') ||
keyType.priv.literalValue === undefined
) {
return type; return type;
} }
const keyValue = keyType.literalValue as string; const keyValue = keyType.priv.literalValue as string;
const valueTypes = valuePattern.orPatterns.map( const valueTypes = valuePattern.orPatterns.map(
(orPattern) => evaluator.getTypeOfExpression((orPattern as PatternLiteralNode).expression).type (orPattern) => evaluator.getTypeOfExpression((orPattern as PatternLiteralNode).expression).type
@ -475,7 +481,7 @@ function narrowTypeBasedOnMappingPattern(
(valueType) => (valueType) =>
isClassInstance(valueType) && isClassInstance(valueType) &&
ClassType.isSameGenericClass(valueType, memberValueType) && ClassType.isSameGenericClass(valueType, memberValueType) &&
valueType.literalValue === memberValueType.literalValue valueType.priv.literalValue === memberValueType.priv.literalValue
) )
) { ) {
return undefined; return undefined;
@ -522,7 +528,7 @@ function narrowTypeBasedOnMappingPattern(
} }
const tdEntries = getTypedDictMembersForClass(evaluator, mappingSubtypeInfo.typedDict!); const tdEntries = getTypedDictMembersForClass(evaluator, mappingSubtypeInfo.typedDict!);
const valueEntry = tdEntries.knownItems.get(keySubtype.literalValue as string); const valueEntry = tdEntries.knownItems.get(keySubtype.priv.literalValue as string);
if (valueEntry) { if (valueEntry) {
const narrowedValueType = narrowTypeBasedOnPattern( const narrowedValueType = narrowTypeBasedOnPattern(
evaluator, evaluator,
@ -539,9 +545,9 @@ function narrowTypeBasedOnMappingPattern(
isTypeSame(mappingSubtypeInfo.subtype, mappingSubtypeInfo.typedDict!) isTypeSame(mappingSubtypeInfo.subtype, mappingSubtypeInfo.typedDict!)
) { ) {
const newNarrowedEntriesMap = new Map<string, TypedDictEntry>( const newNarrowedEntriesMap = new Map<string, TypedDictEntry>(
mappingSubtypeInfo.typedDict!.typedDictNarrowedEntries ?? [] mappingSubtypeInfo.typedDict!.priv.typedDictNarrowedEntries ?? []
); );
newNarrowedEntriesMap.set(keySubtype.literalValue as string, { newNarrowedEntriesMap.set(keySubtype.priv.literalValue as string, {
valueType: valueEntry.valueType, valueType: valueEntry.valueType,
isReadOnly: valueEntry.isReadOnly, isReadOnly: valueEntry.isReadOnly,
isRequired: false, isRequired: false,
@ -607,9 +613,9 @@ function getPositionalMatchArgNames(evaluator: TypeEvaluator, type: ClassType):
isClassInstance(matchArgsType) && isClassInstance(matchArgsType) &&
isTupleClass(matchArgsType) && isTupleClass(matchArgsType) &&
!isUnboundedTupleClass(matchArgsType) && !isUnboundedTupleClass(matchArgsType) &&
matchArgsType.tupleTypeArguments matchArgsType.priv.tupleTypeArguments
) { ) {
const tupleArgs = matchArgsType.tupleTypeArguments; const tupleArgs = matchArgsType.priv.tupleTypeArguments;
// Are all the args string literals? // Are all the args string literals?
if ( if (
@ -618,7 +624,7 @@ function getPositionalMatchArgNames(evaluator: TypeEvaluator, type: ClassType):
isClassInstance(arg.type) && ClassType.isBuiltIn(arg.type, 'str') && isLiteralType(arg.type) isClassInstance(arg.type) && ClassType.isBuiltIn(arg.type, 'str') && isLiteralType(arg.type)
) )
) { ) {
return tupleArgs.map((arg) => (arg.type as ClassType).literalValue as string); return tupleArgs.map((arg) => (arg.type as ClassType).priv.literalValue as string);
} }
} }
} }
@ -657,12 +663,12 @@ function narrowTypeBasedOnLiteralPattern(
if ( if (
isClassInstance(expandedSubtype) && isClassInstance(expandedSubtype) &&
ClassType.isBuiltIn(expandedSubtype, 'bool') && ClassType.isBuiltIn(expandedSubtype, 'bool') &&
expandedSubtype.literalValue === undefined && expandedSubtype.priv.literalValue === undefined &&
isClassInstance(literalType) && isClassInstance(literalType) &&
ClassType.isBuiltIn(literalType, 'bool') && ClassType.isBuiltIn(literalType, 'bool') &&
literalType.literalValue !== undefined literalType.priv.literalValue !== undefined
) { ) {
return ClassType.cloneWithLiteral(literalType, !(literalType.literalValue as boolean)); return ClassType.cloneWithLiteral(literalType, !(literalType.priv.literalValue as boolean));
} }
return expandedSubtype; return expandedSubtype;
@ -721,7 +727,7 @@ function narrowTypeBasedOnClassPattern(
let classType = exprType; let classType = exprType;
if (classType.details.typeParameters.length > 0) { if (classType.shared.typeParameters.length > 0) {
classType = ClassType.cloneForSpecialization( classType = ClassType.cloneForSpecialization(
classType, classType,
/* typeArguments */ undefined, /* typeArguments */ undefined,
@ -741,7 +747,7 @@ function narrowTypeBasedOnClassPattern(
// Handle the case where the class pattern references type() or a subtype thereof // Handle the case where the class pattern references type() or a subtype thereof
// and the subject type is an instantiable class itself. // and the subject type is an instantiable class itself.
if (isPatternMetaclass && isInstantiableClass(subjectSubtypeExpanded)) { if (isPatternMetaclass && isInstantiableClass(subjectSubtypeExpanded)) {
const metaclass = subjectSubtypeExpanded.details.effectiveMetaclass ?? UnknownType.create(); const metaclass = subjectSubtypeExpanded.shared.effectiveMetaclass ?? UnknownType.create();
if (isInstantiableClass(classType) && evaluator.assignType(classType, metaclass)) { if (isInstantiableClass(classType) && evaluator.assignType(classType, metaclass)) {
return undefined; return undefined;
} }
@ -865,7 +871,7 @@ function narrowTypeBasedOnClassPattern(
unknownCallable, unknownCallable,
/* useUnknown */ isUnknown(subjectSubtypeExpanded) /* useUnknown */ isUnknown(subjectSubtypeExpanded)
); );
unknownCallable.details.declaredReturnType = subjectSubtypeExpanded; unknownCallable.shared.declaredReturnType = subjectSubtypeExpanded;
return unknownCallable; return unknownCallable;
} }
@ -875,7 +881,7 @@ function narrowTypeBasedOnClassPattern(
// Handle the case where the class pattern references type() or a subtype thereof // Handle the case where the class pattern references type() or a subtype thereof
// and the subject type is a class itself. // and the subject type is a class itself.
if (isPatternMetaclass && isInstantiableClass(subjectSubtypeExpanded)) { if (isPatternMetaclass && isInstantiableClass(subjectSubtypeExpanded)) {
const metaclass = subjectSubtypeExpanded.details.effectiveMetaclass ?? UnknownType.create(); const metaclass = subjectSubtypeExpanded.shared.effectiveMetaclass ?? UnknownType.create();
if ( if (
evaluator.assignType(expandedSubtype, metaclass) || evaluator.assignType(expandedSubtype, metaclass) ||
evaluator.assignType(metaclass, expandedSubtype) evaluator.assignType(metaclass, expandedSubtype)
@ -928,7 +934,7 @@ function narrowTypeBasedOnClassPattern(
if (isInstantiableClass(unexpandedSubtype) && isClassInstance(subjectSubtypeExpanded)) { if (isInstantiableClass(unexpandedSubtype) && isClassInstance(subjectSubtypeExpanded)) {
if ( if (
ClassType.isSpecialBuiltIn(unexpandedSubtype) || ClassType.isSpecialBuiltIn(unexpandedSubtype) ||
unexpandedSubtype.details.typeParameters.length > 0 unexpandedSubtype.shared.typeParameters.length > 0
) { ) {
const typeVarContext = new TypeVarContext(getTypeVarScopeId(unexpandedSubtype)); const typeVarContext = new TypeVarContext(getTypeVarScopeId(unexpandedSubtype));
const unspecializedMatchType = ClassType.cloneForSpecialization( const unspecializedMatchType = ClassType.cloneForSpecialization(
@ -1002,7 +1008,7 @@ function narrowTypeBasedOnClassPattern(
// Some built-in classes are treated as special cases for the class pattern // Some built-in classes are treated as special cases for the class pattern
// if a positional argument is used. // if a positional argument is used.
function isClassSpecialCaseForClassPattern(classType: ClassType) { function isClassSpecialCaseForClassPattern(classType: ClassType) {
if (classPatternSpecialCases.some((className) => classType.details.fullName === className)) { if (classPatternSpecialCases.some((className) => classType.shared.fullName === className)) {
return true; return true;
} }
@ -1013,11 +1019,8 @@ function isClassSpecialCaseForClassPattern(classType: ClassType) {
} }
// If the class derives from a built-in class, it is considered a special case. // If the class derives from a built-in class, it is considered a special case.
for (const mroClass of classType.details.mro) { for (const mroClass of classType.shared.mro) {
if ( if (isClass(mroClass) && classPatternSpecialCases.some((className) => mroClass.shared.fullName === className)) {
isClass(mroClass) &&
classPatternSpecialCases.some((className) => mroClass.details.fullName === className)
) {
return true; return true;
} }
} }
@ -1061,7 +1064,7 @@ function narrowTypeOfClassPatternArgument(
if (isClassSpecialCaseForClassPattern(matchType)) { if (isClassSpecialCaseForClassPattern(matchType)) {
useSelfForPattern = true; useSelfForPattern = true;
} else if (positionalArgNames.length === 0) { } else if (positionalArgNames.length === 0) {
matchType.details.mro.forEach((mroClass) => { matchType.shared.mro.forEach((mroClass) => {
if (isClass(mroClass) && isClassSpecialCaseForClassPattern(mroClass)) { if (isClass(mroClass) && isClassSpecialCaseForClassPattern(mroClass)) {
selfForPatternType = mroClass; selfForPatternType = mroClass;
useSelfForPattern = true; useSelfForPattern = true;
@ -1236,7 +1239,7 @@ function getMappingPatternInfo(evaluator: TypeEvaluator, type: Type, node: Patte
// Is it a subclass of Mapping? // Is it a subclass of Mapping?
let mroClassToSpecialize: ClassType | undefined; let mroClassToSpecialize: ClassType | undefined;
for (const mroClass of concreteSubtype.details.mro) { for (const mroClass of concreteSubtype.shared.mro) {
if (isInstantiableClass(mroClass) && ClassType.isBuiltIn(mroClass, 'Mapping')) { if (isInstantiableClass(mroClass) && ClassType.isBuiltIn(mroClass, 'Mapping')) {
mroClassToSpecialize = mroClass; mroClassToSpecialize = mroClass;
break; break;
@ -1246,14 +1249,14 @@ function getMappingPatternInfo(evaluator: TypeEvaluator, type: Type, node: Patte
if (mroClassToSpecialize) { if (mroClassToSpecialize) {
const specializedMapping = partiallySpecializeType(mroClassToSpecialize, concreteSubtype) as ClassType; const specializedMapping = partiallySpecializeType(mroClassToSpecialize, concreteSubtype) as ClassType;
if (specializedMapping.typeArguments && specializedMapping.typeArguments.length >= 2) { if (specializedMapping.priv.typeArguments && specializedMapping.priv.typeArguments.length >= 2) {
mappingInfo.push({ mappingInfo.push({
subtype, subtype,
isDefinitelyMapping: true, isDefinitelyMapping: true,
isDefinitelyNotMapping: false, isDefinitelyNotMapping: false,
dictTypeArgs: { dictTypeArgs: {
key: specializedMapping.typeArguments[0], key: specializedMapping.priv.typeArguments[0],
value: specializedMapping.typeArguments[1], value: specializedMapping.priv.typeArguments[1],
}, },
}); });
} }
@ -1307,7 +1310,7 @@ function getSequencePatternInfo(
let pushedEntry = false; let pushedEntry = false;
if (isClassInstance(concreteSubtype)) { if (isClassInstance(concreteSubtype)) {
for (const mroClass of concreteSubtype.details.mro) { for (const mroClass of concreteSubtype.shared.mro) {
if (!isInstantiableClass(mroClass)) { if (!isInstantiableClass(mroClass)) {
break; break;
} }
@ -1343,7 +1346,7 @@ function getSequencePatternInfo(
const specializedSequence = partiallySpecializeType(mroClassToSpecialize, concreteSubtype) as ClassType; const specializedSequence = partiallySpecializeType(mroClassToSpecialize, concreteSubtype) as ClassType;
if (isTupleClass(specializedSequence)) { if (isTupleClass(specializedSequence)) {
const typeArgs = specializedSequence.tupleTypeArguments ?? [ const typeArgs = specializedSequence.priv.tupleTypeArguments ?? [
{ type: UnknownType.create(), isUnbounded: true }, { type: UnknownType.create(), isUnbounded: true },
]; ];
@ -1481,8 +1484,8 @@ function getSequencePatternInfo(
sequenceInfo.push({ sequenceInfo.push({
subtype, subtype,
entryTypes: [ entryTypes: [
specializedSequence.typeArguments && specializedSequence.typeArguments.length > 0 specializedSequence.priv.typeArguments && specializedSequence.priv.typeArguments.length > 0
? specializedSequence.typeArguments[0] ? specializedSequence.priv.typeArguments[0]
: UnknownType.create(), : UnknownType.create(),
], ],
isIndeterminateLength: true, isIndeterminateLength: true,
@ -1514,10 +1517,10 @@ function getSequencePatternInfo(
sequenceTypeVarContext sequenceTypeVarContext
) as ClassType; ) as ClassType;
if (specializedSequence.typeArguments && specializedSequence.typeArguments.length > 0) { if (specializedSequence.priv.typeArguments && specializedSequence.priv.typeArguments.length > 0) {
sequenceInfo.push({ sequenceInfo.push({
subtype, subtype,
entryTypes: [specializedSequence.typeArguments[0]], entryTypes: [specializedSequence.priv.typeArguments[0]],
isIndeterminateLength: true, isIndeterminateLength: true,
isDefiniteNoMatch: false, isDefiniteNoMatch: false,
isPotentialNoMatch: true, isPotentialNoMatch: true,
@ -1593,7 +1596,7 @@ function getTypeOfPatternSequenceEntry(
// its type other than it's "Unknown". We could evaluate it as an // its type other than it's "Unknown". We could evaluate it as an
// "object", but that will cause problems given that this type will // "object", but that will cause problems given that this type will
// be wrapped in a "list" below, and lists are invariant. // be wrapped in a "list" below, and lists are invariant.
if (isVariadicTypeVar(type) && !type.isVariadicInUnion) { if (isVariadicTypeVar(type) && !type.priv.isVariadicInUnion) {
return UnknownType.create(); return UnknownType.create();
} }
@ -1741,7 +1744,7 @@ export function assignTypeToPatternTargets(
evaluator, evaluator,
mappingSubtypeInfo.typedDict! mappingSubtypeInfo.typedDict!
); );
const valueInfo = tdEntries.knownItems.get(keySubtype.literalValue as string); const valueInfo = tdEntries.knownItems.get(keySubtype.priv.literalValue as string);
valueTypes.push(valueInfo ? valueInfo.valueType : UnknownType.create()); valueTypes.push(valueInfo ? valueInfo.valueType : UnknownType.create());
} else { } else {
valueTypes.push(UnknownType.create()); valueTypes.push(UnknownType.create());
@ -1900,8 +1903,8 @@ export function validateClassPattern(evaluator: TypeEvaluator, pattern: PatternC
if ( if (
exprType.props?.typeAliasInfo && exprType.props?.typeAliasInfo &&
isInstantiableClass(exprType) && isInstantiableClass(exprType) &&
exprType.typeArguments && exprType.priv.typeArguments &&
exprType.isTypeArgumentExplicit exprType.priv.isTypeArgumentExplicit
) { ) {
evaluator.addDiagnostic( evaluator.addDiagnostic(
DiagnosticRule.reportGeneralTypeIssues, DiagnosticRule.reportGeneralTypeIssues,
@ -1951,7 +1954,7 @@ export function validateClassPattern(evaluator: TypeEvaluator, pattern: PatternC
evaluator.addDiagnostic( evaluator.addDiagnostic(
DiagnosticRule.reportGeneralTypeIssues, DiagnosticRule.reportGeneralTypeIssues,
LocMessage.classPatternPositionalArgCount().format({ LocMessage.classPatternPositionalArgCount().format({
type: exprType.details.name, type: exprType.shared.name,
expected: expectedPatternCount, expected: expectedPatternCount,
received: positionalPatternCount, received: positionalPatternCount,
}), }),
@ -1997,7 +2000,7 @@ export function getPatternSubtypeNarrowingCallback(
doForEachSubtype(narrowedSubjectType, (subtype) => { doForEachSubtype(narrowedSubjectType, (subtype) => {
subtype = evaluator.makeTopLevelTypeVarsConcrete(subtype); subtype = evaluator.makeTopLevelTypeVarsConcrete(subtype);
if (isClassInstance(subtype) && subtype.literalValue !== undefined) { if (isClassInstance(subtype) && subtype.priv.literalValue !== undefined) {
if (ClassType.isBuiltIn(indexType, 'str')) { if (ClassType.isBuiltIn(indexType, 'str')) {
typesToCombine.push( typesToCombine.push(
narrowTypeForDiscriminatedDictEntryComparison( narrowTypeForDiscriminatedDictEntryComparison(
@ -2055,11 +2058,11 @@ export function getPatternSubtypeNarrowingCallback(
if ( if (
isClassInstance(subtype) && isClassInstance(subtype) &&
ClassType.isBuiltIn(subtype, 'tuple') && ClassType.isBuiltIn(subtype, 'tuple') &&
subtype.tupleTypeArguments && subtype.priv.tupleTypeArguments &&
matchingEntryIndex < subtype.tupleTypeArguments.length && matchingEntryIndex < subtype.priv.tupleTypeArguments.length &&
subtype.tupleTypeArguments.every((e) => !e.isUnbounded) subtype.priv.tupleTypeArguments.every((e) => !e.isUnbounded)
) { ) {
narrowedSubtypes.push(subtype.tupleTypeArguments[matchingEntryIndex].type); narrowedSubtypes.push(subtype.priv.tupleTypeArguments[matchingEntryIndex].type);
} else if (isNever(narrowedSubjectType)) { } else if (isNever(narrowedSubjectType)) {
narrowedSubtypes.push(narrowedSubjectType); narrowedSubtypes.push(narrowedSubjectType);
} else { } else {
@ -2096,7 +2099,7 @@ export function getPatternSubtypeNarrowingCallback(
} }
const resultType = mapSubtypes(narrowedSubjectType, (literalSubtype) => { const resultType = mapSubtypes(narrowedSubjectType, (literalSubtype) => {
assert(isClassInstance(literalSubtype) && literalSubtype.literalValue !== undefined); assert(isClassInstance(literalSubtype) && literalSubtype.priv.literalValue !== undefined);
return narrowTypeForDiscriminatedLiteralFieldComparison( return narrowTypeForDiscriminatedLiteralFieldComparison(
evaluator, evaluator,

View File

@ -60,11 +60,11 @@ export function createProperty(
const typeMetaclass = evaluator.getBuiltInType(decoratorNode, 'type'); const typeMetaclass = evaluator.getBuiltInType(decoratorNode, 'type');
const typeSourceId = ClassType.isBuiltIn(decoratorType, 'property') const typeSourceId = ClassType.isBuiltIn(decoratorType, 'property')
? getTypeSourceId(decoratorNode) ? getTypeSourceId(decoratorNode)
: decoratorType.details.typeSourceId; : decoratorType.shared.typeSourceId;
const propertyClass = ClassType.createInstantiable( const propertyClass = ClassType.createInstantiable(
decoratorType.details.name, decoratorType.shared.name,
getClassFullName(decoratorNode, fileInfo.moduleName, `__property_${fget.details.name}`), getClassFullName(decoratorNode, fileInfo.moduleName, `__property_${fget.shared.name}`),
fileInfo.moduleName, fileInfo.moduleName,
fileInfo.fileUri, fileInfo.fileUri,
ClassTypeFlags.PropertyClass | ClassTypeFlags.BuiltIn, ClassTypeFlags.PropertyClass | ClassTypeFlags.BuiltIn,
@ -73,10 +73,10 @@ export function createProperty(
isInstantiableClass(typeMetaclass) ? typeMetaclass : UnknownType.create() isInstantiableClass(typeMetaclass) ? typeMetaclass : UnknownType.create()
); );
propertyClass.details.declaration = decoratorType.details.declaration; propertyClass.shared.declaration = decoratorType.shared.declaration;
propertyClass.details.typeVarScopeId = decoratorType.details.typeVarScopeId; propertyClass.shared.typeVarScopeId = decoratorType.shared.typeVarScopeId;
const objectType = evaluator.getBuiltInType(decoratorNode, 'object'); const objectType = evaluator.getBuiltInType(decoratorNode, 'object');
propertyClass.details.baseClasses.push(isInstantiableClass(objectType) ? objectType : UnknownType.create()); propertyClass.shared.baseClasses.push(isInstantiableClass(objectType) ? objectType : UnknownType.create());
computeMroLinearization(propertyClass); computeMroLinearization(propertyClass);
// Clone the symbol table of the old class type. // Clone the symbol table of the old class type.
@ -92,19 +92,19 @@ export function createProperty(
}); });
const propertyObject = ClassType.cloneAsInstance(propertyClass); const propertyObject = ClassType.cloneAsInstance(propertyClass);
propertyClass.isAsymmetricDescriptor = false; propertyClass.priv.isAsymmetricDescriptor = false;
// Update the __set__ and __delete__ methods if present. // Update the __set__ and __delete__ methods if present.
updateGetSetDelMethodForClonedProperty(evaluator, propertyObject); updateGetSetDelMethodForClonedProperty(evaluator, propertyObject);
// Fill in the fget method. // Fill in the fget method.
propertyObject.fgetInfo = { propertyObject.priv.fgetInfo = {
methodType: FunctionType.cloneWithNewFlags(fget, fget.details.flags | FunctionTypeFlags.StaticMethod), methodType: FunctionType.cloneWithNewFlags(fget, fget.shared.flags | FunctionTypeFlags.StaticMethod),
classType: fget.details.methodClass, classType: fget.shared.methodClass,
}; };
if (FunctionType.isClassMethod(fget)) { if (FunctionType.isClassMethod(fget)) {
propertyClass.details.flags |= ClassTypeFlags.ClassProperty; propertyClass.shared.flags |= ClassTypeFlags.ClassProperty;
} }
// Fill in the __get__ method with an overload. // Fill in the __get__ method with an overload.
@ -127,8 +127,8 @@ export function clonePropertyWithSetter(
} }
const classType = prop as ClassType; const classType = prop as ClassType;
const flagsToClone = classType.details.flags; const flagsToClone = classType.shared.flags;
let isAsymmetricDescriptor = !!classType.isAsymmetricDescriptor; let isAsymmetricDescriptor = !!classType.priv.isAsymmetricDescriptor;
// Verify parameters for fset. // Verify parameters for fset.
// We'll skip this test if the diagnostic rule is disabled because it // We'll skip this test if the diagnostic rule is disabled because it
@ -164,25 +164,25 @@ export function clonePropertyWithSetter(
} }
const propertyClass = ClassType.createInstantiable( const propertyClass = ClassType.createInstantiable(
classType.details.name, classType.shared.name,
classType.details.fullName, classType.shared.fullName,
classType.details.moduleName, classType.shared.moduleName,
getFileInfo(errorNode).fileUri, getFileInfo(errorNode).fileUri,
flagsToClone, flagsToClone,
classType.details.typeSourceId, classType.shared.typeSourceId,
classType.details.declaredMetaclass, classType.shared.declaredMetaclass,
classType.details.effectiveMetaclass classType.shared.effectiveMetaclass
); );
propertyClass.details.declaration = classType.details.declaration; propertyClass.shared.declaration = classType.shared.declaration;
propertyClass.details.typeVarScopeId = classType.details.typeVarScopeId; propertyClass.shared.typeVarScopeId = classType.shared.typeVarScopeId;
const objectType = evaluator.getBuiltInType(errorNode, 'object'); const objectType = evaluator.getBuiltInType(errorNode, 'object');
propertyClass.details.baseClasses.push(isInstantiableClass(objectType) ? objectType : UnknownType.create()); propertyClass.shared.baseClasses.push(isInstantiableClass(objectType) ? objectType : UnknownType.create());
computeMroLinearization(propertyClass); computeMroLinearization(propertyClass);
propertyClass.fgetInfo = classType.fgetInfo; propertyClass.priv.fgetInfo = classType.priv.fgetInfo;
propertyClass.fdelInfo = classType.fdelInfo; propertyClass.priv.fdelInfo = classType.priv.fdelInfo;
propertyClass.isAsymmetricDescriptor = isAsymmetricDescriptor; propertyClass.priv.isAsymmetricDescriptor = isAsymmetricDescriptor;
const propertyObject = ClassType.cloneAsInstance(propertyClass); const propertyObject = ClassType.cloneAsInstance(propertyClass);
// Clone the symbol table of the old class type. // Clone the symbol table of the old class type.
@ -197,9 +197,9 @@ export function clonePropertyWithSetter(
updateGetSetDelMethodForClonedProperty(evaluator, propertyObject); updateGetSetDelMethodForClonedProperty(evaluator, propertyObject);
// Fill in the new fset method. // Fill in the new fset method.
propertyObject.fsetInfo = { propertyObject.priv.fsetInfo = {
methodType: FunctionType.cloneWithNewFlags(fset, fset.details.flags | FunctionTypeFlags.StaticMethod), methodType: FunctionType.cloneWithNewFlags(fset, fset.shared.flags | FunctionTypeFlags.StaticMethod),
classType: fset.details.methodClass, classType: fset.shared.methodClass,
}; };
// Fill in the __set__ method. // Fill in the __set__ method.
@ -223,26 +223,26 @@ export function clonePropertyWithDeleter(
const classType = prop as ClassType; const classType = prop as ClassType;
const propertyClass = ClassType.createInstantiable( const propertyClass = ClassType.createInstantiable(
classType.details.name, classType.shared.name,
classType.details.fullName, classType.shared.fullName,
classType.details.moduleName, classType.shared.moduleName,
getFileInfo(errorNode).fileUri, getFileInfo(errorNode).fileUri,
classType.details.flags, classType.shared.flags,
classType.details.typeSourceId, classType.shared.typeSourceId,
classType.details.declaredMetaclass, classType.shared.declaredMetaclass,
classType.details.effectiveMetaclass classType.shared.effectiveMetaclass
); );
propertyClass.details.declaration = classType.details.declaration; propertyClass.shared.declaration = classType.shared.declaration;
propertyClass.details.typeVarScopeId = classType.details.typeVarScopeId; propertyClass.shared.typeVarScopeId = classType.shared.typeVarScopeId;
const objectType = evaluator.getBuiltInType(errorNode, 'object'); const objectType = evaluator.getBuiltInType(errorNode, 'object');
propertyClass.details.baseClasses.push(isInstantiableClass(objectType) ? objectType : UnknownType.create()); propertyClass.shared.baseClasses.push(isInstantiableClass(objectType) ? objectType : UnknownType.create());
computeMroLinearization(propertyClass); computeMroLinearization(propertyClass);
propertyClass.fgetInfo = classType.fgetInfo; propertyClass.priv.fgetInfo = classType.priv.fgetInfo;
propertyClass.fsetInfo = classType.fsetInfo; propertyClass.priv.fsetInfo = classType.priv.fsetInfo;
const propertyObject = ClassType.cloneAsInstance(propertyClass); const propertyObject = ClassType.cloneAsInstance(propertyClass);
propertyClass.isAsymmetricDescriptor = classType.isAsymmetricDescriptor ?? false; propertyClass.priv.isAsymmetricDescriptor = classType.priv.isAsymmetricDescriptor ?? false;
// Clone the symbol table of the old class type. // Clone the symbol table of the old class type.
const fields = ClassType.getSymbolTable(propertyClass); const fields = ClassType.getSymbolTable(propertyClass);
@ -256,9 +256,9 @@ export function clonePropertyWithDeleter(
updateGetSetDelMethodForClonedProperty(evaluator, propertyObject); updateGetSetDelMethodForClonedProperty(evaluator, propertyObject);
// Fill in the fdel method. // Fill in the fdel method.
propertyObject.fdelInfo = { propertyObject.priv.fdelInfo = {
methodType: FunctionType.cloneWithNewFlags(fdel, fdel.details.flags | FunctionTypeFlags.StaticMethod), methodType: FunctionType.cloneWithNewFlags(fdel, fdel.shared.flags | FunctionTypeFlags.StaticMethod),
classType: fdel.details.methodClass, classType: fdel.shared.methodClass,
}; };
// Fill in the __delete__ method. // Fill in the __delete__ method.
@ -294,15 +294,15 @@ function addGetMethodToPropertySymbolTable(evaluator: TypeEvaluator, propertyObj
AnyType.create(/* isEllipsis */ true) AnyType.create(/* isEllipsis */ true)
) )
); );
getFunction1.details.declaredReturnType = FunctionType.isClassMethod(fget) getFunction1.shared.declaredReturnType = FunctionType.isClassMethod(fget)
? FunctionType.getEffectiveReturnType(fget) ? FunctionType.getEffectiveReturnType(fget)
: propertyObject; : propertyObject;
getFunction1.details.declaration = fget.details.declaration; getFunction1.shared.declaration = fget.shared.declaration;
getFunction1.details.deprecatedMessage = fget.details.deprecatedMessage; getFunction1.shared.deprecatedMessage = fget.shared.deprecatedMessage;
// Override the scope ID since we're using parameter types from the // Override the scope ID since we're using parameter types from the
// decorated function. // decorated function.
getFunction1.details.typeVarScopeId = getTypeVarScopeId(fget); getFunction1.shared.typeVarScopeId = getTypeVarScopeId(fget);
// The second overload is for accesses through a class instance. // The second overload is for accesses through a class instance.
const getFunction2 = FunctionType.createSynthesizedInstance('__get__', FunctionTypeFlags.Overloaded); const getFunction2 = FunctionType.createSynthesizedInstance('__get__', FunctionTypeFlags.Overloaded);
@ -312,7 +312,7 @@ function addGetMethodToPropertySymbolTable(evaluator: TypeEvaluator, propertyObj
); );
const objType = const objType =
fget.details.parameters.length > 0 ? FunctionType.getEffectiveParameterType(fget, 0) : AnyType.create(); fget.shared.parameters.length > 0 ? FunctionType.getEffectiveParameterType(fget, 0) : AnyType.create();
FunctionType.addParameter( FunctionType.addParameter(
getFunction2, getFunction2,
@ -329,13 +329,13 @@ function addGetMethodToPropertySymbolTable(evaluator: TypeEvaluator, propertyObj
AnyType.create(/* isEllipsis */ true) AnyType.create(/* isEllipsis */ true)
) )
); );
getFunction2.details.declaredReturnType = FunctionType.getEffectiveReturnType(fget); getFunction2.shared.declaredReturnType = FunctionType.getEffectiveReturnType(fget);
getFunction2.details.declaration = fget.details.declaration; getFunction2.shared.declaration = fget.shared.declaration;
getFunction2.details.deprecatedMessage = fget.details.deprecatedMessage; getFunction2.shared.deprecatedMessage = fget.shared.deprecatedMessage;
// Override the scope ID since we're using parameter types from the // Override the scope ID since we're using parameter types from the
// decorated function. // decorated function.
getFunction2.details.typeVarScopeId = getTypeVarScopeId(fget); getFunction2.shared.typeVarScopeId = getTypeVarScopeId(fget);
// We previously placed getFunction1 before getFunction2, but this creates // We previously placed getFunction1 before getFunction2, but this creates
// problems specifically for the `NoneType` class because None.__class__ // problems specifically for the `NoneType` class because None.__class__
@ -356,8 +356,8 @@ function addSetMethodToPropertySymbolTable(evaluator: TypeEvaluator, propertyObj
); );
let objType = let objType =
fset.details.parameters.length > 0 ? FunctionType.getEffectiveParameterType(fset, 0) : AnyType.create(); fset.shared.parameters.length > 0 ? FunctionType.getEffectiveParameterType(fset, 0) : AnyType.create();
if (isTypeVar(objType) && objType.details.isSynthesizedSelf) { if (isTypeVar(objType) && objType.shared.isSynthesizedSelf) {
objType = evaluator.makeTopLevelTypeVarsConcrete(objType); objType = evaluator.makeTopLevelTypeVarsConcrete(objType);
} }
@ -371,21 +371,21 @@ function addSetMethodToPropertySymbolTable(evaluator: TypeEvaluator, propertyObj
) )
); );
setFunction.details.declaredReturnType = evaluator.getNoneType(); setFunction.shared.declaredReturnType = evaluator.getNoneType();
// Adopt the TypeVarScopeId of the fset function in case it has any // Adopt the TypeVarScopeId of the fset function in case it has any
// TypeVars that need to be solved. // TypeVars that need to be solved.
setFunction.details.typeVarScopeId = getTypeVarScopeId(fset); setFunction.shared.typeVarScopeId = getTypeVarScopeId(fset);
setFunction.details.deprecatedMessage = fset.details.deprecatedMessage; setFunction.shared.deprecatedMessage = fset.shared.deprecatedMessage;
let setParamType: Type = UnknownType.create(); let setParamType: Type = UnknownType.create();
if ( if (
fset.details.parameters.length >= 2 && fset.shared.parameters.length >= 2 &&
fset.details.parameters[1].category === ParameterCategory.Simple && fset.shared.parameters[1].category === ParameterCategory.Simple &&
fset.details.parameters[1].name fset.shared.parameters[1].name
) { ) {
setParamType = fset.details.parameters[1].type; setParamType = fset.shared.parameters[1].type;
} }
FunctionType.addParameter( FunctionType.addParameter(
setFunction, setFunction,
@ -406,13 +406,13 @@ function addDelMethodToPropertySymbolTable(evaluator: TypeEvaluator, propertyObj
// Adopt the TypeVarScopeId of the fdel function in case it has any // Adopt the TypeVarScopeId of the fdel function in case it has any
// TypeVars that need to be solved. // TypeVars that need to be solved.
delFunction.details.typeVarScopeId = getTypeVarScopeId(fdel); delFunction.shared.typeVarScopeId = getTypeVarScopeId(fdel);
delFunction.details.deprecatedMessage = fdel.details.deprecatedMessage; delFunction.shared.deprecatedMessage = fdel.shared.deprecatedMessage;
let objType = let objType =
fdel.details.parameters.length > 0 ? FunctionType.getEffectiveParameterType(fdel, 0) : AnyType.create(); fdel.shared.parameters.length > 0 ? FunctionType.getEffectiveParameterType(fdel, 0) : AnyType.create();
if (isTypeVar(objType) && objType.details.isSynthesizedSelf) { if (isTypeVar(objType) && objType.shared.isSynthesizedSelf) {
objType = evaluator.makeTopLevelTypeVarsConcrete(objType); objType = evaluator.makeTopLevelTypeVarsConcrete(objType);
} }
@ -425,23 +425,23 @@ function addDelMethodToPropertySymbolTable(evaluator: TypeEvaluator, propertyObj
'obj' 'obj'
) )
); );
delFunction.details.declaredReturnType = evaluator.getNoneType(); delFunction.shared.declaredReturnType = evaluator.getNoneType();
const delSymbol = Symbol.createWithType(SymbolFlags.ClassMember, delFunction); const delSymbol = Symbol.createWithType(SymbolFlags.ClassMember, delFunction);
fields.set('__delete__', delSymbol); fields.set('__delete__', delSymbol);
} }
function updateGetSetDelMethodForClonedProperty(evaluator: TypeEvaluator, propertyObject: ClassType) { function updateGetSetDelMethodForClonedProperty(evaluator: TypeEvaluator, propertyObject: ClassType) {
const fgetInfo = propertyObject.fgetInfo; const fgetInfo = propertyObject.priv.fgetInfo;
if (fgetInfo && isFunction(fgetInfo.methodType)) { if (fgetInfo && isFunction(fgetInfo.methodType)) {
addGetMethodToPropertySymbolTable(evaluator, propertyObject, fgetInfo.methodType); addGetMethodToPropertySymbolTable(evaluator, propertyObject, fgetInfo.methodType);
} }
const fsetInfo = propertyObject.fsetInfo; const fsetInfo = propertyObject.priv.fsetInfo;
if (fsetInfo && isFunction(fsetInfo.methodType)) { if (fsetInfo && isFunction(fsetInfo.methodType)) {
addSetMethodToPropertySymbolTable(evaluator, propertyObject, fsetInfo.methodType); addSetMethodToPropertySymbolTable(evaluator, propertyObject, fsetInfo.methodType);
} }
const fdelInfo = propertyObject.fdelInfo; const fdelInfo = propertyObject.priv.fdelInfo;
if (fdelInfo && isFunction(fdelInfo.methodType)) { if (fdelInfo && isFunction(fdelInfo.methodType)) {
addDelMethodToPropertySymbolTable(evaluator, propertyObject, fdelInfo.methodType); addDelMethodToPropertySymbolTable(evaluator, propertyObject, fdelInfo.methodType);
} }
@ -466,7 +466,7 @@ function addDecoratorMethodsToPropertySymbolTable(propertyObject: ClassType) {
'accessor' 'accessor'
) )
); );
accessorFunction.details.declaredReturnType = propertyObject; accessorFunction.shared.declaredReturnType = propertyObject;
const accessorSymbol = Symbol.createWithType(SymbolFlags.ClassMember, accessorFunction); const accessorSymbol = Symbol.createWithType(SymbolFlags.ClassMember, accessorFunction);
fields.set(accessorName, accessorSymbol); fields.set(accessorName, accessorSymbol);
}); });
@ -492,17 +492,17 @@ export function assignProperty(
incompatibleDiagMsg: () => string; incompatibleDiagMsg: () => string;
}[] = [ }[] = [
{ {
getFunction: (c: ClassType) => c.fgetInfo?.methodType, getFunction: (c: ClassType) => c.priv.fgetInfo?.methodType,
missingDiagMsg: LocAddendum.missingGetter, missingDiagMsg: LocAddendum.missingGetter,
incompatibleDiagMsg: LocAddendum.incompatibleGetter, incompatibleDiagMsg: LocAddendum.incompatibleGetter,
}, },
{ {
getFunction: (c: ClassType) => c.fsetInfo?.methodType, getFunction: (c: ClassType) => c.priv.fsetInfo?.methodType,
missingDiagMsg: LocAddendum.missingSetter, missingDiagMsg: LocAddendum.missingSetter,
incompatibleDiagMsg: LocAddendum.incompatibleSetter, incompatibleDiagMsg: LocAddendum.incompatibleSetter,
}, },
{ {
getFunction: (c: ClassType) => c.fdelInfo?.methodType, getFunction: (c: ClassType) => c.priv.fdelInfo?.methodType,
missingDiagMsg: LocAddendum.missingDeleter, missingDiagMsg: LocAddendum.missingDeleter,
incompatibleDiagMsg: LocAddendum.incompatibleDeleter, incompatibleDiagMsg: LocAddendum.incompatibleDeleter,
}, },
@ -535,12 +535,12 @@ export function assignProperty(
// here and bind them to the associated objects. // here and bind them to the associated objects.
destAccessType = FunctionType.cloneWithNewFlags( destAccessType = FunctionType.cloneWithNewFlags(
destAccessType, destAccessType,
destAccessType.details.flags & ~FunctionTypeFlags.StaticMethod destAccessType.shared.flags & ~FunctionTypeFlags.StaticMethod
); );
srcAccessType = FunctionType.cloneWithNewFlags( srcAccessType = FunctionType.cloneWithNewFlags(
srcAccessType, srcAccessType,
srcAccessType.details.flags & ~FunctionTypeFlags.StaticMethod srcAccessType.shared.flags & ~FunctionTypeFlags.StaticMethod
); );
const boundDestAccessType = evaluator.bindFunctionToClassOrObject( const boundDestAccessType = evaluator.bindFunctionToClassOrObject(

View File

@ -178,7 +178,7 @@ export function isMethodOnlyProtocol(classType: ClassType): boolean {
} }
// First check for data members in any protocol base classes. // First check for data members in any protocol base classes.
for (const baseClass of classType.details.baseClasses) { for (const baseClass of classType.shared.baseClasses) {
if (isClass(baseClass) && ClassType.isProtocolClass(baseClass) && !isMethodOnlyProtocol(baseClass)) { if (isClass(baseClass) && ClassType.isProtocolClass(baseClass) && !isMethodOnlyProtocol(baseClass)) {
return false; return false;
} }
@ -208,7 +208,7 @@ export function isProtocolUnsafeOverlap(evaluator: TypeEvaluator, protocol: Clas
let isUnsafeOverlap = true; let isUnsafeOverlap = true;
protocol.details.mro.forEach((mroClass) => { protocol.shared.mro.forEach((mroClass) => {
if (!isUnsafeOverlap || !isInstantiableClass(mroClass) || !ClassType.isProtocolClass(mroClass)) { if (!isUnsafeOverlap || !isInstantiableClass(mroClass) || !ClassType.isProtocolClass(mroClass)) {
return; return;
} }
@ -237,8 +237,8 @@ function getProtocolCompatibility(
flags: AssignTypeFlags, flags: AssignTypeFlags,
typeVarContext: TypeVarContext | undefined typeVarContext: TypeVarContext | undefined
): boolean | undefined { ): boolean | undefined {
const map = srcType.details.protocolCompatibility as Map<string, ProtocolCompatibility[]> | undefined; const map = srcType.shared.protocolCompatibility as Map<string, ProtocolCompatibility[]> | undefined;
const entries = map?.get(destType.details.fullName); const entries = map?.get(destType.shared.fullName);
if (entries === undefined) { if (entries === undefined) {
return undefined; return undefined;
} }
@ -262,16 +262,16 @@ function setProtocolCompatibility(
typeVarContext: TypeVarContext | undefined, typeVarContext: TypeVarContext | undefined,
isCompatible: boolean isCompatible: boolean
) { ) {
let map = srcType.details.protocolCompatibility as Map<string, ProtocolCompatibility[]> | undefined; let map = srcType.shared.protocolCompatibility as Map<string, ProtocolCompatibility[]> | undefined;
if (!map) { if (!map) {
map = new Map<string, ProtocolCompatibility[]>(); map = new Map<string, ProtocolCompatibility[]>();
srcType.details.protocolCompatibility = map; srcType.shared.protocolCompatibility = map;
} }
let entries = map.get(destType.details.fullName); let entries = map.get(destType.shared.fullName);
if (!entries) { if (!entries) {
entries = []; entries = [];
map.set(destType.details.fullName, entries); map.set(destType.shared.fullName, entries);
} }
entries.push({ entries.push({
@ -319,7 +319,7 @@ function assignClassToProtocolInternal(
if (isClass(srcType)) { if (isClass(srcType)) {
// If the srcType is conditioned on "self", use "Self" as the selfType. // If the srcType is conditioned on "self", use "Self" as the selfType.
// Otherwise use the class type for selfType. // Otherwise use the class type for selfType.
if (srcType.props?.condition?.some((c) => c.typeVar.details.isSynthesizedSelf)) { if (srcType.props?.condition?.some((c) => c.typeVar.shared.isSynthesizedSelf)) {
selfType = synthesizeTypeVarForSelfCls( selfType = synthesizeTypeVarForSelfCls(
TypeBase.cloneForCondition(srcType, undefined), TypeBase.cloneForCondition(srcType, undefined),
/* isClsType */ false /* isClsType */ false
@ -349,7 +349,7 @@ function assignClassToProtocolInternal(
? AssignTypeFlags.RetainLiteralsForTypeVar ? AssignTypeFlags.RetainLiteralsForTypeVar
: AssignTypeFlags.Default; : AssignTypeFlags.Default;
destType.details.mro.forEach((mroClass) => { destType.shared.mro.forEach((mroClass) => {
if (!isInstantiableClass(mroClass) || !ClassType.isProtocolClass(mroClass)) { if (!isInstantiableClass(mroClass) || !ClassType.isProtocolClass(mroClass)) {
return; return;
} }
@ -403,10 +403,10 @@ function assignClassToProtocolInternal(
// Look in the metaclass first if we're treating the source as an instantiable class. // Look in the metaclass first if we're treating the source as an instantiable class.
if ( if (
sourceIsClassObject && sourceIsClassObject &&
srcType.details.effectiveMetaclass && srcType.shared.effectiveMetaclass &&
isInstantiableClass(srcType.details.effectiveMetaclass) isInstantiableClass(srcType.shared.effectiveMetaclass)
) { ) {
srcMemberInfo = lookUpClassMember(srcType.details.effectiveMetaclass, name); srcMemberInfo = lookUpClassMember(srcType.shared.effectiveMetaclass, name);
if (srcMemberInfo) { if (srcMemberInfo) {
isMemberFromMetaclass = true; isMemberFromMetaclass = true;
} }
@ -490,7 +490,7 @@ function assignClassToProtocolInternal(
isSrcReadOnly = true; isSrcReadOnly = true;
} }
} else { } else {
srcSymbol = srcType.fields.get(name); srcSymbol = srcType.priv.fields.get(name);
if (!srcSymbol) { if (!srcSymbol) {
diag?.addMessage(LocAddendum.protocolMemberMissing().format({ name })); diag?.addMessage(LocAddendum.protocolMemberMissing().format({ name }));
@ -716,7 +716,7 @@ function assignClassToProtocolInternal(
}); });
// If the dest protocol has type parameters, make sure the source type arguments match. // If the dest protocol has type parameters, make sure the source type arguments match.
if (typesAreConsistent && destType.details.typeParameters.length > 0) { if (typesAreConsistent && destType.shared.typeParameters.length > 0) {
// Create a specialized version of the protocol defined by the dest and // Create a specialized version of the protocol defined by the dest and
// make sure the resulting type args can be assigned. // make sure the resulting type args can be assigned.
const genericProtocolType = ClassType.cloneForSpecialization( const genericProtocolType = ClassType.cloneForSpecialization(
@ -726,7 +726,7 @@ function assignClassToProtocolInternal(
); );
const specializedProtocolType = applySolvedTypeVars(genericProtocolType, protocolTypeVarContext) as ClassType; const specializedProtocolType = applySolvedTypeVars(genericProtocolType, protocolTypeVarContext) as ClassType;
if (destType.typeArguments) { if (destType.priv.typeArguments) {
if ( if (
!evaluator.assignTypeArguments( !evaluator.assignTypeArguments(
destType, destType,
@ -741,7 +741,7 @@ function assignClassToProtocolInternal(
typesAreConsistent = false; typesAreConsistent = false;
} }
} else if (destTypeVarContext && !destTypeVarContext.isLocked()) { } else if (destTypeVarContext && !destTypeVarContext.isLocked()) {
for (const typeParam of destType.details.typeParameters) { for (const typeParam of destType.shared.typeParameters) {
const typeArgEntry = protocolTypeVarContext.getPrimarySignature().getTypeVar(typeParam); const typeArgEntry = protocolTypeVarContext.getPrimarySignature().getTypeVar(typeParam);
if (typeArgEntry) { if (typeArgEntry) {
@ -769,7 +769,7 @@ function createProtocolTypeVarContext(
): TypeVarContext { ): TypeVarContext {
const protocolTypeVarContext = new TypeVarContext(getTypeVarScopeId(destType)); const protocolTypeVarContext = new TypeVarContext(getTypeVarScopeId(destType));
destType.details.typeParameters.forEach((typeParam, index) => { destType.shared.typeParameters.forEach((typeParam, index) => {
const entry = destTypeVarContext?.getPrimarySignature().getTypeVar(typeParam); const entry = destTypeVarContext?.getPrimarySignature().getTypeVar(typeParam);
if (entry) { if (entry) {
@ -779,8 +779,8 @@ function createProtocolTypeVarContext(
entry.narrowBoundNoLiterals, entry.narrowBoundNoLiterals,
entry.wideBound entry.wideBound
); );
} else if (destType.typeArguments && index < destType.typeArguments.length) { } else if (destType.priv.typeArguments && index < destType.priv.typeArguments.length) {
let typeArg = destType.typeArguments[index]; let typeArg = destType.priv.typeArguments[index];
let flags: AssignTypeFlags; let flags: AssignTypeFlags;
let hasUnsolvedTypeVars = requiresSpecialization(typeArg); let hasUnsolvedTypeVars = requiresSpecialization(typeArg);

View File

@ -518,10 +518,10 @@ export class SourceMapper {
return; return;
} }
if (isFunction(type) && type.details.declaration) { if (isFunction(type) && type.shared.declaration) {
this._addClassOrFunctionDeclarations(type.details.declaration, result, recursiveDeclCache); this._addClassOrFunctionDeclarations(type.shared.declaration, result, recursiveDeclCache);
} else if (isOverloadedFunction(type)) { } else if (isOverloadedFunction(type)) {
for (const overloadDecl of type.overloads.map((o) => o.details.declaration).filter(isDefined)) { for (const overloadDecl of type.priv.overloads.map((o) => o.shared.declaration).filter(isDefined)) {
this._addClassOrFunctionDeclarations(overloadDecl, result, recursiveDeclCache); this._addClassOrFunctionDeclarations(overloadDecl, result, recursiveDeclCache);
} }
} else if (isInstantiableClass(type)) { } else if (isInstantiableClass(type)) {
@ -601,13 +601,13 @@ export class SourceMapper {
useTypeAlias = false useTypeAlias = false
) { ) {
const fileUri = const fileUri =
useTypeAlias && type.props?.typeAliasInfo ? type.props.typeAliasInfo.fileUri : type.details.fileUri; useTypeAlias && type.props?.typeAliasInfo ? type.props.typeAliasInfo.fileUri : type.shared.fileUri;
const sourceFiles = this._getSourceFiles(fileUri, /* stubToShadow */ undefined, originated); const sourceFiles = this._getSourceFiles(fileUri, /* stubToShadow */ undefined, originated);
const fullName = const fullName =
useTypeAlias && type.props?.typeAliasInfo ? type.props.typeAliasInfo.fullName : type.details.fullName; useTypeAlias && type.props?.typeAliasInfo ? type.props.typeAliasInfo.fullName : type.shared.fullName;
const moduleName = const moduleName =
useTypeAlias && type.props?.typeAliasInfo ? type.props.typeAliasInfo.moduleName : type.details.moduleName; useTypeAlias && type.props?.typeAliasInfo ? type.props.typeAliasInfo.moduleName : type.shared.moduleName;
const fullClassName = fullName.substring(moduleName.length + 1 /* +1 for trailing dot */); const fullClassName = fullName.substring(moduleName.length + 1 /* +1 for trailing dot */);
for (const sourceFile of sourceFiles) { for (const sourceFile of sourceFiles) {

View File

@ -63,31 +63,31 @@ export function createTracePrinter(roots: Uri[]): TracePrinter {
case TypeCategory.Class: case TypeCategory.Class:
if (TypeBase.isInstantiable(type)) { if (TypeBase.isInstantiable(type)) {
return `Class '${type.details.name}' (${type.details.moduleName})`; return `Class '${type.shared.name}' (${type.shared.moduleName})`;
} else { } else {
return `Object '${type.details.name}' (${type.details.moduleName})`; return `Object '${type.shared.name}' (${type.shared.moduleName})`;
} }
case TypeCategory.Function: case TypeCategory.Function:
return `Function '${type.details.name}' (${type.details.moduleName})`; return `Function '${type.shared.name}' (${type.shared.moduleName})`;
case TypeCategory.Module: case TypeCategory.Module:
return `Module '${type.moduleName}' (${type.moduleName})`; return `Module '${type.priv.moduleName}' (${type.priv.moduleName})`;
case TypeCategory.Never: case TypeCategory.Never:
return `Never ${wrap(type.props?.typeAliasInfo?.fullName)}`; return `Never ${wrap(type.props?.typeAliasInfo?.fullName)}`;
case TypeCategory.OverloadedFunction: case TypeCategory.OverloadedFunction:
return `OverloadedFunction [${type.overloads.map((o) => wrap(printType(o), '"')).join(',')}]`; return `OverloadedFunction [${type.priv.overloads.map((o) => wrap(printType(o), '"')).join(',')}]`;
case TypeCategory.TypeVar: case TypeCategory.TypeVar:
return `TypeVar '${type.details.name}' ${wrap(type.props?.typeAliasInfo?.fullName)}`; return `TypeVar '${type.shared.name}' ${wrap(type.props?.typeAliasInfo?.fullName)}`;
case TypeCategory.Unbound: case TypeCategory.Unbound:
return `Unbound ${wrap(type.props?.typeAliasInfo?.fullName)}`; return `Unbound ${wrap(type.props?.typeAliasInfo?.fullName)}`;
case TypeCategory.Union: case TypeCategory.Union:
return `Union [${type.subtypes.map((o) => wrap(printType(o), '"')).join(',')}]`; return `Union [${type.priv.subtypes.map((o) => wrap(printType(o), '"')).join(',')}]`;
case TypeCategory.Unknown: case TypeCategory.Unknown:
return `Unknown ${wrap(type.props?.typeAliasInfo?.fullName)}`; return `Unknown ${wrap(type.props?.typeAliasInfo?.fullName)}`;

View File

@ -53,19 +53,19 @@ const DefaultClassIteratorFlagsForFunctions =
function isInheritedFromBuiltin(type: FunctionType | OverloadedFunctionType, classType?: ClassType): boolean { function isInheritedFromBuiltin(type: FunctionType | OverloadedFunctionType, classType?: ClassType): boolean {
if (type.category === TypeCategory.OverloadedFunction) { if (type.category === TypeCategory.OverloadedFunction) {
if (type.overloads.length === 0) { if (type.priv.overloads.length === 0) {
return false; return false;
} }
type = type.overloads[0]; type = type.priv.overloads[0];
} }
// Functions that are bound to a different type than where they // Functions that are bound to a different type than where they
// were declared are inherited. // were declared are inherited.
return ( return (
!!type.details.methodClass && !!type.shared.methodClass &&
ClassType.isBuiltIn(type.details.methodClass) && ClassType.isBuiltIn(type.shared.methodClass) &&
!!type.boundToType && !!type.priv.boundToType &&
!ClassType.isBuiltIn(type.boundToType) !ClassType.isBuiltIn(type.priv.boundToType)
); );
} }
@ -86,7 +86,7 @@ export function getFunctionDocStringInherited(
// Search mro // Search mro
if (!docString && classType) { if (!docString && classType) {
const funcName = type.details.name; const funcName = type.shared.name;
const memberIterator = getClassMemberIterator(classType, funcName, DefaultClassIteratorFlagsForFunctions); const memberIterator = getClassMemberIterator(classType, funcName, DefaultClassIteratorFlagsForFunctions);
for (const classMember of memberIterator) { for (const classMember of memberIterator) {
@ -103,7 +103,7 @@ export function getFunctionDocStringInherited(
} }
} }
return docString || type.details.docString; return docString || type.shared.docString;
} }
export function getOverloadedFunctionDocStringsInherited( export function getOverloadedFunctionDocStringsInherited(
@ -128,8 +128,8 @@ export function getOverloadedFunctionDocStringsInherited(
} }
// Search mro // Search mro
if (classType && type.overloads.length > 0) { if (classType && type.priv.overloads.length > 0) {
const funcName = type.overloads[0].details.name; const funcName = type.priv.overloads[0].shared.name;
const memberIterator = getClassMemberIterator(classType, funcName, DefaultClassIteratorFlagsForFunctions); const memberIterator = getClassMemberIterator(classType, funcName, DefaultClassIteratorFlagsForFunctions);
for (const classMember of memberIterator) { for (const classMember of memberIterator) {
@ -220,9 +220,9 @@ export function getModuleDocString(
resolvedDecl: DeclarationBase | undefined, resolvedDecl: DeclarationBase | undefined,
sourceMapper: SourceMapper sourceMapper: SourceMapper
) { ) {
let docString = type.docString; let docString = type.priv.docString;
if (!docString) { if (!docString) {
const uri = resolvedDecl?.uri ?? type.fileUri; const uri = resolvedDecl?.uri ?? type.priv.fileUri;
docString = getModuleDocStringFromUris([uri], sourceMapper); docString = getModuleDocStringFromUris([uri], sourceMapper);
} }
@ -234,7 +234,7 @@ export function getClassDocString(
resolvedDecl: Declaration | undefined, resolvedDecl: Declaration | undefined,
sourceMapper: SourceMapper sourceMapper: SourceMapper
) { ) {
let docString = classType.details.docString; let docString = classType.shared.docString;
if (!docString && resolvedDecl && _isAnyClassDeclaration(resolvedDecl)) { if (!docString && resolvedDecl && _isAnyClassDeclaration(resolvedDecl)) {
docString = isClassDeclaration(resolvedDecl) ? _getFunctionOrClassDeclsDocString([resolvedDecl]) : undefined; docString = isClassDeclaration(resolvedDecl) ? _getFunctionOrClassDeclsDocString([resolvedDecl]) : undefined;
if (!docString && resolvedDecl && isStubFile(resolvedDecl.uri)) { if (!docString && resolvedDecl && isStubFile(resolvedDecl.uri)) {
@ -292,10 +292,10 @@ function _getOverloadedFunctionDocStrings(
} }
const docStrings: string[] = []; const docStrings: string[] = [];
if (type.overloads.some((o) => o.details.docString)) { if (type.priv.overloads.some((o) => o.shared.docString)) {
type.overloads.forEach((overload) => { type.priv.overloads.forEach((overload) => {
if (overload.details.docString) { if (overload.shared.docString) {
docStrings.push(overload.details.docString); docStrings.push(overload.shared.docString);
} }
}); });
} else if (resolvedDecl && isStubFile(resolvedDecl.uri) && isFunctionDeclaration(resolvedDecl)) { } else if (resolvedDecl && isStubFile(resolvedDecl.uri) && isFunctionDeclaration(resolvedDecl)) {
@ -362,13 +362,13 @@ function _getFunctionDocString(type: Type, resolvedDecl: FunctionDeclaration | u
return undefined; return undefined;
} }
let docString = type.details.docString; let docString = type.shared.docString;
if (!docString && resolvedDecl) { if (!docString && resolvedDecl) {
docString = _getFunctionDocStringFromDeclaration(resolvedDecl, sourceMapper); docString = _getFunctionDocStringFromDeclaration(resolvedDecl, sourceMapper);
} }
if (!docString && type.details.declaration) { if (!docString && type.shared.declaration) {
docString = _getFunctionDocStringFromDeclaration(type.details.declaration, sourceMapper); docString = _getFunctionDocStringFromDeclaration(type.shared.declaration, sourceMapper);
} }
return docString; return docString;

File diff suppressed because it is too large Load Diff

View File

@ -249,7 +249,7 @@ export function getTypeNarrowingCallback(
if ( if (
isClassInstance(rightType) && isClassInstance(rightType) &&
(ClassType.isEnumClass(rightType) || ClassType.isBuiltIn(rightType, 'bool')) && (ClassType.isEnumClass(rightType) || ClassType.isBuiltIn(rightType, 'bool')) &&
rightType.literalValue !== undefined rightType.priv.literalValue !== undefined
) { ) {
return (type: Type) => { return (type: Type) => {
return { return {
@ -292,7 +292,7 @@ export function getTypeNarrowingCallback(
if (isClassInstance(indexType) && isLiteralType(indexType)) { if (isClassInstance(indexType) && isLiteralType(indexType)) {
if (ClassType.isBuiltIn(indexType, 'str')) { if (ClassType.isBuiltIn(indexType, 'str')) {
const rightType = evaluator.getTypeOfExpression(testExpression.rightExpression).type; const rightType = evaluator.getTypeOfExpression(testExpression.rightExpression).type;
if (isClassInstance(rightType) && rightType.literalValue !== undefined) { if (isClassInstance(rightType) && rightType.priv.literalValue !== undefined) {
return (type: Type) => { return (type: Type) => {
return { return {
type: narrowTypeForDiscriminatedDictEntryComparison( type: narrowTypeForDiscriminatedDictEntryComparison(
@ -310,12 +310,12 @@ export function getTypeNarrowingCallback(
const rightTypeResult = evaluator.getTypeOfExpression(testExpression.rightExpression); const rightTypeResult = evaluator.getTypeOfExpression(testExpression.rightExpression);
const rightType = rightTypeResult.type; const rightType = rightTypeResult.type;
if (isClassInstance(rightType) && rightType.literalValue !== undefined) { if (isClassInstance(rightType) && rightType.priv.literalValue !== undefined) {
let canNarrow = false; let canNarrow = false;
// Narrowing can be applied only for bool or enum literals. // Narrowing can be applied only for bool or enum literals.
if (ClassType.isBuiltIn(rightType, 'bool')) { if (ClassType.isBuiltIn(rightType, 'bool')) {
canNarrow = true; canNarrow = true;
} else if (rightType.literalValue instanceof EnumLiteral) { } else if (rightType.priv.literalValue instanceof EnumLiteral) {
canNarrow = true; canNarrow = true;
} }
@ -354,7 +354,7 @@ export function getTypeNarrowingCallback(
const rightType = rightTypeResult.type; const rightType = rightTypeResult.type;
if (isClassInstance(rightType) && rightType.literalValue !== undefined) { if (isClassInstance(rightType) && rightType.priv.literalValue !== undefined) {
return (type: Type) => { return (type: Type) => {
return { return {
type: narrowTypeForLiteralComparison( type: narrowTypeForLiteralComparison(
@ -432,7 +432,7 @@ export function getTypeNarrowingCallback(
const memberName = testExpression.leftExpression.memberName; const memberName = testExpression.leftExpression.memberName;
if (isClassInstance(rightType)) { if (isClassInstance(rightType)) {
if (rightType.literalValue !== undefined || isNoneInstance(rightType)) { if (rightType.priv.literalValue !== undefined || isNoneInstance(rightType)) {
return (type: Type) => { return (type: Type) => {
return { return {
type: narrowTypeForDiscriminatedLiteralFieldComparison( type: narrowTypeForDiscriminatedLiteralFieldComparison(
@ -462,7 +462,7 @@ export function getTypeNarrowingCallback(
if ( if (
isClassInstance(rightType) && isClassInstance(rightType) &&
(ClassType.isEnumClass(rightType) || ClassType.isBuiltIn(rightType, 'bool')) && (ClassType.isEnumClass(rightType) || ClassType.isBuiltIn(rightType, 'bool')) &&
rightType.literalValue !== undefined rightType.priv.literalValue !== undefined
) { ) {
return (type: Type) => { return (type: Type) => {
return { return {
@ -517,16 +517,16 @@ export function getTypeNarrowingCallback(
); );
const callType = callTypeResult.type; const callType = callTypeResult.type;
if (isFunction(callType) && callType.details.fullName === 'builtins.len') { if (isFunction(callType) && callType.shared.fullName === 'builtins.len') {
const rightTypeResult = evaluator.getTypeOfExpression(testExpression.rightExpression); const rightTypeResult = evaluator.getTypeOfExpression(testExpression.rightExpression);
const rightType = rightTypeResult.type; const rightType = rightTypeResult.type;
if ( if (
isClassInstance(rightType) && isClassInstance(rightType) &&
typeof rightType.literalValue === 'number' && typeof rightType.priv.literalValue === 'number' &&
rightType.literalValue >= 0 rightType.priv.literalValue >= 0
) { ) {
let tupleLength = rightType.literalValue; let tupleLength = rightType.priv.literalValue;
// We'll treat <, <= and == as positive tests with >=, > and != as // We'll treat <, <= and == as positive tests with >=, > and != as
// their negative counterparts. // their negative counterparts.
@ -725,9 +725,9 @@ export function getTypeNarrowingCallback(
const isFunctionReturnTypeGuard = (type: FunctionType) => { const isFunctionReturnTypeGuard = (type: FunctionType) => {
return ( return (
type.details.declaredReturnType && type.shared.declaredReturnType &&
isClassInstance(type.details.declaredReturnType) && isClassInstance(type.shared.declaredReturnType) &&
ClassType.isBuiltIn(type.details.declaredReturnType, ['TypeGuard', 'TypeIs']) ClassType.isBuiltIn(type.shared.declaredReturnType, ['TypeGuard', 'TypeIs'])
); );
}; };
@ -756,10 +756,10 @@ export function getTypeNarrowingCallback(
if ( if (
isClassInstance(functionReturnType) && isClassInstance(functionReturnType) &&
ClassType.isBuiltIn(functionReturnType, 'bool') && ClassType.isBuiltIn(functionReturnType, 'bool') &&
functionReturnType.typeGuardType functionReturnType.priv.typeGuardType
) { ) {
const isStrictTypeGuard = !!functionReturnType.isStrictTypeGuard; const isStrictTypeGuard = !!functionReturnType.priv.isStrictTypeGuard;
const typeGuardType = functionReturnType.typeGuardType; const typeGuardType = functionReturnType.priv.typeGuardType;
const isIncomplete = !!callTypeResult.isIncomplete || !!functionReturnTypeResult.isIncomplete; const isIncomplete = !!callTypeResult.isIncomplete || !!functionReturnTypeResult.isIncomplete;
return (type: Type) => { return (type: Type) => {
@ -1009,16 +1009,16 @@ function narrowTypeForTruthiness(evaluator: TypeEvaluator, type: Type, isPositiv
function narrowTupleTypeForIsNone(evaluator: TypeEvaluator, type: Type, isPositiveTest: boolean, indexValue: number) { function narrowTupleTypeForIsNone(evaluator: TypeEvaluator, type: Type, isPositiveTest: boolean, indexValue: number) {
return evaluator.mapSubtypesExpandTypeVars(type, /* options */ undefined, (subtype) => { return evaluator.mapSubtypesExpandTypeVars(type, /* options */ undefined, (subtype) => {
const tupleType = getSpecializedTupleType(subtype); const tupleType = getSpecializedTupleType(subtype);
if (!tupleType || isUnboundedTupleClass(tupleType) || !tupleType.tupleTypeArguments) { if (!tupleType || isUnboundedTupleClass(tupleType) || !tupleType.priv.tupleTypeArguments) {
return subtype; return subtype;
} }
const tupleLength = tupleType.tupleTypeArguments.length; const tupleLength = tupleType.priv.tupleTypeArguments.length;
if (indexValue < 0 || indexValue >= tupleLength) { if (indexValue < 0 || indexValue >= tupleLength) {
return subtype; return subtype;
} }
const typeOfEntry = evaluator.makeTopLevelTypeVarsConcrete(tupleType.tupleTypeArguments[indexValue].type); const typeOfEntry = evaluator.makeTopLevelTypeVarsConcrete(tupleType.priv.tupleTypeArguments[indexValue].type);
if (isPositiveTest) { if (isPositiveTest) {
if (!evaluator.assignType(typeOfEntry, evaluator.getNoneType())) { if (!evaluator.assignType(typeOfEntry, evaluator.getNoneType())) {
@ -1056,7 +1056,7 @@ function narrowTypeForIsNone(evaluator: TypeEvaluator, type: Type, isPositiveTes
// TypeVar. For all other cases (including constrained TypeVars), // TypeVar. For all other cases (including constrained TypeVars),
// use the expanded subtype. // use the expanded subtype.
const adjustedSubtype = const adjustedSubtype =
isTypeVar(unexpandedSubtype) && unexpandedSubtype.details.constraints.length === 0 isTypeVar(unexpandedSubtype) && unexpandedSubtype.shared.constraints.length === 0
? unexpandedSubtype ? unexpandedSubtype
: subtype; : subtype;
@ -1072,7 +1072,7 @@ function narrowTypeForIsNone(evaluator: TypeEvaluator, type: Type, isPositiveTes
if (isNoneInstance(subtype) === isPositiveTest) { if (isNoneInstance(subtype) === isPositiveTest) {
resultIncludesNoneSubtype = true; resultIncludesNoneSubtype = true;
if (isTypeVar(adjustedSubtype) && adjustedSubtype.details.isSynthesizedSelf) { if (isTypeVar(adjustedSubtype) && adjustedSubtype.shared.isSynthesizedSelf) {
return adjustedSubtype; return adjustedSubtype;
} }
@ -1112,7 +1112,7 @@ function narrowTypeForIsEllipsis(evaluator: TypeEvaluator, type: Type, isPositiv
// TypeVar. For all other cases (including constrained TypeVars), // TypeVar. For all other cases (including constrained TypeVars),
// use the expanded subtype. // use the expanded subtype.
const adjustedSubtype = const adjustedSubtype =
isTypeVar(unexpandedSubtype) && unexpandedSubtype.details.constraints.length === 0 isTypeVar(unexpandedSubtype) && unexpandedSubtype.shared.constraints.length === 0
? unexpandedSubtype ? unexpandedSubtype
: subtype; : subtype;
@ -1164,9 +1164,9 @@ function getIsInstanceClassTypes(
classTypeList.push(subtype); classTypeList.push(subtype);
} else if ( } else if (
isFunction(subtype) && isFunction(subtype) &&
subtype.details.parameters.length === 2 && subtype.shared.parameters.length === 2 &&
subtype.details.parameters[0].category === ParameterCategory.ArgsList && subtype.shared.parameters[0].category === ParameterCategory.ArgsList &&
subtype.details.parameters[1].category === ParameterCategory.KwargsDict subtype.shared.parameters[1].category === ParameterCategory.KwargsDict
) { ) {
classTypeList.push(subtype); classTypeList.push(subtype);
} else { } else {
@ -1181,8 +1181,8 @@ function getIsInstanceClassTypes(
} }
if (isClass(type) && TypeBase.isInstance(type) && isTupleClass(type)) { if (isClass(type) && TypeBase.isInstance(type) && isTupleClass(type)) {
if (type.tupleTypeArguments) { if (type.priv.tupleTypeArguments) {
type.tupleTypeArguments.forEach((tupleEntry) => { type.priv.tupleTypeArguments.forEach((tupleEntry) => {
addClassTypesRecursive(tupleEntry.type, recursionCount + 1); addClassTypesRecursive(tupleEntry.type, recursionCount + 1);
}); });
} }
@ -1208,14 +1208,14 @@ export function isIsinstanceFilterSuperclass(
concreteFilterType: ClassType, concreteFilterType: ClassType,
isInstanceCheck: boolean isInstanceCheck: boolean
) { ) {
if (isTypeVar(filterType) || concreteFilterType.literalValue !== undefined) { if (isTypeVar(filterType) || concreteFilterType.priv.literalValue !== undefined) {
return isTypeSame(convertToInstance(filterType), varType); return isTypeSame(convertToInstance(filterType), varType);
} }
// If the filter type represents all possible subclasses // If the filter type represents all possible subclasses
// of a type, we can't make any statements about its superclass // of a type, we can't make any statements about its superclass
// relationship with concreteVarType. // relationship with concreteVarType.
if (concreteFilterType.includeSubclasses) { if (concreteFilterType.priv.includeSubclasses) {
return false; return false;
} }
@ -1348,7 +1348,7 @@ function narrowTypeForIsInstanceInternal(
// If the class was implicitly specialized (e.g. because its type // If the class was implicitly specialized (e.g. because its type
// parameters have default values), replace the default type arguments // parameters have default values), replace the default type arguments
// with Unknown. // with Unknown.
if (concreteFilterType.typeArguments && !concreteFilterType.isTypeArgumentExplicit) { if (concreteFilterType.priv.typeArguments && !concreteFilterType.priv.isTypeArgumentExplicit) {
concreteFilterType = specializeWithUnknownTypeArgs( concreteFilterType = specializeWithUnknownTypeArgs(
ClassType.cloneForSpecialization( ClassType.cloneForSpecialization(
concreteFilterType, concreteFilterType,
@ -1404,7 +1404,7 @@ function narrowTypeForIsInstanceInternal(
// we haven't learned anything new about the variable type. // we haven't learned anything new about the variable type.
// If the varType is a Self or type[Self], retain the unnarrowedType. // If the varType is a Self or type[Self], retain the unnarrowedType.
if (isTypeVar(varType) && varType.details.isSynthesizedSelf) { if (isTypeVar(varType) && varType.shared.isSynthesizedSelf) {
filteredTypes.push(addConditionToType(varType, conditions)); filteredTypes.push(addConditionToType(varType, conditions));
} else { } else {
filteredTypes.push(addConditionToType(concreteVarType, conditions)); filteredTypes.push(addConditionToType(concreteVarType, conditions));
@ -1432,11 +1432,11 @@ function narrowTypeForIsInstanceInternal(
if (isClass(filterType)) { if (isClass(filterType)) {
if ( if (
ClassType.isSpecialBuiltIn(filterType) || ClassType.isSpecialBuiltIn(filterType) ||
filterType.details.typeParameters.length > 0 filterType.shared.typeParameters.length > 0
) { ) {
if ( if (
!filterType.typeArguments || !filterType.priv.typeArguments ||
!filterType.isTypeArgumentExplicit || !filterType.priv.isTypeArgumentExplicit ||
!ClassType.isSameGenericClass(concreteVarType, filterType) !ClassType.isSameGenericClass(concreteVarType, filterType)
) { ) {
const typeVarContext = new TypeVarContext(getTypeVarScopeId(filterType)); const typeVarContext = new TypeVarContext(getTypeVarScopeId(filterType));
@ -1482,17 +1482,17 @@ function narrowTypeForIsInstanceInternal(
// be a mix-in class used with the other. In this case, we'll // be a mix-in class used with the other. In this case, we'll
// synthesize a new class type that represents an intersection of // synthesize a new class type that represents an intersection of
// the two types. // the two types.
const className = `<subclass of ${concreteVarType.details.name} and ${concreteFilterType.details.name}>`; const className = `<subclass of ${concreteVarType.shared.name} and ${concreteFilterType.shared.name}>`;
const fileInfo = getFileInfo(errorNode); const fileInfo = getFileInfo(errorNode);
// The effective metaclass of the intersection is the narrower of the two metaclasses. // The effective metaclass of the intersection is the narrower of the two metaclasses.
let effectiveMetaclass = concreteVarType.details.effectiveMetaclass; let effectiveMetaclass = concreteVarType.shared.effectiveMetaclass;
if (concreteFilterType.details.effectiveMetaclass) { if (concreteFilterType.shared.effectiveMetaclass) {
if ( if (
!effectiveMetaclass || !effectiveMetaclass ||
evaluator.assignType(effectiveMetaclass, concreteFilterType.details.effectiveMetaclass) evaluator.assignType(effectiveMetaclass, concreteFilterType.shared.effectiveMetaclass)
) { ) {
effectiveMetaclass = concreteFilterType.details.effectiveMetaclass; effectiveMetaclass = concreteFilterType.shared.effectiveMetaclass;
} }
} }
@ -1505,9 +1505,9 @@ function narrowTypeForIsInstanceInternal(
ParseTreeUtils.getTypeSourceId(errorNode), ParseTreeUtils.getTypeSourceId(errorNode),
/* declaredMetaclass */ undefined, /* declaredMetaclass */ undefined,
effectiveMetaclass, effectiveMetaclass,
concreteVarType.details.docString concreteVarType.shared.docString
); );
newClassType.details.baseClasses = [ newClassType.shared.baseClasses = [
ClassType.cloneAsInstantiable(concreteVarType), ClassType.cloneAsInstantiable(concreteVarType),
concreteFilterType, concreteFilterType,
]; ];
@ -1520,8 +1520,8 @@ function narrowTypeForIsInstanceInternal(
if ( if (
isTypeVar(varType) && isTypeVar(varType) &&
!varType.details.isParamSpec && !varType.shared.isParamSpec &&
varType.details.constraints.length === 0 varType.shared.constraints.length === 0
) { ) {
newClassType = addConditionToType(newClassType, [ newClassType = addConditionToType(newClassType, [
{ typeVar: varType, constraintIndex: 0 }, { typeVar: varType, constraintIndex: 0 },
@ -1658,7 +1658,7 @@ function narrowTypeForIsInstanceInternal(
const concreteFilterType = evaluator.makeTopLevelTypeVarsConcrete(filterType); const concreteFilterType = evaluator.makeTopLevelTypeVarsConcrete(filterType);
if (isInstantiableClass(concreteFilterType)) { if (isInstantiableClass(concreteFilterType)) {
const filterMetaclass = concreteFilterType.details.effectiveMetaclass; const filterMetaclass = concreteFilterType.shared.effectiveMetaclass;
if (filterMetaclass && isInstantiableClass(filterMetaclass)) { if (filterMetaclass && isInstantiableClass(filterMetaclass)) {
let isMetaclassOverlap = evaluator.assignType( let isMetaclassOverlap = evaluator.assignType(
@ -1670,7 +1670,7 @@ function narrowTypeForIsInstanceInternal(
// This will normally be treated as type[Any], which is compatible with // This will normally be treated as type[Any], which is compatible with
// any metaclass, but we specifically want to treat type as the class // any metaclass, but we specifically want to treat type as the class
// type[object] in this case. // type[object] in this case.
if (ClassType.isBuiltIn(filterMetaclass, 'type') && !filterMetaclass.isTypeArgumentExplicit) { if (ClassType.isBuiltIn(filterMetaclass, 'type') && !filterMetaclass.priv.isTypeArgumentExplicit) {
if (!ClassType.isBuiltIn(metaclassType, 'type')) { if (!ClassType.isBuiltIn(metaclassType, 'type')) {
isMetaclassOverlap = false; isMetaclassOverlap = false;
} }
@ -1680,7 +1680,10 @@ function narrowTypeForIsInstanceInternal(
if (isPositiveTest) { if (isPositiveTest) {
filteredTypes.push(filterType); filteredTypes.push(filterType);
foundPositiveMatch = true; foundPositiveMatch = true;
} else if (!isTypeSame(metaclassType, filterMetaclass) || filterMetaclass.includeSubclasses) { } else if (
!isTypeSame(metaclassType, filterMetaclass) ||
filterMetaclass.priv.includeSubclasses
) {
filteredTypes.push(metaclassType); filteredTypes.push(metaclassType);
isMatchIndeterminate = true; isMatchIndeterminate = true;
} }
@ -1916,28 +1919,28 @@ function narrowTypeForTupleLength(
if ( if (
!isClassInstance(concreteSubtype) || !isClassInstance(concreteSubtype) ||
!isTupleClass(concreteSubtype) || !isTupleClass(concreteSubtype) ||
!concreteSubtype.tupleTypeArguments !concreteSubtype.priv.tupleTypeArguments
) { ) {
return subtype; return subtype;
} }
// If the tuple contains a variadic TypeVar, we can't narrow it. // If the tuple contains a variadic TypeVar, we can't narrow it.
if (concreteSubtype.tupleTypeArguments.some((typeArg) => isUnpackedVariadicTypeVar(typeArg.type))) { if (concreteSubtype.priv.tupleTypeArguments.some((typeArg) => isUnpackedVariadicTypeVar(typeArg.type))) {
return subtype; return subtype;
} }
// If the tuple contains no unbounded elements, then we know its length exactly. // If the tuple contains no unbounded elements, then we know its length exactly.
if (!concreteSubtype.tupleTypeArguments.some((typeArg) => typeArg.isUnbounded)) { if (!concreteSubtype.priv.tupleTypeArguments.some((typeArg) => typeArg.isUnbounded)) {
const tupleLengthMatches = isLessThanCheck const tupleLengthMatches = isLessThanCheck
? concreteSubtype.tupleTypeArguments.length < lengthValue ? concreteSubtype.priv.tupleTypeArguments.length < lengthValue
: concreteSubtype.tupleTypeArguments.length === lengthValue; : concreteSubtype.priv.tupleTypeArguments.length === lengthValue;
return tupleLengthMatches === isPositiveTest ? subtype : undefined; return tupleLengthMatches === isPositiveTest ? subtype : undefined;
} }
// The tuple contains a "...". We'll expand this into as many elements as // The tuple contains a "...". We'll expand this into as many elements as
// necessary to match the lengthValue. // necessary to match the lengthValue.
const elementsToAdd = lengthValue - concreteSubtype.tupleTypeArguments.length + 1; const elementsToAdd = lengthValue - concreteSubtype.priv.tupleTypeArguments.length + 1;
if (!isLessThanCheck) { if (!isLessThanCheck) {
// If the specified length is smaller than the minimum length of this tuple, // If the specified length is smaller than the minimum length of this tuple,
@ -1954,7 +1957,7 @@ function narrowTypeForTupleLength(
} }
// If this is a tuple related to an "*args: P.args" parameter, don't expand it. // If this is a tuple related to an "*args: P.args" parameter, don't expand it.
if (isParamSpec(subtype) && subtype.paramSpecAccess) { if (isParamSpec(subtype) && subtype.priv.paramSpecAccess) {
return subtype; return subtype;
} }
@ -1989,7 +1992,7 @@ function narrowTypeForTupleLength(
function expandUnboundedTupleElement(tupleType: ClassType, elementsToAdd: number, keepUnbounded: boolean) { function expandUnboundedTupleElement(tupleType: ClassType, elementsToAdd: number, keepUnbounded: boolean) {
const tupleTypeArgs: TupleTypeArgument[] = []; const tupleTypeArgs: TupleTypeArgument[] = [];
tupleType.tupleTypeArguments!.forEach((typeArg) => { tupleType.priv.tupleTypeArguments!.forEach((typeArg) => {
if (!typeArg.isUnbounded) { if (!typeArg.isUnbounded) {
tupleTypeArgs.push(typeArg); tupleTypeArgs.push(typeArg);
} else { } else {
@ -2031,7 +2034,7 @@ function narrowTypeForContainerType(
if ( if (
!isClassInstance(containerType) || !isClassInstance(containerType) ||
!ClassType.isBuiltIn(containerType, 'tuple') || !ClassType.isBuiltIn(containerType, 'tuple') ||
!containerType.tupleTypeArguments !containerType.priv.tupleTypeArguments
) { ) {
return referenceType; return referenceType;
} }
@ -2039,7 +2042,7 @@ function narrowTypeForContainerType(
// Determine which tuple types can be eliminated. Only "None" and // Determine which tuple types can be eliminated. Only "None" and
// literal types can be handled here. // literal types can be handled here.
const typesToEliminate: Type[] = []; const typesToEliminate: Type[] = [];
containerType.tupleTypeArguments.forEach((tupleEntry) => { containerType.priv.tupleTypeArguments.forEach((tupleEntry) => {
if (!tupleEntry.isUnbounded) { if (!tupleEntry.isUnbounded) {
if (isNoneInstance(tupleEntry.type)) { if (isNoneInstance(tupleEntry.type)) {
typesToEliminate.push(tupleEntry.type); typesToEliminate.push(tupleEntry.type);
@ -2055,7 +2058,7 @@ function narrowTypeForContainerType(
return mapSubtypes(referenceType, (referenceSubtype) => { return mapSubtypes(referenceType, (referenceSubtype) => {
referenceSubtype = evaluator.makeTopLevelTypeVarsConcrete(referenceSubtype); referenceSubtype = evaluator.makeTopLevelTypeVarsConcrete(referenceSubtype);
if (isClassInstance(referenceSubtype) && referenceSubtype.literalValue === undefined) { if (isClassInstance(referenceSubtype) && referenceSubtype.priv.literalValue === undefined) {
// If we're able to enumerate all possible literal values // If we're able to enumerate all possible literal values
// (for bool or enum), we can eliminate all others in a negative test. // (for bool or enum), we can eliminate all others in a negative test.
const allLiteralTypes = enumerateLiteralsForType(evaluator, referenceSubtype); const allLiteralTypes = enumerateLiteralsForType(evaluator, referenceSubtype);
@ -2081,13 +2084,13 @@ export function getElementTypeForContainerNarrowing(containerType: Type) {
return undefined; return undefined;
} }
if (!containerType.typeArguments || containerType.typeArguments.length < 1) { if (!containerType.priv.typeArguments || containerType.priv.typeArguments.length < 1) {
return undefined; return undefined;
} }
let elementType = containerType.typeArguments[0]; let elementType = containerType.priv.typeArguments[0];
if (isTupleClass(containerType) && containerType.tupleTypeArguments) { if (isTupleClass(containerType) && containerType.priv.tupleTypeArguments) {
elementType = combineTypes(containerType.tupleTypeArguments.map((t) => t.type)); elementType = combineTypes(containerType.priv.tupleTypeArguments.map((t) => t.type));
} }
return elementType; return elementType;
@ -2188,7 +2191,7 @@ function narrowTypeForTypedDictKey(
if (isClassInstance(subtype) && ClassType.isTypedDictClass(subtype)) { if (isClassInstance(subtype) && ClassType.isTypedDictClass(subtype)) {
const entries = getTypedDictMembersForClass(evaluator, subtype, /* allowNarrowed */ true); const entries = getTypedDictMembersForClass(evaluator, subtype, /* allowNarrowed */ true);
const tdEntry = entries.knownItems.get(literalKey.literalValue as string) ?? entries.extraItems; const tdEntry = entries.knownItems.get(literalKey.priv.literalValue as string) ?? entries.extraItems;
if (isPositiveTest) { if (isPositiveTest) {
if (!tdEntry) { if (!tdEntry) {
@ -2202,11 +2205,11 @@ function narrowTypeForTypedDictKey(
} }
const newNarrowedEntriesMap = new Map<string, TypedDictEntry>( const newNarrowedEntriesMap = new Map<string, TypedDictEntry>(
subtype.typedDictNarrowedEntries ?? [] subtype.priv.typedDictNarrowedEntries ?? []
); );
// Add the new entry. // Add the new entry.
newNarrowedEntriesMap.set(literalKey.literalValue as string, { newNarrowedEntriesMap.set(literalKey.priv.literalValue as string, {
valueType: tdEntry.valueType, valueType: tdEntry.valueType,
isReadOnly: tdEntry.isReadOnly, isReadOnly: tdEntry.isReadOnly,
isRequired: false, isRequired: false,
@ -2247,7 +2250,7 @@ export function narrowTypeForDiscriminatedDictEntryComparison(
const narrowedType = mapSubtypes(referenceType, (subtype) => { const narrowedType = mapSubtypes(referenceType, (subtype) => {
if (isClassInstance(subtype) && ClassType.isTypedDictClass(subtype)) { if (isClassInstance(subtype) && ClassType.isTypedDictClass(subtype)) {
const symbolMap = getTypedDictMembersForClass(evaluator, subtype); const symbolMap = getTypedDictMembersForClass(evaluator, subtype);
const tdEntry = symbolMap.knownItems.get(indexLiteralType.literalValue as string); const tdEntry = symbolMap.knownItems.get(indexLiteralType.priv.literalValue as string);
if (tdEntry && isLiteralTypeOrUnion(tdEntry.valueType)) { if (tdEntry && isLiteralTypeOrUnion(tdEntry.valueType)) {
if (isPositiveTest) { if (isPositiveTest) {
@ -2295,12 +2298,16 @@ export function narrowTypeForDiscriminatedTupleComparison(
isClassInstance(subtype) && isClassInstance(subtype) &&
ClassType.isTupleClass(subtype) && ClassType.isTupleClass(subtype) &&
!isUnboundedTupleClass(subtype) && !isUnboundedTupleClass(subtype) &&
typeof indexLiteralType.literalValue === 'number' && typeof indexLiteralType.priv.literalValue === 'number' &&
isClassInstance(literalType) isClassInstance(literalType)
) { ) {
const indexValue = indexLiteralType.literalValue; const indexValue = indexLiteralType.priv.literalValue;
if (subtype.tupleTypeArguments && indexValue >= 0 && indexValue < subtype.tupleTypeArguments.length) { if (
const tupleEntryType = subtype.tupleTypeArguments[indexValue]?.type; subtype.priv.tupleTypeArguments &&
indexValue >= 0 &&
indexValue < subtype.priv.tupleTypeArguments.length
) {
const tupleEntryType = subtype.priv.tupleTypeArguments[indexValue]?.type;
if (tupleEntryType && isLiteralTypeOrUnion(tupleEntryType)) { if (tupleEntryType && isLiteralTypeOrUnion(tupleEntryType)) {
if (isPositiveTest) { if (isPositiveTest) {
return evaluator.assignType(tupleEntryType, literalType) ? subtype : undefined; return evaluator.assignType(tupleEntryType, literalType) ? subtype : undefined;
@ -2343,8 +2350,8 @@ export function narrowTypeForDiscriminatedLiteralFieldComparison(
// Handle the case where the field is a property // Handle the case where the field is a property
// that has a declared literal return type for its getter. // that has a declared literal return type for its getter.
if (isClassInstance(subtype) && isClassInstance(memberType) && isProperty(memberType)) { if (isClassInstance(subtype) && isClassInstance(memberType) && isProperty(memberType)) {
const getterType = memberType.fgetInfo?.methodType; const getterType = memberType.priv.fgetInfo?.methodType;
if (getterType && getterType.details.declaredReturnType) { if (getterType && getterType.shared.declaredReturnType) {
const getterReturnType = FunctionType.getEffectiveReturnType(getterType); const getterReturnType = FunctionType.getEffectiveReturnType(getterType);
if (getterReturnType) { if (getterReturnType) {
memberType = getterReturnType; memberType = getterReturnType;
@ -2431,10 +2438,10 @@ function narrowTypeForTypeIs(evaluator: TypeEvaluator, type: Type, classType: Cl
return addConditionToType(ClassType.cloneAsInstance(classType), subtype.props?.condition); return addConditionToType(ClassType.cloneAsInstance(classType), subtype.props?.condition);
} }
if (!classType.includeSubclasses) { if (!classType.priv.includeSubclasses) {
return undefined; return undefined;
} }
} else if (!classType.includeSubclasses) { } else if (!classType.priv.includeSubclasses) {
// If the class if marked final and it matches, then // If the class if marked final and it matches, then
// we can eliminate it in the negative case. // we can eliminate it in the negative case.
if (matches && ClassType.isFinal(subtype)) { if (matches && ClassType.isFinal(subtype)) {
@ -2479,8 +2486,8 @@ function narrowTypeForClassComparison(
ClassType.isBuiltIn(concreteSubtype, 'type') ClassType.isBuiltIn(concreteSubtype, 'type')
) { ) {
concreteSubtype = concreteSubtype =
concreteSubtype.typeArguments && concreteSubtype.typeArguments.length > 0 concreteSubtype.priv.typeArguments && concreteSubtype.priv.typeArguments.length > 0
? convertToInstantiable(concreteSubtype.typeArguments[0]) ? convertToInstantiable(concreteSubtype.priv.typeArguments[0])
: UnknownType.create(); : UnknownType.create();
} }
@ -2502,11 +2509,11 @@ function narrowTypeForClassComparison(
/* isInstanceCheck */ false /* isInstanceCheck */ false
); );
if (!classType.includeSubclasses) { if (!classType.priv.includeSubclasses) {
// Handle the case where the LHS and RHS operands are specific // Handle the case where the LHS and RHS operands are specific
// classes, as opposed to types that represent classes and their // classes, as opposed to types that represent classes and their
// subclasses. // subclasses.
if (!concreteSubtype.includeSubclasses) { if (!concreteSubtype.priv.includeSubclasses) {
return ClassType.isSameGenericClass(concreteSubtype, classType) ? classType : undefined; return ClassType.isSameGenericClass(concreteSubtype, classType) ? classType : undefined;
} }
@ -2566,7 +2573,7 @@ function narrowTypeForLiteralComparison(
return subtype; return subtype;
} else if (isClassInstance(subtype) && ClassType.isSameGenericClass(literalType, subtype)) { } else if (isClassInstance(subtype) && ClassType.isSameGenericClass(literalType, subtype)) {
if (subtype.literalValue !== undefined) { if (subtype.priv.literalValue !== undefined) {
const literalValueMatches = ClassType.isLiteralValueSame(subtype, literalType); const literalValueMatches = ClassType.isLiteralValueSame(subtype, literalType);
if ((literalValueMatches && !isPositiveTest) || (!literalValueMatches && isPositiveTest)) { if ((literalValueMatches && !isPositiveTest) || (!literalValueMatches && isPositiveTest)) {
return undefined; return undefined;
@ -2607,9 +2614,7 @@ export function enumerateLiteralsForType(evaluator: TypeEvaluator, type: ClassTy
if (ClassType.isEnumClass(type)) { if (ClassType.isEnumClass(type)) {
// Enum expansion doesn't apply to enum classes that derive // Enum expansion doesn't apply to enum classes that derive
// from enum.Flag. // from enum.Flag.
if ( if (type.shared.baseClasses.some((baseClass) => isClass(baseClass) && ClassType.isBuiltIn(baseClass, 'Flag'))) {
type.details.baseClasses.some((baseClass) => isClass(baseClass) && ClassType.isBuiltIn(baseClass, 'Flag'))
) {
return undefined; return undefined;
} }
@ -2624,7 +2629,7 @@ export function enumerateLiteralsForType(evaluator: TypeEvaluator, type: ClassTy
if ( if (
isClassInstance(symbolType) && isClassInstance(symbolType) &&
ClassType.isSameGenericClass(type, symbolType) && ClassType.isSameGenericClass(type, symbolType) &&
symbolType.literalValue !== undefined symbolType.priv.literalValue !== undefined
) { ) {
enumList.push(symbolType); enumList.push(symbolType);
} }
@ -2680,7 +2685,7 @@ function narrowTypeForCallable(
// The type appears to not be callable. It's possible that the // The type appears to not be callable. It's possible that the
// two type is a subclass that is callable. We'll synthesize a // two type is a subclass that is callable. We'll synthesize a
// new intersection type. // new intersection type.
const className = `<callable subtype of ${subtype.details.name}>`; const className = `<callable subtype of ${subtype.shared.name}>`;
const fileInfo = getFileInfo(errorNode); const fileInfo = getFileInfo(errorNode);
let newClassType = ClassType.createInstantiable( let newClassType = ClassType.createInstantiable(
className, className,
@ -2690,10 +2695,10 @@ function narrowTypeForCallable(
ClassTypeFlags.None, ClassTypeFlags.None,
ParseTreeUtils.getTypeSourceId(errorNode), ParseTreeUtils.getTypeSourceId(errorNode),
/* declaredMetaclass */ undefined, /* declaredMetaclass */ undefined,
subtype.details.effectiveMetaclass, subtype.shared.effectiveMetaclass,
subtype.details.docString subtype.shared.docString
); );
newClassType.details.baseClasses = [ClassType.cloneAsInstantiable(subtype)]; newClassType.shared.baseClasses = [ClassType.cloneAsInstantiable(subtype)];
computeMroLinearization(newClassType); computeMroLinearization(newClassType);
newClassType = addConditionToType(newClassType, subtype.props?.condition) as ClassType; newClassType = addConditionToType(newClassType, subtype.props?.condition) as ClassType;
@ -2708,7 +2713,7 @@ function narrowTypeForCallable(
); );
FunctionType.addParameter(callMethod, selfParam); FunctionType.addParameter(callMethod, selfParam);
FunctionType.addDefaultParameters(callMethod); FunctionType.addDefaultParameters(callMethod);
callMethod.details.declaredReturnType = UnknownType.create(); callMethod.shared.declaredReturnType = UnknownType.create();
ClassType.getSymbolTable(newClassType).set( ClassType.getSymbolTable(newClassType).set(
'__call__', '__call__',
Symbol.createWithType(SymbolFlags.ClassMember, callMethod) Symbol.createWithType(SymbolFlags.ClassMember, callMethod)

View File

@ -127,8 +127,8 @@ export function printObjectTypeForClass(
const maxLiteralStringLength = 50; const maxLiteralStringLength = 50;
export function isLiteralValueTruncated(type: ClassType): boolean { export function isLiteralValueTruncated(type: ClassType): boolean {
if (typeof type.literalValue === 'string') { if (typeof type.priv.literalValue === 'string') {
if (type.literalValue.length > maxLiteralStringLength) { if (type.priv.literalValue.length > maxLiteralStringLength) {
return true; return true;
} }
} }
@ -137,16 +137,16 @@ export function isLiteralValueTruncated(type: ClassType): boolean {
} }
export function printLiteralValueTruncated(type: ClassType): string { export function printLiteralValueTruncated(type: ClassType): string {
if (type.details.name === 'bytes') { if (type.shared.name === 'bytes') {
return 'bytes'; return 'bytes';
} }
assert(type.details.name === 'str'); assert(type.shared.name === 'str');
return 'LiteralString'; return 'LiteralString';
} }
export function printLiteralValue(type: ClassType, quotation = "'"): string { export function printLiteralValue(type: ClassType, quotation = "'"): string {
const literalValue = type.literalValue; const literalValue = type.priv.literalValue;
if (literalValue === undefined) { if (literalValue === undefined) {
return ''; return '';
} }
@ -160,7 +160,7 @@ export function printLiteralValue(type: ClassType, quotation = "'"): string {
effectiveLiteralValue = literalValue.substring(0, maxLiteralStringLength) + '…'; effectiveLiteralValue = literalValue.substring(0, maxLiteralStringLength) + '…';
} }
if (type.details.name === 'bytes') { if (type.shared.name === 'bytes') {
let bytesString = ''; let bytesString = '';
// There's no good built-in conversion routine in javascript to convert // There's no good built-in conversion routine in javascript to convert
@ -277,10 +277,10 @@ function printTypeInternal(
isVariadicTypeVar(typeParam) && isVariadicTypeVar(typeParam) &&
isClassInstance(typeArg) && isClassInstance(typeArg) &&
isTupleClass(typeArg) && isTupleClass(typeArg) &&
typeArg.tupleTypeArguments && typeArg.priv.tupleTypeArguments &&
typeArg.tupleTypeArguments.every((typeArg) => !typeArg.isUnbounded) typeArg.priv.tupleTypeArguments.every((typeArg) => !typeArg.isUnbounded)
) { ) {
typeArg.tupleTypeArguments.forEach((tupleTypeArg) => { typeArg.priv.tupleTypeArguments.forEach((tupleTypeArg) => {
argumentStrings!.push( argumentStrings!.push(
printTypeInternal( printTypeInternal(
tupleTypeArg.type, tupleTypeArg.type,
@ -355,8 +355,8 @@ function printTypeInternal(
) { ) {
// If this is a recursive TypeVar, we've already expanded it once, so // If this is a recursive TypeVar, we've already expanded it once, so
// just print its name at this point. // just print its name at this point.
if (isTypeVar(type) && type.details.isSynthesized && type.details.recursiveTypeAliasName) { if (isTypeVar(type) && type.shared.isSynthesized && type.shared.recursiveAlias) {
return type.details.recursiveTypeAliasName; return type.shared.recursiveAlias.name;
} }
if (aliasInfo) { if (aliasInfo) {
@ -418,12 +418,12 @@ function printTypeInternal(
if (printTypeFlags & PrintTypeFlags.PythonSyntax) { if (printTypeFlags & PrintTypeFlags.PythonSyntax) {
return 'Any'; return 'Any';
} }
return `Module("${type.moduleName}")`; return `Module("${type.priv.moduleName}")`;
} }
case TypeCategory.Class: { case TypeCategory.Class: {
if (TypeBase.isInstance(type)) { if (TypeBase.isInstance(type)) {
if (type.literalValue !== undefined) { if (type.priv.literalValue !== undefined) {
if (isLiteralValueTruncated(type) && (printTypeFlags & PrintTypeFlags.PythonSyntax) !== 0) { if (isLiteralValueTruncated(type) && (printTypeFlags & PrintTypeFlags.PythonSyntax) !== 0) {
return printLiteralValueTruncated(type); return printLiteralValueTruncated(type);
} else { } else {
@ -442,7 +442,7 @@ function printTypeInternal(
} else { } else {
let typeToWrap: string; let typeToWrap: string;
if (type.literalValue !== undefined) { if (type.priv.literalValue !== undefined) {
if (isLiteralValueTruncated(type) && (printTypeFlags & PrintTypeFlags.PythonSyntax) !== 0) { if (isLiteralValueTruncated(type) && (printTypeFlags & PrintTypeFlags.PythonSyntax) !== 0) {
typeToWrap = printLiteralValueTruncated(type); typeToWrap = printLiteralValueTruncated(type);
} else { } else {
@ -550,18 +550,18 @@ function printTypeInternal(
: printTypeFlags; : printTypeFlags;
// Start by matching possible type aliases to the subtypes. // Start by matching possible type aliases to the subtypes.
if ((printTypeFlags & PrintTypeFlags.ExpandTypeAlias) === 0 && type.typeAliasSources) { if ((printTypeFlags & PrintTypeFlags.ExpandTypeAlias) === 0 && type.priv.typeAliasSources) {
for (const typeAliasSource of type.typeAliasSources) { for (const typeAliasSource of type.priv.typeAliasSources) {
let matchedAllSubtypes = true; let matchedAllSubtypes = true;
let allSubtypesPreviouslyHandled = true; let allSubtypesPreviouslyHandled = true;
const indicesCoveredByTypeAlias = new Set<number>(); const indicesCoveredByTypeAlias = new Set<number>();
for (const sourceSubtype of typeAliasSource.subtypes) { for (const sourceSubtype of typeAliasSource.priv.subtypes) {
let unionSubtypeIndex = 0; let unionSubtypeIndex = 0;
let foundMatch = false; let foundMatch = false;
const sourceSubtypeInstance = convertToInstance(sourceSubtype); const sourceSubtypeInstance = convertToInstance(sourceSubtype);
for (const unionSubtype of type.subtypes) { for (const unionSubtype of type.priv.subtypes) {
if (isTypeSame(sourceSubtypeInstance, unionSubtype)) { if (isTypeSame(sourceSubtypeInstance, unionSubtype)) {
if (!subtypeHandledSet.has(unionSubtypeIndex)) { if (!subtypeHandledSet.has(unionSubtypeIndex)) {
allSubtypesPreviouslyHandled = false; allSubtypesPreviouslyHandled = false;
@ -596,7 +596,7 @@ function printTypeInternal(
} }
} }
const noneIndex = type.subtypes.findIndex((subtype) => isNoneInstance(subtype)); const noneIndex = type.priv.subtypes.findIndex((subtype) => isNoneInstance(subtype));
if (noneIndex >= 0 && !subtypeHandledSet.has(noneIndex)) { if (noneIndex >= 0 && !subtypeHandledSet.has(noneIndex)) {
const typeWithoutNone = removeNoneFromUnion(type); const typeWithoutNone = removeNoneFromUnion(type);
if (isNever(typeWithoutNone)) { if (isNever(typeWithoutNone)) {
@ -627,7 +627,7 @@ function printTypeInternal(
const literalClassStrings = new Set<string>(); const literalClassStrings = new Set<string>();
doForEachSubtype(type, (subtype, index) => { doForEachSubtype(type, (subtype, index) => {
if (!subtypeHandledSet.has(index)) { if (!subtypeHandledSet.has(index)) {
if (isClassInstance(subtype) && subtype.literalValue !== undefined) { if (isClassInstance(subtype) && subtype.priv.literalValue !== undefined) {
if ( if (
isLiteralValueTruncated(subtype) && isLiteralValueTruncated(subtype) &&
(printTypeFlags & PrintTypeFlags.PythonSyntax) !== 0 (printTypeFlags & PrintTypeFlags.PythonSyntax) !== 0
@ -636,7 +636,7 @@ function printTypeInternal(
} else { } else {
literalObjectStrings.add(printLiteralValue(subtype)); literalObjectStrings.add(printLiteralValue(subtype));
} }
} else if (isInstantiableClass(subtype) && subtype.literalValue !== undefined) { } else if (isInstantiableClass(subtype) && subtype.priv.literalValue !== undefined) {
if ( if (
isLiteralValueTruncated(subtype) && isLiteralValueTruncated(subtype) &&
(printTypeFlags & PrintTypeFlags.PythonSyntax) !== 0 (printTypeFlags & PrintTypeFlags.PythonSyntax) !== 0
@ -695,15 +695,15 @@ function printTypeInternal(
// This will confuse users. The exception is if it's a bound synthesized // This will confuse users. The exception is if it's a bound synthesized
// type, in which case we'll print the bound type. This is used for // type, in which case we'll print the bound type. This is used for
// "self" and "cls" parameters. // "self" and "cls" parameters.
if (type.details.isSynthesized) { if (type.shared.isSynthesized) {
// If it's a synthesized type var used to implement recursive type // If it's a synthesized type var used to implement recursive type
// aliases, return the type alias name. // aliases, return the type alias name.
if (type.details.recursiveTypeAliasName) { if (type.shared.recursiveAlias) {
if ((printTypeFlags & PrintTypeFlags.ExpandTypeAlias) !== 0 && type.details.boundType) { if ((printTypeFlags & PrintTypeFlags.ExpandTypeAlias) !== 0 && type.shared.boundType) {
return printTypeInternal( return printTypeInternal(
TypeBase.isInstance(type) TypeBase.isInstance(type)
? convertToInstance(type.details.boundType) ? convertToInstance(type.shared.boundType)
: type.details.boundType, : type.shared.boundType,
printTypeFlags, printTypeFlags,
returnTypeCallback, returnTypeCallback,
uniqueNameMap, uniqueNameMap,
@ -711,15 +711,15 @@ function printTypeInternal(
recursionCount recursionCount
); );
} }
return type.details.recursiveTypeAliasName; return type.shared.recursiveAlias.name;
} }
// If it's a synthesized type var used to implement `self` or `cls` types, // If it's a synthesized type var used to implement `self` or `cls` types,
// print the type with a special character that indicates that the type // print the type with a special character that indicates that the type
// is internally represented as a TypeVar. // is internally represented as a TypeVar.
if (type.details.isSynthesizedSelf && type.details.boundType) { if (type.shared.isSynthesizedSelf && type.shared.boundType) {
let boundTypeString = printTypeInternal( let boundTypeString = printTypeInternal(
type.details.boundType, type.shared.boundType,
printTypeFlags & ~PrintTypeFlags.ExpandTypeAlias, printTypeFlags & ~PrintTypeFlags.ExpandTypeAlias,
returnTypeCallback, returnTypeCallback,
uniqueNameMap, uniqueNameMap,
@ -727,7 +727,7 @@ function printTypeInternal(
recursionCount recursionCount
); );
if (!isAnyOrUnknown(type.details.boundType)) { if (!isAnyOrUnknown(type.shared.boundType)) {
if (printTypeFlags & PrintTypeFlags.PythonSyntax) { if (printTypeFlags & PrintTypeFlags.PythonSyntax) {
boundTypeString = `Self`; boundTypeString = `Self`;
} else { } else {
@ -747,24 +747,24 @@ function printTypeInternal(
: 'Unknown'; : 'Unknown';
} }
if (type.details.isParamSpec) { if (type.shared.isParamSpec) {
const paramSpecText = _getReadableTypeVarName( const paramSpecText = _getReadableTypeVarName(
type, type,
(printTypeFlags & PrintTypeFlags.PythonSyntax) !== 0 (printTypeFlags & PrintTypeFlags.PythonSyntax) !== 0
); );
if (type.paramSpecAccess) { if (type.priv.paramSpecAccess) {
return `${paramSpecText}.${type.paramSpecAccess}`; return `${paramSpecText}.${type.priv.paramSpecAccess}`;
} }
return paramSpecText; return paramSpecText;
} }
let typeVarName = _getReadableTypeVarName(type, (printTypeFlags & PrintTypeFlags.PythonSyntax) !== 0); let typeVarName = _getReadableTypeVarName(type, (printTypeFlags & PrintTypeFlags.PythonSyntax) !== 0);
if (type.isVariadicUnpacked) { if (type.priv.isVariadicUnpacked) {
typeVarName = _printUnpack(typeVarName, printTypeFlags); typeVarName = _printUnpack(typeVarName, printTypeFlags);
} }
if (type.isVariadicInUnion) { if (type.priv.isVariadicInUnion) {
typeVarName = `Union[${typeVarName}]`; typeVarName = `Union[${typeVarName}]`;
} }
@ -772,7 +772,7 @@ function printTypeInternal(
typeVarName = `${_printNestedInstantiable(type, typeVarName)}`; typeVarName = `${_printNestedInstantiable(type, typeVarName)}`;
} }
if (!type.details.isVariadic && (printTypeFlags & PrintTypeFlags.PrintTypeVarVariance) !== 0) { if (!type.shared.isVariadic && (printTypeFlags & PrintTypeFlags.PrintTypeVarVariance) !== 0) {
const varianceText = _getTypeVarVarianceText(type); const varianceText = _getTypeVarVarianceText(type);
if (varianceText) { if (varianceText) {
typeVarName = `${typeVarName} (${varianceText})`; typeVarName = `${typeVarName} (${varianceText})`;
@ -783,12 +783,12 @@ function printTypeInternal(
} }
case TypeCategory.Never: { case TypeCategory.Never: {
return type.isNoReturn ? 'NoReturn' : 'Never'; return type.priv.isNoReturn ? 'NoReturn' : 'Never';
} }
case TypeCategory.Any: { case TypeCategory.Any: {
const anyType = type; const anyType = type;
return anyType.isEllipsis ? '...' : 'Any'; return anyType.priv.isEllipsis ? '...' : 'Any';
} }
} }
@ -812,12 +812,12 @@ function printFunctionType(
// Callable works only in cases where all parameters are positional-only. // Callable works only in cases where all parameters are positional-only.
let isPositionalParamsOnly = false; let isPositionalParamsOnly = false;
if (typeWithoutParamSpec.details.parameters.length === 0) { if (typeWithoutParamSpec.shared.parameters.length === 0) {
isPositionalParamsOnly = true; isPositionalParamsOnly = true;
} else { } else {
if (typeWithoutParamSpec.details.parameters.every((param) => param.category === ParameterCategory.Simple)) { if (typeWithoutParamSpec.shared.parameters.every((param) => param.category === ParameterCategory.Simple)) {
const lastParam = const lastParam =
typeWithoutParamSpec.details.parameters[typeWithoutParamSpec.details.parameters.length - 1]; typeWithoutParamSpec.shared.parameters[typeWithoutParamSpec.shared.parameters.length - 1];
if (!lastParam.name) { if (!lastParam.name) {
isPositionalParamsOnly = true; isPositionalParamsOnly = true;
} }
@ -840,7 +840,7 @@ function printFunctionType(
if (isPositionalParamsOnly) { if (isPositionalParamsOnly) {
const paramTypes: string[] = []; const paramTypes: string[] = [];
typeWithoutParamSpec.details.parameters.forEach((param, index) => { typeWithoutParamSpec.shared.parameters.forEach((param, index) => {
if (param.name) { if (param.name) {
const paramType = FunctionType.getEffectiveParameterType(typeWithoutParamSpec, index); const paramType = FunctionType.getEffectiveParameterType(typeWithoutParamSpec, index);
if (recursionTypes.length < maxTypeRecursionCount) { if (recursionTypes.length < maxTypeRecursionCount) {
@ -863,11 +863,11 @@ function printFunctionType(
if (paramSpec) { if (paramSpec) {
if (paramTypes.length > 0) { if (paramTypes.length > 0) {
return `Callable[Concatenate[${paramTypes.join(', ')}, ${ return `Callable[Concatenate[${paramTypes.join(', ')}, ${
paramSpec.details.name paramSpec.shared.name
}], ${returnTypeString}]`; }], ${returnTypeString}]`;
} }
return `Callable[${paramSpec.details.name}, ${returnTypeString}]`; return `Callable[${paramSpec.shared.name}, ${returnTypeString}]`;
} }
return `Callable[[${paramTypes.join(', ')}], ${returnTypeString}]`; return `Callable[[${paramTypes.join(', ')}], ${returnTypeString}]`;
@ -913,10 +913,10 @@ function printObjectTypeForClassInternal(
recursionTypes: Type[], recursionTypes: Type[],
recursionCount: number recursionCount: number
): string { ): string {
let objName = type.aliasName; let objName = type.priv.aliasName;
if (!objName) { if (!objName) {
objName = objName =
(printTypeFlags & PrintTypeFlags.UseFullyQualifiedNames) !== 0 ? type.details.fullName : type.details.name; (printTypeFlags & PrintTypeFlags.UseFullyQualifiedNames) !== 0 ? type.shared.fullName : type.shared.name;
} }
// Special-case NoneType to convert it to None. // Special-case NoneType to convert it to None.
@ -926,7 +926,7 @@ function printObjectTypeForClassInternal(
// Use the fully-qualified name if the name isn't unique. // Use the fully-qualified name if the name isn't unique.
if (!uniqueNameMap.isUnique(objName)) { if (!uniqueNameMap.isUnique(objName)) {
objName = type.details.fullName; objName = type.shared.fullName;
} }
// If this is a pseudo-generic class, don't display the type arguments // If this is a pseudo-generic class, don't display the type arguments
@ -934,12 +934,12 @@ function printObjectTypeForClassInternal(
if (!ClassType.isPseudoGenericClass(type)) { if (!ClassType.isPseudoGenericClass(type)) {
const typeParams = ClassType.getTypeParameters(type); const typeParams = ClassType.getTypeParameters(type);
const lastTypeParam = typeParams.length > 0 ? typeParams[typeParams.length - 1] : undefined; const lastTypeParam = typeParams.length > 0 ? typeParams[typeParams.length - 1] : undefined;
const isVariadic = lastTypeParam ? lastTypeParam.details.isVariadic : false; const isVariadic = lastTypeParam ? lastTypeParam.shared.isVariadic : false;
// If there is a type arguments array, it's a specialized class. // If there is a type arguments array, it's a specialized class.
const typeArgs: TupleTypeArgument[] | undefined = const typeArgs: TupleTypeArgument[] | undefined =
type.tupleTypeArguments ?? type.priv.tupleTypeArguments ??
type.typeArguments?.map((t) => { type.priv.typeArguments?.map((t) => {
return { type: t, isUnbounded: false }; return { type: t, isUnbounded: false };
}); });
if (typeArgs) { if (typeArgs) {
@ -952,13 +952,13 @@ function printObjectTypeForClassInternal(
const typeParam = index < typeParams.length ? typeParams[index] : undefined; const typeParam = index < typeParams.length ? typeParams[index] : undefined;
if ( if (
typeParam && typeParam &&
typeParam.details.isVariadic && typeParam.shared.isVariadic &&
isClassInstance(typeArg.type) && isClassInstance(typeArg.type) &&
ClassType.isBuiltIn(typeArg.type, 'tuple') && ClassType.isBuiltIn(typeArg.type, 'tuple') &&
typeArg.type.tupleTypeArguments typeArg.type.priv.tupleTypeArguments
) { ) {
// Expand the tuple type that maps to the variadic type parameter. // Expand the tuple type that maps to the variadic type parameter.
if (typeArg.type.tupleTypeArguments.length === 0) { if (typeArg.type.priv.tupleTypeArguments.length === 0) {
if (!isUnknown(typeArg.type)) { if (!isUnknown(typeArg.type)) {
isAllUnknown = false; isAllUnknown = false;
} }
@ -969,7 +969,7 @@ function printObjectTypeForClassInternal(
} else { } else {
appendArray( appendArray(
typeArgStrings, typeArgStrings,
typeArg.type.tupleTypeArguments.map((typeArg) => { typeArg.type.priv.tupleTypeArguments.map((typeArg) => {
if (!isUnknown(typeArg.type)) { if (!isUnknown(typeArg.type)) {
isAllUnknown = false; isAllUnknown = false;
} }
@ -1017,7 +1017,7 @@ function printObjectTypeForClassInternal(
} }
}); });
if (type.isUnpacked) { if (type.priv.isUnpacked) {
objName = _printUnpack(objName, printTypeFlags); objName = _printUnpack(objName, printTypeFlags);
} }
@ -1025,7 +1025,7 @@ function printObjectTypeForClassInternal(
objName += '[' + typeArgStrings.join(', ') + ']'; objName += '[' + typeArgStrings.join(', ') + ']';
} }
} else { } else {
if (type.isUnpacked) { if (type.priv.isUnpacked) {
objName = _printUnpack(objName, printTypeFlags); objName = _printUnpack(objName, printTypeFlags);
} }
@ -1034,7 +1034,7 @@ function printObjectTypeForClassInternal(
} }
} }
} else { } else {
if (type.isUnpacked) { if (type.priv.isUnpacked) {
objName = _printUnpack(objName, printTypeFlags); objName = _printUnpack(objName, printTypeFlags);
} }
@ -1064,7 +1064,7 @@ function printObjectTypeForClassInternal(
} }
// Wrap in a "Partial" for TypedDict that has been synthesized as partial. // Wrap in a "Partial" for TypedDict that has been synthesized as partial.
if (type.isTypedDictPartial) { if (type.priv.isTypedDictPartial) {
if ((printTypeFlags & PrintTypeFlags.PythonSyntax) === 0) { if ((printTypeFlags & PrintTypeFlags.PythonSyntax) === 0) {
objName = `Partial[${objName}]`; objName = `Partial[${objName}]`;
} }
@ -1083,7 +1083,7 @@ function printFunctionPartsInternal(
): [string[], string] { ): [string[], string] {
const paramTypeStrings: string[] = []; const paramTypeStrings: string[] = [];
let sawDefinedName = false; let sawDefinedName = false;
const functionNode = type.details.declaration?.node; const functionNode = type.shared.declaration?.node;
// Remove the (*args: P.args, **kwargs: P.kwargs) from the end of the parameter list. // Remove the (*args: P.args, **kwargs: P.kwargs) from the end of the parameter list.
const paramSpec = FunctionType.getParamSpecFromArgsKwargs(type); const paramSpec = FunctionType.getParamSpecFromArgsKwargs(type);
@ -1091,10 +1091,10 @@ function printFunctionPartsInternal(
type = FunctionType.cloneRemoveParamSpecArgsKwargs(type); type = FunctionType.cloneRemoveParamSpecArgsKwargs(type);
} }
type.details.parameters.forEach((param, index) => { type.shared.parameters.forEach((param, index) => {
// Handle specialized variadic type parameters specially. // Handle specialized variadic type parameters specially.
if ( if (
index === type.details.parameters.length - 1 && index === type.shared.parameters.length - 1 &&
param.category === ParameterCategory.ArgsList && param.category === ParameterCategory.ArgsList &&
isVariadicTypeVar(param.type) isVariadicTypeVar(param.type)
) { ) {
@ -1102,9 +1102,9 @@ function printFunctionPartsInternal(
if ( if (
isClassInstance(specializedParamType) && isClassInstance(specializedParamType) &&
ClassType.isBuiltIn(specializedParamType, 'tuple') && ClassType.isBuiltIn(specializedParamType, 'tuple') &&
specializedParamType.tupleTypeArguments specializedParamType.priv.tupleTypeArguments
) { ) {
specializedParamType.tupleTypeArguments.forEach((paramType) => { specializedParamType.priv.tupleTypeArguments.forEach((paramType) => {
const paramString = printTypeInternal( const paramString = printTypeInternal(
paramType.type, paramType.type,
printTypeFlags, printTypeFlags,
@ -1125,7 +1125,7 @@ function printFunctionPartsInternal(
printTypeFlags & PrintTypeFlags.ExpandTypedDictArgs && printTypeFlags & PrintTypeFlags.ExpandTypedDictArgs &&
param.type.category === TypeCategory.Class param.type.category === TypeCategory.Class
) { ) {
param.type.details.typedDictEntries!.knownItems.forEach((v, k) => { param.type.shared.typedDictEntries!.knownItems.forEach((v, k) => {
const valueTypeString = printTypeInternal( const valueTypeString = printTypeInternal(
v.valueType, v.valueType,
printTypeFlags, printTypeFlags,
@ -1303,14 +1303,14 @@ function _printNestedInstantiable(type: Type, textToWrap: string) {
function _getReadableTypeVarName(type: TypeVarType, usePythonSyntax: boolean) { function _getReadableTypeVarName(type: TypeVarType, usePythonSyntax: boolean) {
if (usePythonSyntax) { if (usePythonSyntax) {
return type.details.name; return type.shared.name;
} }
return TypeVarType.getReadableName(type); return TypeVarType.getReadableName(type);
} }
function _getTypeVarVarianceText(type: TypeVarType) { function _getTypeVarVarianceText(type: TypeVarType) {
const computedVariance = type.computedVariance ?? type.details.declaredVariance; const computedVariance = type.priv.computedVariance ?? type.shared.declaredVariance;
if (computedVariance === Variance.Invariant) { if (computedVariance === Variance.Invariant) {
return 'invariant'; return 'invariant';
} }
@ -1380,7 +1380,7 @@ class UniqueNameMap {
switch (type.category) { switch (type.category) {
case TypeCategory.Function: { case TypeCategory.Function: {
type.details.parameters.forEach((_, index) => { type.shared.parameters.forEach((_, index) => {
const paramType = FunctionType.getEffectiveParameterType(type, index); const paramType = FunctionType.getEffectiveParameterType(type, index);
this.build(paramType, recursionTypes, recursionCount); this.build(paramType, recursionTypes, recursionCount);
}); });
@ -1391,34 +1391,34 @@ class UniqueNameMap {
} }
case TypeCategory.OverloadedFunction: { case TypeCategory.OverloadedFunction: {
type.overloads.forEach((overload) => { type.priv.overloads.forEach((overload) => {
this.build(overload, recursionTypes, recursionCount); this.build(overload, recursionTypes, recursionCount);
}); });
break; break;
} }
case TypeCategory.Class: { case TypeCategory.Class: {
if (type.literalValue !== undefined) { if (type.priv.literalValue !== undefined) {
break; break;
} }
let className = type.aliasName; let className = type.priv.aliasName;
if (!className) { if (!className) {
className = className =
(this._printTypeFlags & PrintTypeFlags.UseFullyQualifiedNames) !== 0 (this._printTypeFlags & PrintTypeFlags.UseFullyQualifiedNames) !== 0
? type.details.fullName ? type.shared.fullName
: type.details.name; : type.shared.name;
} }
this._addIfUnique(className, type); this._addIfUnique(className, type);
if (!ClassType.isPseudoGenericClass(type)) { if (!ClassType.isPseudoGenericClass(type)) {
if (type.tupleTypeArguments) { if (type.priv.tupleTypeArguments) {
type.tupleTypeArguments.forEach((typeArg) => { type.priv.tupleTypeArguments.forEach((typeArg) => {
this.build(typeArg.type, recursionTypes, recursionCount); this.build(typeArg.type, recursionTypes, recursionCount);
}); });
} else if (type.typeArguments) { } else if (type.priv.typeArguments) {
type.typeArguments.forEach((typeArg) => { type.priv.typeArguments.forEach((typeArg) => {
this.build(typeArg, recursionTypes, recursionCount); this.build(typeArg, recursionTypes, recursionCount);
}); });
} }
@ -1431,7 +1431,7 @@ class UniqueNameMap {
this.build(subtype, recursionTypes, recursionCount); this.build(subtype, recursionTypes, recursionCount);
}); });
type.typeAliasSources?.forEach((typeAliasSource) => { type.priv.typeAliasSources?.forEach((typeAliasSource) => {
this.build(typeAliasSource, recursionTypes, recursionCount); this.build(typeAliasSource, recursionTypes, recursionCount);
}); });
break; break;

File diff suppressed because it is too large Load Diff

View File

@ -269,8 +269,8 @@ export class TypeVarSignatureContext {
// If this union has a very large number of subtypes, don't bother // If this union has a very large number of subtypes, don't bother
// accurately computing the score. Assume a fixed value. // accurately computing the score. Assume a fixed value.
if (type.subtypes.length < 16) { if (type.priv.subtypes.length < 16) {
type.subtypes.forEach((subtype) => { type.priv.subtypes.forEach((subtype) => {
const subtypeScore = this._getComplexityScoreForType(subtype, recursionCount); const subtypeScore = this._getComplexityScoreForType(subtype, recursionCount);
maxScore = Math.max(maxScore, subtypeScore); maxScore = Math.max(maxScore, subtypeScore);
}); });
@ -294,18 +294,18 @@ export class TypeVarSignatureContext {
let typeArgScoreSum = 0; let typeArgScoreSum = 0;
let typeArgCount = 0; let typeArgCount = 0;
if (classType.tupleTypeArguments) { if (classType.priv.tupleTypeArguments) {
classType.tupleTypeArguments.forEach((typeArg) => { classType.priv.tupleTypeArguments.forEach((typeArg) => {
typeArgScoreSum += this._getComplexityScoreForType(typeArg.type, recursionCount); typeArgScoreSum += this._getComplexityScoreForType(typeArg.type, recursionCount);
typeArgCount++; typeArgCount++;
}); });
} else if (classType.typeArguments) { } else if (classType.priv.typeArguments) {
classType.typeArguments.forEach((type) => { classType.priv.typeArguments.forEach((type) => {
typeArgScoreSum += this._getComplexityScoreForType(type, recursionCount); typeArgScoreSum += this._getComplexityScoreForType(type, recursionCount);
typeArgCount++; typeArgCount++;
}); });
} else if (classType.details.typeParameters) { } else if (classType.shared.typeParameters) {
classType.details.typeParameters.forEach((type) => { classType.shared.typeParameters.forEach((type) => {
typeArgScoreSum += this._getComplexityScoreForType(AnyType.create(), recursionCount); typeArgScoreSum += this._getComplexityScoreForType(AnyType.create(), recursionCount);
typeArgCount++; typeArgCount++;
}); });

View File

@ -137,9 +137,9 @@ export class TypeWalker {
} }
visitFunction(type: FunctionType): void { visitFunction(type: FunctionType): void {
for (let i = 0; i < type.details.parameters.length; i++) { for (let i = 0; i < type.shared.parameters.length; i++) {
// Ignore parameters such as "*" that have no name. // Ignore parameters such as "*" that have no name.
if (type.details.parameters[i].name) { if (type.shared.parameters[i].name) {
const paramType = FunctionType.getEffectiveParameterType(type, i); const paramType = FunctionType.getEffectiveParameterType(type, i);
this.walk(paramType); this.walk(paramType);
if (this._isWalkCanceled) { if (this._isWalkCanceled) {
@ -149,7 +149,7 @@ export class TypeWalker {
} }
if (!this._isWalkCanceled && !FunctionType.isParamSpecValue(type) && !FunctionType.isParamSpecValue(type)) { if (!this._isWalkCanceled && !FunctionType.isParamSpecValue(type) && !FunctionType.isParamSpecValue(type)) {
const returnType = type.details.declaredReturnType ?? type.inferredReturnType; const returnType = type.shared.declaredReturnType ?? type.priv.inferredReturnType;
if (returnType) { if (returnType) {
this.walk(returnType); this.walk(returnType);
} }
@ -157,7 +157,7 @@ export class TypeWalker {
} }
visitOverloadedFunction(type: OverloadedFunctionType): void { visitOverloadedFunction(type: OverloadedFunctionType): void {
for (const overload of type.overloads) { for (const overload of type.priv.overloads) {
this.walk(overload); this.walk(overload);
if (this._isWalkCanceled) { if (this._isWalkCanceled) {
break; break;
@ -167,7 +167,7 @@ export class TypeWalker {
visitClass(type: ClassType): void { visitClass(type: ClassType): void {
if (!ClassType.isPseudoGenericClass(type)) { if (!ClassType.isPseudoGenericClass(type)) {
const typeArgs = type.tupleTypeArguments?.map((t) => t.type) || type.typeArguments; const typeArgs = type.priv.tupleTypeArguments?.map((t) => t.type) || type.priv.typeArguments;
if (typeArgs) { if (typeArgs) {
for (const argType of typeArgs) { for (const argType of typeArgs) {
this.walk(argType); this.walk(argType);
@ -184,7 +184,7 @@ export class TypeWalker {
} }
visitUnion(type: UnionType): void { visitUnion(type: UnionType): void {
for (const subtype of type.subtypes) { for (const subtype of type.priv.subtypes) {
this.walk(subtype); this.walk(subtype);
if (this._isWalkCanceled) { if (this._isWalkCanceled) {
break; break;

View File

@ -109,9 +109,9 @@ export function createTypedDictType(
ClassTypeFlags.TypedDictClass | ClassTypeFlags.ValidTypeAliasClass, ClassTypeFlags.TypedDictClass | ClassTypeFlags.ValidTypeAliasClass,
ParseTreeUtils.getTypeSourceId(errorNode), ParseTreeUtils.getTypeSourceId(errorNode),
/* declaredMetaclass */ undefined, /* declaredMetaclass */ undefined,
typedDictClass.details.effectiveMetaclass typedDictClass.shared.effectiveMetaclass
); );
classType.details.baseClasses.push(typedDictClass); classType.shared.baseClasses.push(typedDictClass);
computeMroLinearization(classType); computeMroLinearization(classType);
const classFields = ClassType.getSymbolTable(classType); const classFields = ClassType.getSymbolTable(classType);
@ -195,11 +195,11 @@ export function createTypedDictType(
arg.valueExpression || errorNode arg.valueExpression || errorNode
); );
} else if (arg.name.value === 'total' && arg.valueExpression.constType === KeywordType.False) { } else if (arg.name.value === 'total' && arg.valueExpression.constType === KeywordType.False) {
classType.details.flags |= ClassTypeFlags.CanOmitDictValues; classType.shared.flags |= ClassTypeFlags.CanOmitDictValues;
} else if (arg.name.value === 'closed' && arg.valueExpression.constType === KeywordType.True) { } else if (arg.name.value === 'closed' && arg.valueExpression.constType === KeywordType.True) {
// This is an experimental feature because PEP 728 hasn't been accepted yet. // This is an experimental feature because PEP 728 hasn't been accepted yet.
if (AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.enableExperimentalFeatures) { if (AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.enableExperimentalFeatures) {
classType.details.flags |= classType.shared.flags |=
ClassTypeFlags.TypedDictMarkedClosed | ClassTypeFlags.TypedDictEffectivelyClosed; ClassTypeFlags.TypedDictMarkedClosed | ClassTypeFlags.TypedDictEffectivelyClosed;
} }
} }
@ -250,8 +250,8 @@ export function synthesizeTypedDictClassMethods(
FunctionParam.create(ParameterCategory.Simple, classType, FunctionParamFlags.TypeDeclared, 'cls') FunctionParam.create(ParameterCategory.Simple, classType, FunctionParamFlags.TypeDeclared, 'cls')
); );
FunctionType.addDefaultParameters(newType); FunctionType.addDefaultParameters(newType);
newType.details.declaredReturnType = ClassType.cloneAsInstance(classType); newType.shared.declaredReturnType = ClassType.cloneAsInstance(classType);
newType.constructorTypeVarScopeId = getTypeVarScopeId(classType); newType.priv.constructorTypeVarScopeId = getTypeVarScopeId(classType);
// Synthesize an __init__ method with two overrides. // Synthesize an __init__ method with two overrides.
const initOverride1 = FunctionType.createSynthesizedInstance('__init__', FunctionTypeFlags.Overloaded); const initOverride1 = FunctionType.createSynthesizedInstance('__init__', FunctionTypeFlags.Overloaded);
@ -264,8 +264,8 @@ export function synthesizeTypedDictClassMethods(
'self' 'self'
) )
); );
initOverride1.details.declaredReturnType = evaluator.getNoneType(); initOverride1.shared.declaredReturnType = evaluator.getNoneType();
initOverride1.constructorTypeVarScopeId = getTypeVarScopeId(classType); initOverride1.priv.constructorTypeVarScopeId = getTypeVarScopeId(classType);
// The first parameter must be positional-only. // The first parameter must be positional-only.
FunctionType.addParameter( FunctionType.addParameter(
@ -292,8 +292,8 @@ export function synthesizeTypedDictClassMethods(
'self' 'self'
) )
); );
initOverride2.details.declaredReturnType = evaluator.getNoneType(); initOverride2.shared.declaredReturnType = evaluator.getNoneType();
initOverride2.constructorTypeVarScopeId = getTypeVarScopeId(classType); initOverride2.priv.constructorTypeVarScopeId = getTypeVarScopeId(classType);
// All parameters must be named, so insert an empty "*". // All parameters must be named, so insert an empty "*".
FunctionType.addKeywordOnlyParameterSeparator(initOverride2); FunctionType.addKeywordOnlyParameterSeparator(initOverride2);
@ -372,8 +372,8 @@ export function synthesizeTypedDictClassMethods(
let defaultTypeVar = TypeVarType.createInstance(`__TDefault`); let defaultTypeVar = TypeVarType.createInstance(`__TDefault`);
defaultTypeVar = TypeVarType.cloneForScopeId( defaultTypeVar = TypeVarType.cloneForScopeId(
defaultTypeVar, defaultTypeVar,
func.details.typeVarScopeId!, func.shared.typeVarScopeId!,
classType.details.name, classType.shared.name,
TypeVarScopeType.Function TypeVarScopeType.Function
); );
return defaultTypeVar; return defaultTypeVar;
@ -388,7 +388,7 @@ export function synthesizeTypedDictClassMethods(
) { ) {
const getOverload = FunctionType.createSynthesizedInstance('get', FunctionTypeFlags.Overloaded); const getOverload = FunctionType.createSynthesizedInstance('get', FunctionTypeFlags.Overloaded);
FunctionType.addParameter(getOverload, selfParam); FunctionType.addParameter(getOverload, selfParam);
getOverload.details.typeVarScopeId = ParseTreeUtils.getScopeIdForNode(node); getOverload.shared.typeVarScopeId = ParseTreeUtils.getScopeIdForNode(node);
FunctionType.addParameter( FunctionType.addParameter(
getOverload, getOverload,
FunctionParam.create(ParameterCategory.Simple, keyType, FunctionParamFlags.TypeDeclared, 'k') FunctionParam.create(ParameterCategory.Simple, keyType, FunctionParamFlags.TypeDeclared, 'k')
@ -423,9 +423,9 @@ export function synthesizeTypedDictClassMethods(
'default' 'default'
) )
); );
getOverload.details.declaredReturnType = returnType; getOverload.shared.declaredReturnType = returnType;
} else { } else {
getOverload.details.declaredReturnType = isEntryRequired getOverload.shared.declaredReturnType = isEntryRequired
? valueType ? valueType
: combineTypes([valueType, evaluator.getNoneType()]); : combineTypes([valueType, evaluator.getNoneType()]);
} }
@ -443,12 +443,12 @@ export function synthesizeTypedDictClassMethods(
const popOverload1 = FunctionType.createSynthesizedInstance('pop', FunctionTypeFlags.Overloaded); const popOverload1 = FunctionType.createSynthesizedInstance('pop', FunctionTypeFlags.Overloaded);
FunctionType.addParameter(popOverload1, selfParam); FunctionType.addParameter(popOverload1, selfParam);
FunctionType.addParameter(popOverload1, keyParam); FunctionType.addParameter(popOverload1, keyParam);
popOverload1.details.declaredReturnType = valueType; popOverload1.shared.declaredReturnType = valueType;
const popOverload2 = FunctionType.createSynthesizedInstance('pop', FunctionTypeFlags.Overloaded); const popOverload2 = FunctionType.createSynthesizedInstance('pop', FunctionTypeFlags.Overloaded);
FunctionType.addParameter(popOverload2, selfParam); FunctionType.addParameter(popOverload2, selfParam);
FunctionType.addParameter(popOverload2, keyParam); FunctionType.addParameter(popOverload2, keyParam);
popOverload2.details.typeVarScopeId = ParseTreeUtils.getScopeIdForNode(node); popOverload2.shared.typeVarScopeId = ParseTreeUtils.getScopeIdForNode(node);
const defaultTypeVar = createDefaultTypeVar(popOverload2); const defaultTypeVar = createDefaultTypeVar(popOverload2);
let defaultParamType: Type; let defaultParamType: Type;
@ -474,7 +474,7 @@ export function synthesizeTypedDictClassMethods(
defaultParamType defaultParamType
) )
); );
popOverload2.details.declaredReturnType = returnType; popOverload2.shared.declaredReturnType = returnType;
return [popOverload1, popOverload2]; return [popOverload1, popOverload2];
} }
@ -492,7 +492,7 @@ export function synthesizeTypedDictClassMethods(
setDefaultOverload, setDefaultOverload,
FunctionParam.create(ParameterCategory.Simple, valueType, FunctionParamFlags.TypeDeclared, 'default') FunctionParam.create(ParameterCategory.Simple, valueType, FunctionParamFlags.TypeDeclared, 'default')
); );
setDefaultOverload.details.declaredReturnType = valueType; setDefaultOverload.shared.declaredReturnType = valueType;
return setDefaultOverload; return setDefaultOverload;
} }
@ -503,7 +503,7 @@ export function synthesizeTypedDictClassMethods(
delItemOverload, delItemOverload,
FunctionParam.create(ParameterCategory.Simple, keyType, FunctionParamFlags.TypeDeclared, 'k') FunctionParam.create(ParameterCategory.Simple, keyType, FunctionParamFlags.TypeDeclared, 'k')
); );
delItemOverload.details.declaredReturnType = evaluator.getNoneType(); delItemOverload.shared.declaredReturnType = evaluator.getNoneType();
return delItemOverload; return delItemOverload;
} }
@ -536,9 +536,9 @@ export function synthesizeTypedDictClassMethods(
FunctionType.addPositionOnlyParameterSeparator(updateMethod1); FunctionType.addPositionOnlyParameterSeparator(updateMethod1);
FunctionType.addKeywordOnlyParameterSeparator(updateMethod3); FunctionType.addKeywordOnlyParameterSeparator(updateMethod3);
updateMethod1.details.declaredReturnType = evaluator.getNoneType(); updateMethod1.shared.declaredReturnType = evaluator.getNoneType();
updateMethod2.details.declaredReturnType = evaluator.getNoneType(); updateMethod2.shared.declaredReturnType = evaluator.getNoneType();
updateMethod3.details.declaredReturnType = evaluator.getNoneType(); updateMethod3.shared.declaredReturnType = evaluator.getNoneType();
const tuplesToCombine: Type[] = []; const tuplesToCombine: Type[] = [];
const tupleClass = evaluator.getBuiltInType(node, 'tuple'); const tupleClass = evaluator.getBuiltInType(node, 'tuple');
@ -687,7 +687,7 @@ export function synthesizeTypedDictClassMethods(
if (dictValueType) { if (dictValueType) {
const clearMethod = FunctionType.createSynthesizedInstance('clear'); const clearMethod = FunctionType.createSynthesizedInstance('clear');
FunctionType.addParameter(clearMethod, selfParam); FunctionType.addParameter(clearMethod, selfParam);
clearMethod.details.declaredReturnType = evaluator.getNoneType(); clearMethod.shared.declaredReturnType = evaluator.getNoneType();
symbolTable.set('clear', Symbol.createWithType(SymbolFlags.ClassMember, clearMethod)); symbolTable.set('clear', Symbol.createWithType(SymbolFlags.ClassMember, clearMethod));
const popItemMethod = FunctionType.createSynthesizedInstance('popitem'); const popItemMethod = FunctionType.createSynthesizedInstance('popitem');
@ -707,7 +707,7 @@ export function synthesizeTypedDictClassMethods(
tupleType = UnknownType.create(); tupleType = UnknownType.create();
} }
popItemMethod.details.declaredReturnType = tupleType; popItemMethod.shared.declaredReturnType = tupleType;
symbolTable.set('popitem', Symbol.createWithType(SymbolFlags.ClassMember, popItemMethod)); symbolTable.set('popitem', Symbol.createWithType(SymbolFlags.ClassMember, popItemMethod));
} }
@ -724,9 +724,9 @@ export function synthesizeTypedDictClassMethods(
if ( if (
returnTypeClass && returnTypeClass &&
isInstantiableClass(returnTypeClass) && isInstantiableClass(returnTypeClass) &&
returnTypeClass.details.typeParameters.length === 2 returnTypeClass.shared.typeParameters.length === 2
) { ) {
method.details.declaredReturnType = ClassType.cloneForSpecialization( method.shared.declaredReturnType = ClassType.cloneForSpecialization(
ClassType.cloneAsInstance(returnTypeClass), ClassType.cloneAsInstance(returnTypeClass),
[strType, mappingValueType], [strType, mappingValueType],
/* isTypeArgumentExplicit */ true /* isTypeArgumentExplicit */ true
@ -745,7 +745,7 @@ export function getTypedDictMembersForClass(
allowNarrowed = false allowNarrowed = false
): TypedDictEntries { ): TypedDictEntries {
// Were the entries already calculated and cached? // Were the entries already calculated and cached?
if (!classType.details.typedDictEntries) { if (!classType.shared.typedDictEntries) {
const entries: TypedDictEntries = { const entries: TypedDictEntries = {
knownItems: new Map<string, TypedDictEntry>(), knownItems: new Map<string, TypedDictEntry>(),
extraItems: undefined, extraItems: undefined,
@ -762,20 +762,20 @@ export function getTypedDictMembersForClass(
} }
// Cache the entries for next time. // Cache the entries for next time.
classType.details.typedDictEntries = entries; classType.shared.typedDictEntries = entries;
} }
const typeVarContext = buildTypeVarContextFromSpecializedClass(classType); const typeVarContext = buildTypeVarContextFromSpecializedClass(classType);
// Create a specialized copy of the entries so the caller can mutate them. // Create a specialized copy of the entries so the caller can mutate them.
const entries = new Map<string, TypedDictEntry>(); const entries = new Map<string, TypedDictEntry>();
classType.details.typedDictEntries!.knownItems.forEach((value, key) => { classType.shared.typedDictEntries!.knownItems.forEach((value, key) => {
const tdEntry = { ...value }; const tdEntry = { ...value };
tdEntry.valueType = applySolvedTypeVars(tdEntry.valueType, typeVarContext); tdEntry.valueType = applySolvedTypeVars(tdEntry.valueType, typeVarContext);
// If the class is "Partial", make all entries optional and convert all // If the class is "Partial", make all entries optional and convert all
// read-only entries to Never. // read-only entries to Never.
if (classType.isTypedDictPartial) { if (classType.priv.isTypedDictPartial) {
tdEntry.isRequired = false; tdEntry.isRequired = false;
if (tdEntry.isReadOnly) { if (tdEntry.isReadOnly) {
@ -789,8 +789,8 @@ export function getTypedDictMembersForClass(
}); });
// Apply narrowed types on top of existing entries if present. // Apply narrowed types on top of existing entries if present.
if (allowNarrowed && classType.typedDictNarrowedEntries) { if (allowNarrowed && classType.priv.typedDictNarrowedEntries) {
classType.typedDictNarrowedEntries.forEach((value, key) => { classType.priv.typedDictNarrowedEntries.forEach((value, key) => {
const tdEntry = { ...value }; const tdEntry = { ...value };
tdEntry.valueType = applySolvedTypeVars(tdEntry.valueType, typeVarContext); tdEntry.valueType = applySolvedTypeVars(tdEntry.valueType, typeVarContext);
entries.set(key, tdEntry); entries.set(key, tdEntry);
@ -799,7 +799,7 @@ export function getTypedDictMembersForClass(
return { return {
knownItems: entries, knownItems: entries,
extraItems: classType.details.typedDictEntries?.extraItems, extraItems: classType.shared.typedDictEntries?.extraItems,
}; };
} }
@ -976,7 +976,7 @@ function getTypedDictMembersForClassRecursive(
} }
recursionCount++; recursionCount++;
classType.details.baseClasses.forEach((baseClassType) => { classType.shared.baseClasses.forEach((baseClassType) => {
if (isInstantiableClass(baseClassType) && ClassType.isTypedDictClass(baseClassType)) { if (isInstantiableClass(baseClassType) && ClassType.isTypedDictClass(baseClassType)) {
const specializedBaseClassType = partiallySpecializeType(baseClassType, classType); const specializedBaseClassType = partiallySpecializeType(baseClassType, classType);
assert(isClass(specializedBaseClassType)); assert(isClass(specializedBaseClassType));
@ -1045,8 +1045,8 @@ export function getEffectiveExtraItemsEntryType(evaluator: TypeEvaluator, classT
}; };
} }
if (classType.details.typedDictEntries?.extraItems) { if (classType.shared.typedDictEntries?.extraItems) {
return classType.details.typedDictEntries.extraItems; return classType.shared.typedDictEntries.extraItems;
} }
return { return {
@ -1275,11 +1275,11 @@ export function assignToTypedDict(
let typeVarContext: TypeVarContext | undefined; let typeVarContext: TypeVarContext | undefined;
let genericClassType = classType; let genericClassType = classType;
if (classType.details.typeParameters.length > 0) { if (classType.shared.typeParameters.length > 0) {
typeVarContext = new TypeVarContext(getTypeVarScopeId(classType)); typeVarContext = new TypeVarContext(getTypeVarScopeId(classType));
// Create a generic (nonspecialized version) of the class. // Create a generic (nonspecialized version) of the class.
if (classType.typeArguments) { if (classType.priv.typeArguments) {
genericClassType = ClassType.cloneForSpecialization( genericClassType = ClassType.cloneForSpecialization(
classType, classType,
/* typeArguments */ undefined, /* typeArguments */ undefined,
@ -1295,7 +1295,7 @@ export function assignToTypedDict(
if (!isClassInstance(keyType) || !ClassType.isBuiltIn(keyType, 'str') || !isLiteralType(keyType)) { if (!isClassInstance(keyType) || !ClassType.isBuiltIn(keyType, 'str') || !isLiteralType(keyType)) {
isMatch = false; isMatch = false;
} else { } else {
const keyValue = keyType.literalValue as string; const keyValue = keyType.priv.literalValue as string;
const symbolEntry = tdEntries.knownItems.get(keyValue); const symbolEntry = tdEntries.knownItems.get(keyValue);
if (!symbolEntry) { if (!symbolEntry) {
@ -1330,7 +1330,7 @@ export function assignToTypedDict(
const subDiag = diagAddendum?.createAddendum(); const subDiag = diagAddendum?.createAddendum();
subDiag.addMessage( subDiag.addMessage(
LocAddendum.typedDictFieldUndefined().format({ LocAddendum.typedDictFieldUndefined().format({
name: keyType.literalValue as string, name: keyType.priv.literalValue as string,
type: evaluator.printType(ClassType.cloneAsInstance(classType)), type: evaluator.printType(ClassType.cloneAsInstance(classType)),
}) })
); );
@ -1354,7 +1354,7 @@ export function assignToTypedDict(
if (subDiag) { if (subDiag) {
subDiag.addMessage( subDiag.addMessage(
LocAddendum.typedDictFieldTypeMismatch().format({ LocAddendum.typedDictFieldTypeMismatch().format({
name: keyType.literalValue as string, name: keyType.priv.literalValue as string,
type: evaluator.printType(valueTypes[index].type), type: evaluator.printType(valueTypes[index].type),
}) })
); );
@ -1443,14 +1443,14 @@ export function getTypeOfIndexedTypedDict(
} }
if (isClassInstance(subtype) && ClassType.isBuiltIn(subtype, 'str')) { if (isClassInstance(subtype) && ClassType.isBuiltIn(subtype, 'str')) {
if (subtype.literalValue === undefined) { if (subtype.priv.literalValue === undefined) {
// If it's a plain str with no literal value, we can't // If it's a plain str with no literal value, we can't
// make any determination about the resulting type. // make any determination about the resulting type.
return UnknownType.create(); return UnknownType.create();
} }
// Look up the entry in the typed dict to get its type. // Look up the entry in the typed dict to get its type.
const entryName = subtype.literalValue as string; const entryName = subtype.priv.literalValue as string;
const entry = entries.knownItems.get(entryName) ?? entries.extraItems; const entry = entries.knownItems.get(entryName) ?? entries.extraItems;
if (!entry) { if (!entry) {
diag.addMessage( diag.addMessage(
@ -1533,22 +1533,22 @@ export function narrowForKeyAssignment(classType: ClassType, key: string) {
// We should never be called if the classType is not a TypedDict or if typedDictEntries // We should never be called if the classType is not a TypedDict or if typedDictEntries
// is empty, but this can theoretically happen in the presence of certain circular // is empty, but this can theoretically happen in the presence of certain circular
// dependencies. // dependencies.
if (!ClassType.isTypedDictClass(classType) || !classType.details.typedDictEntries) { if (!ClassType.isTypedDictClass(classType) || !classType.shared.typedDictEntries) {
return classType; return classType;
} }
const tdEntry = classType.details.typedDictEntries.knownItems.get(key); const tdEntry = classType.shared.typedDictEntries.knownItems.get(key);
if (!tdEntry || tdEntry.isRequired) { if (!tdEntry || tdEntry.isRequired) {
return classType; return classType;
} }
const narrowedTdEntry = classType.typedDictNarrowedEntries?.get(key); const narrowedTdEntry = classType.priv.typedDictNarrowedEntries?.get(key);
if (narrowedTdEntry?.isProvided) { if (narrowedTdEntry?.isProvided) {
return classType; return classType;
} }
const narrowedEntries = classType.typedDictNarrowedEntries const narrowedEntries = classType.priv.typedDictNarrowedEntries
? new Map<string, TypedDictEntry>(classType.typedDictNarrowedEntries) ? new Map<string, TypedDictEntry>(classType.priv.typedDictNarrowedEntries)
: new Map<string, TypedDictEntry>(); : new Map<string, TypedDictEntry>();
narrowedEntries.set(key, { narrowedEntries.set(key, {
isProvided: true, isProvided: true,

File diff suppressed because it is too large Load Diff

View File

@ -20,7 +20,7 @@ import {
TypeBase, TypeBase,
TypeCategory, TypeCategory,
TypeFlags, TypeFlags,
TypeVarDetails, TypeVarDetailsShared,
TypeVarType, TypeVarType,
Variance, Variance,
} from '../analyzer/types'; } from '../analyzer/types';
@ -337,15 +337,15 @@ function getTypeEvaluatorString(
if (!isNumber(value) && !isString(value)) { if (!isNumber(value) && !isString(value)) {
if (set.has(value)) { if (set.has(value)) {
if (isClassType(value)) { if (isClassType(value)) {
return `<cycle> class '${value.details.fullName}' typeSourceId:${value.details.typeSourceId}`; return `<cycle> class '${value.shared.fullName}' typeSourceId:${value.shared.typeSourceId}`;
} }
if (isFunctionType(value)) { if (isFunctionType(value)) {
return `<cycle> function '${value.details.fullName}' parameter count:${value.details.parameters.length}`; return `<cycle> function '${value.shared.fullName}' parameter count:${value.shared.parameters.length}`;
} }
if (isTypeVarType(value)) { if (isTypeVarType(value)) {
return `<cycle> function '${value.details.name}' scope id:${value.nameWithScope}`; return `<cycle> function '${value.shared.name}' scope id:${value.priv.nameWithScope}`;
} }
return undefined; return undefined;
@ -417,7 +417,7 @@ function getTypeEvaluatorString(
return isTypeBase(type) && type.details && isTypeVarDetails(type.details); return isTypeBase(type) && type.details && isTypeVarDetails(type.details);
} }
function isTypeVarDetails(type: any): type is TypeVarDetails { function isTypeVarDetails(type: any): type is TypeVarDetailsShared {
return type.name !== undefined && type.constraints && type.variance !== undefined; return type.name !== undefined && type.constraints && type.variance !== undefined;
} }

View File

@ -425,8 +425,8 @@ export class CompletionProvider {
} }
const symbolTable = new Map<string, Symbol>(); const symbolTable = new Map<string, Symbol>();
for (let i = 1; i < classResults.classType.details.mro.length; i++) { for (let i = 1; i < classResults.classType.shared.mro.length; i++) {
const mroClass = classResults.classType.details.mro[i]; const mroClass = classResults.classType.shared.mro[i];
if (isInstantiableClass(mroClass)) { if (isInstantiableClass(mroClass)) {
getMembersForClass(mroClass, symbolTable, /* includeInstanceVars */ false); getMembersForClass(mroClass, symbolTable, /* includeInstanceVars */ false);
} }
@ -523,9 +523,9 @@ export class CompletionProvider {
let sb = this.parseResults.tokenizerOutput.predominantTabSequence; let sb = this.parseResults.tokenizerOutput.predominantTabSequence;
if ( if (
classType.details.baseClasses.length === 1 && classType.shared.baseClasses.length === 1 &&
isClass(classType.details.baseClasses[0]) && isClass(classType.shared.baseClasses[0]) &&
classType.details.baseClasses[0].details.fullName === 'builtins.object' classType.shared.baseClasses[0].shared.fullName === 'builtins.object'
) { ) {
sb += this.options.snippet ? '${0:pass}' : 'pass'; sb += this.options.snippet ? '${0:pass}' : 'pass';
return sb; return sb;
@ -744,8 +744,8 @@ export class CompletionProvider {
// If this is an unknown type with a "possible type" associated with // If this is an unknown type with a "possible type" associated with
// it, use the possible type. // it, use the possible type.
if (isUnknown(leftType) && leftType.possibleType) { if (isUnknown(leftType) && leftType.priv.possibleType) {
leftType = this.evaluator.makeTopLevelTypeVarsConcrete(leftType.possibleType); leftType = this.evaluator.makeTopLevelTypeVarsConcrete(leftType.priv.possibleType);
} }
doForEachSubtype(leftType, (subtype) => { doForEachSubtype(leftType, (subtype) => {
@ -1657,7 +1657,7 @@ export class CompletionProvider {
// If we can't do that using semantic info, then try syntactic info. // If we can't do that using semantic info, then try syntactic info.
const symbolTable = new Map<string, Symbol>(); const symbolTable = new Map<string, Symbol>();
for (const mroClass of classResults.classType.details.mro) { for (const mroClass of classResults.classType.shared.mro) {
if (mroClass === classResults.classType) { if (mroClass === classResults.classType) {
// Ignore current type. // Ignore current type.
continue; continue;
@ -1717,7 +1717,7 @@ export class CompletionProvider {
} }
const symbolTable = new Map<string, Symbol>(); const symbolTable = new Map<string, Symbol>();
for (const mroClass of classResults.classType.details.mro) { for (const mroClass of classResults.classType.shared.mro) {
if (isInstantiableClass(mroClass)) { if (isInstantiableClass(mroClass)) {
getMembersForClass(mroClass, symbolTable, /* includeInstanceVars */ false); getMembersForClass(mroClass, symbolTable, /* includeInstanceVars */ false);
} }
@ -1799,7 +1799,7 @@ export class CompletionProvider {
} }
const symbolTable = new Map<string, Symbol>(); const symbolTable = new Map<string, Symbol>();
for (const mroClass of classResults.classType.details.mro) { for (const mroClass of classResults.classType.shared.mro) {
if (isInstantiableClass(mroClass)) { if (isInstantiableClass(mroClass)) {
getMembersForClass(mroClass, symbolTable, /* includeInstanceVars */ false); getMembersForClass(mroClass, symbolTable, /* includeInstanceVars */ false);
} }
@ -1826,7 +1826,7 @@ export class CompletionProvider {
if (isStubFile(this.fileUri)) { if (isStubFile(this.fileUri)) {
// In stubs, always use "...". // In stubs, always use "...".
ellipsisForDefault = true; ellipsisForDefault = true;
} else if (classType.details.moduleName === decl.moduleName) { } else if (classType.shared.moduleName === decl.moduleName) {
// In the same file, always print the full default. // In the same file, always print the full default.
ellipsisForDefault = false; ellipsisForDefault = false;
} }
@ -2035,13 +2035,13 @@ export class CompletionProvider {
} }
const type = signature.type; const type = signature.type;
const paramIndex = type.details.parameters.indexOf(signature.activeParam); const paramIndex = type.shared.parameters.indexOf(signature.activeParam);
if (paramIndex < 0) { if (paramIndex < 0) {
return undefined; return undefined;
} }
const paramType = type.details.parameters[paramIndex].type; const paramType = type.shared.parameters[paramIndex].type;
this._addLiteralValuesForTargetType(paramType, priorWord, priorText, postText, completionMap); this._addLiteralValuesForTargetType(paramType, priorWord, priorText, postText, completionMap);
return undefined; return undefined;
}); });
@ -2060,7 +2060,7 @@ export class CompletionProvider {
const value = printLiteralValue(v, quoteValue.quoteCharacter); const value = printLiteralValue(v, quoteValue.quoteCharacter);
if (quoteValue.stringValue === undefined) { if (quoteValue.stringValue === undefined) {
this.addNameToCompletions(value, CompletionItemKind.Constant, priorWord, completionMap, { this.addNameToCompletions(value, CompletionItemKind.Constant, priorWord, completionMap, {
sortText: this._makeSortText(SortCategory.LiteralValue, v.literalValue as string), sortText: this._makeSortText(SortCategory.LiteralValue, v.priv.literalValue as string),
}); });
} else { } else {
this._addStringLiteralToCompletions( this._addStringLiteralToCompletions(
@ -2131,8 +2131,8 @@ export class CompletionProvider {
// Handle both overloaded and non-overloaded functions. // Handle both overloaded and non-overloaded functions.
doForEachSignature(getItemType, (signature) => { doForEachSignature(getItemType, (signature) => {
if ( if (
signature.details.parameters.length >= 1 && signature.shared.parameters.length >= 1 &&
signature.details.parameters[0].category === ParameterCategory.Simple signature.shared.parameters[0].category === ParameterCategory.Simple
) { ) {
typesToCombine.push(FunctionType.getEffectiveParameterType(signature, 0)); typesToCombine.push(FunctionType.getEffectiveParameterType(signature, 0));
} }
@ -2816,8 +2816,10 @@ export class CompletionProvider {
// Add keys from typed dict outside signatures. // Add keys from typed dict outside signatures.
signatureInfo.signatures.forEach((signature) => { signatureInfo.signatures.forEach((signature) => {
if (signature.type.boundToType) { if (signature.type.priv.boundToType) {
const keys = Array.from(signature.type.boundToType.details.typedDictEntries?.knownItems.keys() || []); const keys = Array.from(
signature.type.priv.boundToType.shared.typedDictEntries?.knownItems.keys() || []
);
keys.forEach((key: string) => argNameSet.add(key)); keys.forEach((key: string) => argNameSet.add(key));
} }
}); });
@ -2889,7 +2891,7 @@ export class CompletionProvider {
if (curNode.nodeType === ParseNodeType.Class) { if (curNode.nodeType === ParseNodeType.Class) {
const classType = this.evaluator.getTypeOfClass(curNode); const classType = this.evaluator.getTypeOfClass(curNode);
if (classType && isInstantiableClass(classType.classType)) { if (classType && isInstantiableClass(classType.classType)) {
classType.classType.details.mro.forEach((baseClass, index) => { classType.classType.shared.mro.forEach((baseClass, index) => {
if (isInstantiableClass(baseClass)) { if (isInstantiableClass(baseClass)) {
this._addSymbolsForSymbolTable( this._addSymbolsForSymbolTable(
ClassType.getSymbolTable(baseClass), ClassType.getSymbolTable(baseClass),
@ -3148,7 +3150,7 @@ export class CompletionProvider {
symbolType && symbolType &&
isClassInstance(symbolType) && isClassInstance(symbolType) &&
ClassType.isSameGenericClass(symbolType, containingType) && ClassType.isSameGenericClass(symbolType, containingType) &&
symbolType.literalValue instanceof EnumLiteral symbolType.priv.literalValue instanceof EnumLiteral
); );
} }
} }

View File

@ -30,11 +30,11 @@ import { isDefined } from '../common/core';
import { ProgramView } from '../common/extensibility'; import { ProgramView } from '../common/extensibility';
import { convertPositionToOffset } from '../common/positionUtils'; import { convertPositionToOffset } from '../common/positionUtils';
import { ServiceKeys } from '../common/serviceKeys'; import { ServiceKeys } from '../common/serviceKeys';
import { ServiceProvider } from '../common/serviceProvider';
import { DocumentRange, Position, rangesAreEqual } from '../common/textRange'; import { DocumentRange, Position, rangesAreEqual } from '../common/textRange';
import { Uri } from '../common/uri/uri'; import { Uri } from '../common/uri/uri';
import { ParseNode, ParseNodeType } from '../parser/parseNodes'; import { ParseNode, ParseNodeType } from '../parser/parseNodes';
import { ParseFileResults } from '../parser/parser'; import { ParseFileResults } from '../parser/parser';
import { ServiceProvider } from '../common/serviceProvider';
export enum DefinitionFilter { export enum DefinitionFilter {
All = 'all', All = 'all',
@ -89,7 +89,9 @@ export function addDeclarationsToDefinitions(
// Handle overloaded function case // Handle overloaded function case
const functionType = evaluator.getTypeForDeclaration(resolvedDecl)?.type; const functionType = evaluator.getTypeForDeclaration(resolvedDecl)?.type;
if (functionType && isOverloadedFunction(functionType)) { if (functionType && isOverloadedFunction(functionType)) {
for (const overloadDecl of functionType.overloads.map((o) => o.details.declaration).filter(isDefined)) { for (const overloadDecl of functionType.priv.overloads
.map((o) => o.shared.declaration)
.filter(isDefined)) {
_addIfUnique(definitions, { _addIfUnique(definitions, {
uri: overloadDecl.uri, uri: overloadDecl.uri,
range: overloadDecl.range, range: overloadDecl.range,

View File

@ -450,7 +450,7 @@ function _getDeclarationsForNonModuleNameNode(
const type = evaluator.getType(node); const type = evaluator.getType(node);
if (type?.category === TypeCategory.Module) { if (type?.category === TypeCategory.Module) {
// Synthesize decl for the module. // Synthesize decl for the module.
return [createSynthesizedAliasDeclaration(type.fileUri)]; return [createSynthesizedAliasDeclaration(type.priv.fileUri)];
} }
} }

View File

@ -141,8 +141,8 @@ export function getVariableTypeText(
const typeAliasInfo = getTypeAliasInfo(type); const typeAliasInfo = getTypeAliasInfo(type);
if (typeAliasInfo?.name === typeNode.value) { if (typeAliasInfo?.name === typeNode.value) {
if (isTypeVar(type)) { if (isTypeVar(type)) {
label = type.details.isParamSpec ? 'param spec' : 'type variable'; label = type.shared.isParamSpec ? 'param spec' : 'type variable';
typeVarName = type.details.name; typeVarName = type.shared.name;
} else { } else {
// Handle type aliases specially. // Handle type aliases specially.
const typeText = evaluator.printType(convertToInstance(getTypeForToolTip(evaluator, typeNode)), { const typeText = evaluator.printType(convertToInstance(getTypeForToolTip(evaluator, typeNode)), {
@ -434,7 +434,7 @@ export class HoverProvider {
// with the type of the TypedDict key and its docstring, if available. // with the type of the TypedDict key and its docstring, if available.
doForEachSubtype(type, (subtype) => { doForEachSubtype(type, (subtype) => {
if (isClassInstance(subtype) && ClassType.isTypedDictClass(subtype)) { if (isClassInstance(subtype) && ClassType.isTypedDictClass(subtype)) {
const entry = subtype.details.typedDictEntries?.knownItems.get(node.value); const entry = subtype.shared.typedDictEntries?.knownItems.get(node.value);
if (entry) { if (entry) {
// If we have already added parts for another declaration (e.g. for a union of TypedDicts that share the same key) // If we have already added parts for another declaration (e.g. for a union of TypedDicts that share the same key)
// then we need to add a separator to prevent a visual bug. // then we need to add a separator to prevent a visual bug.

View File

@ -20,12 +20,15 @@ import {
SignatureInformation, SignatureInformation,
} from 'vscode-languageserver'; } from 'vscode-languageserver';
import { getFileInfo } from '../analyzer/analyzerNodeInfo';
import * as ParseTreeUtils from '../analyzer/parseTreeUtils'; import * as ParseTreeUtils from '../analyzer/parseTreeUtils';
import { getCallNodeAndActiveParameterIndex } from '../analyzer/parseTreeUtils'; import { getCallNodeAndActiveParameterIndex } from '../analyzer/parseTreeUtils';
import { SourceMapper } from '../analyzer/sourceMapper'; import { SourceMapper } from '../analyzer/sourceMapper';
import { isBuiltInModule } from '../analyzer/typeDocStringUtils';
import { CallSignature, TypeEvaluator } from '../analyzer/typeEvaluatorTypes'; import { CallSignature, TypeEvaluator } from '../analyzer/typeEvaluatorTypes';
import { PrintTypeFlags } from '../analyzer/typePrinter'; import { PrintTypeFlags } from '../analyzer/typePrinter';
import { throwIfCancellationRequested } from '../common/cancellationUtils'; import { throwIfCancellationRequested } from '../common/cancellationUtils';
import { DocStringService } from '../common/docStringService';
import { ProgramView } from '../common/extensibility'; import { ProgramView } from '../common/extensibility';
import { convertPositionToOffset } from '../common/positionUtils'; import { convertPositionToOffset } from '../common/positionUtils';
import { Position } from '../common/textRange'; import { Position } from '../common/textRange';
@ -33,9 +36,6 @@ import { Uri } from '../common/uri/uri';
import { CallNode, NameNode, ParseNodeType } from '../parser/parseNodes'; import { CallNode, NameNode, ParseNodeType } from '../parser/parseNodes';
import { ParseFileResults } from '../parser/parser'; import { ParseFileResults } from '../parser/parser';
import { getDocumentationPartsForTypeAndDecl, getFunctionDocStringFromType } from './tooltipUtils'; import { getDocumentationPartsForTypeAndDecl, getFunctionDocStringFromType } from './tooltipUtils';
import { DocStringService } from '../common/docStringService';
import { getFileInfo } from '../analyzer/analyzerNodeInfo';
import { isBuiltInModule } from '../analyzer/typeDocStringUtils';
export class SignatureHelpProvider { export class SignatureHelpProvider {
private readonly _parseResults: ParseFileResults | undefined; private readonly _parseResults: ParseFileResults | undefined;
@ -235,7 +235,7 @@ export class SignatureHelpProvider {
let label = '('; let label = '(';
let activeParameter: number | undefined; let activeParameter: number | undefined;
const params = functionType.details.parameters; const params = functionType.shared.parameters;
stringParts[0].forEach((paramString: string, paramIndex) => { stringParts[0].forEach((paramString: string, paramIndex) => {
let paramName = ''; let paramName = '';

View File

@ -78,7 +78,7 @@ export function getOverloadedFunctionTooltip(
const overloads = OverloadedFunctionType.getOverloads(type).map((o) => const overloads = OverloadedFunctionType.getOverloads(type).map((o) =>
getFunctionTooltip( getFunctionTooltip(
/* label */ '', /* label */ '',
o.details.name, o.shared.name,
o, o,
evaluator, evaluator,
/* isProperty */ false, /* isProperty */ false,
@ -145,7 +145,7 @@ export function getConstructorTooltip(
let signature = ''; let signature = '';
if (isOverloadedFunction(type)) { if (isOverloadedFunction(type)) {
const overloads = type.overloads.map((overload) => const overloads = type.priv.overloads.map((overload) =>
getConstructorTooltip(constructorName, overload, evaluator, functionSignatureDisplay) getConstructorTooltip(constructorName, overload, evaluator, functionSignatureDisplay)
); );
overloads.forEach((overload, index) => { overloads.forEach((overload, index) => {
@ -177,7 +177,7 @@ function formatSignature(
} }
export function getFunctionDocStringFromType(type: FunctionType, sourceMapper: SourceMapper, evaluator: TypeEvaluator) { export function getFunctionDocStringFromType(type: FunctionType, sourceMapper: SourceMapper, evaluator: TypeEvaluator) {
const decl = type.details.declaration; const decl = type.shared.declaration;
const enclosingClass = decl ? ParseTreeUtils.getEnclosingClass(decl.node) : undefined; const enclosingClass = decl ? ParseTreeUtils.getEnclosingClass(decl.node) : undefined;
const classResults = enclosingClass ? evaluator.getTypeOfClass(enclosingClass) : undefined; const classResults = enclosingClass ? evaluator.getTypeOfClass(enclosingClass) : undefined;
@ -189,17 +189,17 @@ export function getOverloadedFunctionDocStringsFromType(
sourceMapper: SourceMapper, sourceMapper: SourceMapper,
evaluator: TypeEvaluator evaluator: TypeEvaluator
) { ) {
if (type.overloads.length === 0) { if (type.priv.overloads.length === 0) {
return []; return [];
} }
const decl = type.overloads[0].details.declaration; const decl = type.priv.overloads[0].shared.declaration;
const enclosingClass = decl ? ParseTreeUtils.getEnclosingClass(decl.node) : undefined; const enclosingClass = decl ? ParseTreeUtils.getEnclosingClass(decl.node) : undefined;
const classResults = enclosingClass ? evaluator.getTypeOfClass(enclosingClass) : undefined; const classResults = enclosingClass ? evaluator.getTypeOfClass(enclosingClass) : undefined;
return getOverloadedFunctionDocStringsInherited( return getOverloadedFunctionDocStringsInherited(
type, type,
type.overloads.map((o) => o.details.declaration).filter(isDefined), type.priv.overloads.map((o) => o.shared.declaration).filter(isDefined),
sourceMapper, sourceMapper,
evaluator, evaluator,
@ -361,9 +361,9 @@ export function combineExpressionTypes(typeNodes: ExpressionNode[], evaluator: T
typeList.length === 1 && typeList.length === 1 &&
result.category === TypeCategory.Class && result.category === TypeCategory.Class &&
ClassType.isBuiltIn(result, 'list') && ClassType.isBuiltIn(result, 'list') &&
result.typeArguments result.priv.typeArguments
) { ) {
result = result.typeArguments[0]; result = result.priv.typeArguments[0];
} else if ( } else if (
typeList.length === 1 && typeList.length === 1 &&
result.category === TypeCategory.Class && result.category === TypeCategory.Class &&
@ -429,7 +429,7 @@ export function getClassAndConstructorTypes(node: NameNode, evaluator: TypeEvalu
!methodType || !methodType ||
(methodType && (methodType &&
isFunction(methodType) && isFunction(methodType) &&
(FunctionType.hasDefaultParameters(methodType) || methodType.details.parameters.length === 0)) (FunctionType.hasDefaultParameters(methodType) || methodType.shared.parameters.length === 0))
) { ) {
const newMember = lookUpClassMember( const newMember = lookUpClassMember(
classType, classType,

View File

@ -137,11 +137,11 @@ test('property', () => {
assert(isProperty(result.decoratedType)); assert(isProperty(result.decoratedType));
assert(isClassInstance(result.decoratedType)); assert(isClassInstance(result.decoratedType));
assert(result.decoratedType.details.declaration); assert(result.decoratedType.shared.declaration);
assert(isClassDeclaration(result.decoratedType.details.declaration)); assert(isClassDeclaration(result.decoratedType.shared.declaration));
assert(result.decoratedType.details.declaration.moduleName === 'builtins'); assert(result.decoratedType.shared.declaration.moduleName === 'builtins');
assert(result.decoratedType.details.declaration.node.name.value === 'property'); assert(result.decoratedType.shared.declaration.node.name.value === 'property');
}); });
}); });
@ -154,13 +154,13 @@ function checkSpecialBuiltInClassDetail(code: string) {
const type = state.program.evaluator!.getType(node); const type = state.program.evaluator!.getType(node);
assert(type?.category === TypeCategory.Class); assert(type?.category === TypeCategory.Class);
assert.strictEqual(node.value, type.aliasName ?? type.details.name); assert.strictEqual(node.value, type.priv.aliasName ?? type.shared.name);
assert(type.details.declaration); assert(type.shared.declaration);
if (type.aliasName) { if (type.priv.aliasName) {
assert(isClassDeclaration(type.details.declaration)); assert(isClassDeclaration(type.shared.declaration));
} else { } else {
assert(isSpecialBuiltInClassDeclaration(type.details.declaration)); assert(isSpecialBuiltInClassDeclaration(type.shared.declaration));
} }
} }
@ -181,18 +181,18 @@ function _checkClassDetail(state: TestState, range: Range | undefined, name?: st
const type = state.program.evaluator!.getType(node); const type = state.program.evaluator!.getType(node);
assert(type?.category === TypeCategory.Class); assert(type?.category === TypeCategory.Class);
assert.strictEqual(name ?? node.value, type.aliasName ?? type.details.name); assert.strictEqual(name ?? node.value, type.priv.aliasName ?? type.shared.name);
if (range) { if (range) {
assert(type.details.declaration); assert(type.shared.declaration);
assert(isClassDeclaration(type.details.declaration)); assert(isClassDeclaration(type.shared.declaration));
assert.deepStrictEqual( assert.deepStrictEqual(
TextRange.create(type.details.declaration.node.start, type.details.declaration.node.length), TextRange.create(type.shared.declaration.node.start, type.shared.declaration.node.length),
TextRange.fromBounds(range.pos, range.end) TextRange.fromBounds(range.pos, range.end)
); );
} else { } else {
// There should be no decl. // There should be no decl.
assert(!type.details.declaration); assert(!type.shared.declaration);
} }
} }

View File

@ -216,7 +216,7 @@ function assertTypeAlias(code: string) {
const type = state.program.evaluator!.getType(node); const type = state.program.evaluator!.getType(node);
assert(type?.category === TypeCategory.Class); assert(type?.category === TypeCategory.Class);
assert.strictEqual(type.details.name, 'Mapping'); assert.strictEqual(type.shared.name, 'Mapping');
assert.strictEqual(type.props?.typeAliasInfo?.name, 'M'); assert.strictEqual(type.props?.typeAliasInfo?.name, 'M');
assert.strictEqual(type.props?.typeAliasInfo.moduleName, 'test'); assert.strictEqual(type.props?.typeAliasInfo.moduleName, 'test');

View File

@ -29,7 +29,7 @@ import { Uri } from '../common/uri/uri';
import { ParameterCategory } from '../parser/parseNodes'; import { ParameterCategory } from '../parser/parseNodes';
function returnTypeCallback(type: FunctionType) { function returnTypeCallback(type: FunctionType) {
return type.details.declaredReturnType ?? UnknownType.create(/* isEllipsis */ true); return type.shared.declaredReturnType ?? UnknownType.create(/* isEllipsis */ true);
} }
test('SimpleTypes', () => { test('SimpleTypes', () => {
@ -58,11 +58,11 @@ test('TypeVarTypes', () => {
assert.strictEqual(printType(typeVarType, PrintTypeFlags.None, returnTypeCallback), 'T'); assert.strictEqual(printType(typeVarType, PrintTypeFlags.None, returnTypeCallback), 'T');
const paramSpecType = TypeVarType.createInstance('P'); const paramSpecType = TypeVarType.createInstance('P');
paramSpecType.details.isParamSpec = true; paramSpecType.shared.isParamSpec = true;
assert.strictEqual(printType(paramSpecType, PrintTypeFlags.None, returnTypeCallback), 'P'); assert.strictEqual(printType(paramSpecType, PrintTypeFlags.None, returnTypeCallback), 'P');
const typeVarTupleType = TypeVarType.createInstance('Ts'); const typeVarTupleType = TypeVarType.createInstance('Ts');
paramSpecType.details.isVariadic = true; paramSpecType.shared.isVariadic = true;
assert.strictEqual(printType(typeVarTupleType, PrintTypeFlags.None, returnTypeCallback), 'Ts'); assert.strictEqual(printType(typeVarTupleType, PrintTypeFlags.None, returnTypeCallback), 'Ts');
}); });
@ -81,7 +81,7 @@ test('ClassTypes', () => {
const typeVarS = TypeVarType.createInstance('S'); const typeVarS = TypeVarType.createInstance('S');
const typeVarT = TypeVarType.createInstance('T'); const typeVarT = TypeVarType.createInstance('T');
classTypeA.details.typeParameters.push(typeVarS, typeVarT); classTypeA.shared.typeParameters.push(typeVarS, typeVarT);
assert.strictEqual(printType(classTypeA, PrintTypeFlags.None, returnTypeCallback), 'type[A[S, T]]'); assert.strictEqual(printType(classTypeA, PrintTypeFlags.None, returnTypeCallback), 'type[A[S, T]]');
@ -133,7 +133,7 @@ test('FunctionTypes', () => {
FunctionParam.create(ParameterCategory.KwargsDict, AnyType.create(), FunctionParamFlags.TypeDeclared, 'kwargs') FunctionParam.create(ParameterCategory.KwargsDict, AnyType.create(), FunctionParamFlags.TypeDeclared, 'kwargs')
); );
funcTypeA.details.declaredReturnType = NeverType.createNoReturn(); funcTypeA.shared.declaredReturnType = NeverType.createNoReturn();
assert.strictEqual( assert.strictEqual(
printType(funcTypeA, PrintTypeFlags.None, returnTypeCallback), printType(funcTypeA, PrintTypeFlags.None, returnTypeCallback),
@ -154,10 +154,10 @@ test('FunctionTypes', () => {
FunctionType.addPositionOnlyParameterSeparator(funcTypeB); FunctionType.addPositionOnlyParameterSeparator(funcTypeB);
const paramSpecP = TypeVarType.createInstance('P'); const paramSpecP = TypeVarType.createInstance('P');
paramSpecP.details.isParamSpec = true; paramSpecP.shared.isParamSpec = true;
FunctionType.addParamSpecVariadics(funcTypeB, paramSpecP); FunctionType.addParamSpecVariadics(funcTypeB, paramSpecP);
funcTypeB.details.declaredReturnType = NeverType.createNever(); funcTypeB.shared.declaredReturnType = NeverType.createNever();
assert.strictEqual(printType(funcTypeB, PrintTypeFlags.None, returnTypeCallback), '(a: Any, /, **P) -> Never'); assert.strictEqual(printType(funcTypeB, PrintTypeFlags.None, returnTypeCallback), '(a: Any, /, **P) -> Never');
assert.strictEqual( assert.strictEqual(
@ -168,7 +168,7 @@ test('FunctionTypes', () => {
const funcTypeC = FunctionType.createInstance('C', '', '', FunctionTypeFlags.None); const funcTypeC = FunctionType.createInstance('C', '', '', FunctionTypeFlags.None);
const typeVarTupleTs = TypeVarType.createInstance('Ts'); const typeVarTupleTs = TypeVarType.createInstance('Ts');
typeVarTupleTs.details.isVariadic = true; typeVarTupleTs.shared.isVariadic = true;
const unpackedTs = TypeVarType.cloneForUnpacked(typeVarTupleTs); const unpackedTs = TypeVarType.cloneForUnpacked(typeVarTupleTs);
FunctionType.addParameter( FunctionType.addParameter(
@ -185,7 +185,7 @@ test('FunctionTypes', () => {
const funcTypeD = FunctionType.createInstance('D', '', '', FunctionTypeFlags.None); const funcTypeD = FunctionType.createInstance('D', '', '', FunctionTypeFlags.None);
funcTypeD.details.declaredReturnType = AnyType.create(); funcTypeD.shared.declaredReturnType = AnyType.create();
FunctionType.addParamSpecVariadics(funcTypeD, paramSpecP); FunctionType.addParamSpecVariadics(funcTypeD, paramSpecP);
assert.strictEqual(printType(funcTypeD, PrintTypeFlags.None, returnTypeCallback), '(**P) -> Any'); assert.strictEqual(printType(funcTypeD, PrintTypeFlags.None, returnTypeCallback), '(**P) -> Any');