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
// guard checks.
function narrowConstrainedTypeVar(flowNode: FlowNode, typeVar: TypeVarType): ClassType | undefined {
assert(!typeVar.details.isParamSpec);
assert(!typeVar.details.isVariadic);
assert(!typeVar.details.boundType);
assert(typeVar.details.constraints.length > 0);
assert(!typeVar.shared.isParamSpec);
assert(!typeVar.shared.isVariadic);
assert(!typeVar.shared.boundType);
assert(typeVar.shared.constraints.length > 0);
const visitedFlowNodeMap = new Set<number>();
const startingConstraints: ClassType[] = [];
for (const constraint of typeVar.details.constraints) {
for (const constraint of typeVar.shared.constraints) {
if (isClassInstance(constraint)) {
startingConstraints.push(constraint);
} else {
@ -1604,8 +1604,8 @@ export function getCodeFlowEngine(
if (
!subtype.props.condition.some(
(condition) =>
condition.typeVar.details.constraints.length > 0 &&
condition.typeVar.nameWithScope === typeVar.nameWithScope
condition.typeVar.shared.constraints.length > 0 &&
condition.typeVar.priv.nameWithScope === typeVar.priv.nameWithScope
)
) {
isCompatible = false;
@ -1749,15 +1749,15 @@ export function getCodeFlowEngine(
}
function isFunctionNoReturn(functionType: FunctionType, isCallAwaited: boolean) {
const returnType = functionType.details.declaredReturnType;
const returnType = functionType.shared.declaredReturnType;
if (returnType) {
if (
isClassInstance(returnType) &&
ClassType.isBuiltIn(returnType, 'Coroutine') &&
returnType.typeArguments &&
returnType.typeArguments.length >= 3
returnType.priv.typeArguments &&
returnType.priv.typeArguments.length >= 3
) {
if (isNever(returnType.typeArguments[2]) && isCallAwaited) {
if (isNever(returnType.priv.typeArguments[2]) && isCallAwaited) {
return true;
}
}
@ -1765,19 +1765,19 @@ export function getCodeFlowEngine(
return isNever(returnType);
} else if (!inferNoReturnForUnannotatedFunctions) {
return false;
} else if (functionType.details.declaration) {
} else if (functionType.shared.declaration) {
// 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
// return" type for abstract methods.
if (
!functionType.details.declaration.isGenerator &&
!functionType.shared.declaration.isGenerator &&
!FunctionType.isAbstractMethod(functionType) &&
!FunctionType.isStubDefinition(functionType) &&
!FunctionType.isPyTypedDefinition(functionType)
) {
// Check specifically for a common idiom where the only statement
// (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;
for (const statement of functionStatements) {
@ -1816,11 +1816,11 @@ export function getCodeFlowEngine(
}
function isAfterNodeReachable(evaluator: TypeEvaluator, functionType: FunctionType) {
if (!functionType.details.declaration) {
if (!functionType.shared.declaration) {
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
@ -1853,8 +1853,8 @@ export function getCodeFlowEngine(
const exitMethodName = isAsync ? '__aexit__' : '__exit__';
const exitType = evaluator.getBoundMagicMethod(cmType, exitMethodName);
if (exitType && isFunction(exitType) && exitType.details.declaredReturnType) {
let returnType = exitType.details.declaredReturnType;
if (exitType && isFunction(exitType) && exitType.shared.declaredReturnType) {
let returnType = exitType.shared.declaredReturnType;
// 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
@ -1863,16 +1863,16 @@ export function getCodeFlowEngine(
if (
isClassInstance(returnType) &&
ClassType.isBuiltIn(returnType, 'Coroutine') &&
returnType.typeArguments &&
returnType.typeArguments.length >= 3
returnType.priv.typeArguments &&
returnType.priv.typeArguments.length >= 3
) {
returnType = returnType.typeArguments[2];
returnType = returnType.priv.typeArguments[2];
}
}
cmSwallowsExceptions = false;
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;
}
}

View File

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

View File

@ -46,7 +46,7 @@ import {
import { TypeVarContext } from './typeVarContext';
export function hasConstructorTransform(classType: ClassType): boolean {
if (classType.details.fullName === 'functools.partial') {
if (classType.shared.fullName === 'functools.partial') {
return true;
}
@ -61,7 +61,7 @@ export function applyConstructorTransform(
result: FunctionResult,
signatureTracker: UniqueSignatureTracker | undefined
): FunctionResult {
if (classType.details.fullName === 'functools.partial') {
if (classType.shared.fullName === 'functools.partial') {
return applyPartialTransform(evaluator, errorNode, argList, result, signatureTracker);
}
@ -78,7 +78,7 @@ function applyPartialTransform(
signatureTracker: UniqueSignatureTracker | undefined
): FunctionResult {
// 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;
}
@ -88,7 +88,7 @@ function applyPartialTransform(
}
const callMemberType = evaluator.getTypeOfMember(callMemberResult);
if (!isFunction(callMemberType) || callMemberType.details.parameters.length < 1) {
if (!isFunction(callMemberType) || callMemberType.shared.parameters.length < 1) {
return result;
}
@ -180,7 +180,7 @@ function applyPartialTransform(
evaluator.addDiagnostic(
DiagnosticRule.reportCallIssue,
LocMessage.noOverload().format({
name: origFunctionType.overloads[0].details.name,
name: origFunctionType.priv.overloads[0].shared.name,
}),
errorNode
);
@ -199,7 +199,7 @@ function applyPartialTransform(
synthesizedCallType = OverloadedFunctionType.create(
// Set the "overloaded" flag for each of the __call__ overloads.
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({
argType: evaluator.printType(argTypeResult.type),
paramType: evaluator.printType(paramType),
functionName: origFunctionType.details.name,
functionName: origFunctionType.shared.name,
paramName: paramListDetails.params[paramListDetails.argsIndex].param.name ?? '',
}),
arg.valueExpression ?? errorNode
@ -315,7 +315,7 @@ function applyPartialTransformToFunction(
LocMessage.argAssignmentParamFunction().format({
argType: evaluator.printType(argTypeResult.type),
paramType: evaluator.printType(paramType),
functionName: origFunctionType.details.name,
functionName: origFunctionType.shared.name,
paramName,
}),
arg.valueExpression ?? errorNode
@ -364,7 +364,7 @@ function applyPartialTransformToFunction(
LocMessage.argAssignmentParamFunction().format({
argType: evaluator.printType(argTypeResult.type),
paramType: evaluator.printType(paramType),
functionName: origFunctionType.details.name,
functionName: origFunctionType.shared.name,
paramName: paramListDetails.params[paramListDetails.kwargsIndex].param.name ?? '',
}),
arg.valueExpression ?? errorNode
@ -404,7 +404,7 @@ function applyPartialTransformToFunction(
LocMessage.argAssignmentParamFunction().format({
argType: evaluator.printType(argTypeResult.type),
paramType: evaluator.printType(paramType),
functionName: origFunctionType.details.name,
functionName: origFunctionType.shared.name,
paramName,
}),
arg.valueExpression ?? errorNode
@ -426,7 +426,7 @@ function applyPartialTransformToFunction(
// Create a new parameter list that omits parameters that have been
// populated already.
const updatedParamList: FunctionParam[] = specializedFunctionType.details.parameters.map((param, index) => {
const updatedParamList: FunctionParam[] = specializedFunctionType.shared.parameters.map((param, index) => {
const specializedParam: FunctionParam = { ...param };
specializedParam.type = FunctionType.getEffectiveParameterType(specializedFunctionType, index);
@ -460,25 +460,25 @@ function applyPartialTransformToFunction(
// Create a new __call__ method that uses the remaining parameters.
const newCallMemberType = FunctionType.createInstance(
partialCallMemberType.details.name,
partialCallMemberType.details.fullName,
partialCallMemberType.details.moduleName,
partialCallMemberType.details.flags,
specializedFunctionType.details.docString
partialCallMemberType.shared.name,
partialCallMemberType.shared.fullName,
partialCallMemberType.shared.moduleName,
partialCallMemberType.shared.flags,
specializedFunctionType.shared.docString
);
if (partialCallMemberType.details.parameters.length > 0) {
FunctionType.addParameter(newCallMemberType, partialCallMemberType.details.parameters[0]);
if (partialCallMemberType.shared.parameters.length > 0) {
FunctionType.addParameter(newCallMemberType, partialCallMemberType.shared.parameters[0]);
}
newParamList.forEach((param) => {
FunctionType.addParameter(newCallMemberType, param);
});
newCallMemberType.details.declaredReturnType = specializedFunctionType.details.declaredReturnType
newCallMemberType.shared.declaredReturnType = specializedFunctionType.shared.declaredReturnType
? FunctionType.getEffectiveReturnType(specializedFunctionType)
: specializedFunctionType.inferredReturnType;
newCallMemberType.details.declaration = partialCallMemberType.details.declaration;
newCallMemberType.details.typeVarScopeId = specializedFunctionType.details.typeVarScopeId;
: specializedFunctionType.priv.inferredReturnType;
newCallMemberType.shared.declaration = partialCallMemberType.shared.declaration;
newCallMemberType.shared.typeVarScopeId = specializedFunctionType.shared.typeVarScopeId;
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.
let initMethodBindToType = newMethodReturnType;
if (
initMethodBindToType.typeArguments &&
initMethodBindToType.typeArguments.some((typeArg) => isUnknown(typeArg))
initMethodBindToType.priv.typeArguments &&
initMethodBindToType.priv.typeArguments.some((typeArg) => isUnknown(typeArg))
) {
initMethodBindToType = ClassType.cloneAsInstance(type);
}
@ -479,10 +479,10 @@ function validateNewMethod(
if (newReturnType) {
// Special-case the 'tuple' type specialization to use the homogenous
// arbitrary-length form.
if (isClassInstance(newReturnType) && isTupleClass(newReturnType) && !newReturnType.tupleTypeArguments) {
if (newReturnType.typeArguments && newReturnType.typeArguments.length === 1) {
if (isClassInstance(newReturnType) && isTupleClass(newReturnType) && !newReturnType.priv.tupleTypeArguments) {
if (newReturnType.priv.typeArguments && newReturnType.priv.typeArguments.length === 1) {
newReturnType = specializeTupleClass(newReturnType, [
{ type: newReturnType.typeArguments[0], isUnbounded: true },
{ type: newReturnType.priv.typeArguments[0], isUnbounded: true },
]);
}
@ -539,7 +539,7 @@ function validateInitMethod(
if (
isClassInstance(expectedSubType) &&
ClassType.isSameGenericClass(type, expectedSubType) &&
type.typeArguments
type.priv.typeArguments
) {
return undefined;
}
@ -617,7 +617,7 @@ function validateInitMethod(
}
if (!returnType) {
const typeVarContext = type.typeArguments
const typeVarContext = type.priv.typeArguments
? buildTypeVarContextFromSpecializedClass(type)
: new TypeVarContext(getTypeVarScopeId(type));
@ -675,13 +675,13 @@ function validateFallbackConstructorCall(
if (argList.length > 0 && argList.some((arg) => arg.argumentCategory === ArgumentCategory.Simple)) {
evaluator.addDiagnostic(
DiagnosticRule.reportCallIssue,
LocMessage.constructorNoArgs().format({ type: type.aliasName || type.details.name }),
LocMessage.constructorNoArgs().format({ type: type.priv.aliasName || type.shared.name }),
errorNode
);
reportedErrors = true;
}
if (!inferenceContext && type.typeArguments) {
if (!inferenceContext && type.priv.typeArguments) {
// If there was no expected type but the type was already specialized,
// assume that we're constructing an instance of the specialized type.
return {
@ -760,7 +760,7 @@ function validateMetaclassCall(
// If the return type is unannotated, don't use the inferred return type.
const callType = metaclassCallMethodInfo.type;
if (isFunction(callType) && !callType.details.declaredReturnType) {
if (isFunction(callType) && !callType.shared.declaredReturnType) {
return undefined;
}
@ -806,7 +806,7 @@ function applyExpectedTypeForConstructor(
// If this isn't a generic type or it's a type that has already been
// 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 });
}
@ -822,7 +822,7 @@ function applyExpectedTypeForConstructor(
// If the expected type didn't provide TypeVar values, remaining
// unsolved TypeVars should be considered Unknown unless they were
// provided explicitly in the constructor call.
if (type.typeArguments) {
if (type.priv.typeArguments) {
unsolvedTypeVarsAreUnknown = false;
}
}
@ -843,9 +843,9 @@ function applyExpectedTypeForTupleConstructor(type: ClassType, inferenceContext:
inferenceContext &&
isClassInstance(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;
@ -901,7 +901,7 @@ function createFunctionFromMetaclassCall(
classType: ClassType,
recursionCount: number
): FunctionType | OverloadedFunctionType | undefined {
const metaclass = classType.details.effectiveMetaclass;
const metaclass = classType.shared.effectiveMetaclass;
if (!metaclass || !isClass(metaclass)) {
return undefined;
}
@ -943,7 +943,7 @@ function createFunctionFromMetaclassCall(
// any of them returns something other than the instance of the class being
// constructed.
doForEachSignature(boundCallType, (signature) => {
if (signature.details.declaredReturnType) {
if (signature.shared.declaredReturnType) {
const returnType = FunctionType.getEffectiveReturnType(signature);
if (returnType && shouldSkipNewAndInitEvaluation(evaluator, classType, returnType)) {
useMetaclassCall = true;
@ -978,14 +978,14 @@ function createFunctionFromNewMethod(
// If there are no parameters that include class-scoped type parameters,
// self-specialize the class because the type arguments for the class
// 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) {
return false;
}
const paramType = FunctionType.getEffectiveParameterType(newSubtype, index);
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(
@ -1003,14 +1003,14 @@ function createFunctionFromNewMethod(
}
const convertedNew = FunctionType.clone(boundNew);
convertedNew.details.typeVarScopeId = newSubtype.details.typeVarScopeId;
convertedNew.shared.typeVarScopeId = newSubtype.shared.typeVarScopeId;
if (!convertedNew.details.docString && classType.details.docString) {
convertedNew.details.docString = classType.details.docString;
if (!convertedNew.shared.docString && classType.shared.docString) {
convertedNew.shared.docString = classType.shared.docString;
}
convertedNew.details.flags &= ~(FunctionTypeFlags.StaticMethod | FunctionTypeFlags.ConstructorMethod);
convertedNew.constructorTypeVarScopeId = getTypeVarScopeId(classType);
convertedNew.shared.flags &= ~(FunctionTypeFlags.StaticMethod | FunctionTypeFlags.ConstructorMethod);
convertedNew.priv.constructorTypeVarScopeId = getTypeVarScopeId(classType);
return convertedNew;
};
@ -1024,7 +1024,7 @@ function createFunctionFromNewMethod(
}
const newOverloads: FunctionType[] = [];
newType.overloads.forEach((overload) => {
newType.priv.overloads.forEach((overload) => {
const converted = convertNewToConstructor(overload);
if (converted) {
newOverloads.push(converted);
@ -1045,16 +1045,16 @@ function createFunctionFromNewMethod(
function createFunctionFromObjectNewMethod(classType: ClassType) {
// Return a fallback constructor based on the object.__new__ method.
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
// by the constructor, so add the default parameters.
if (classType.includeSubclasses || ClassType.isProtocolClass(classType)) {
if (classType.priv.includeSubclasses || ClassType.isProtocolClass(classType)) {
FunctionType.addDefaultParameters(constructorFunction);
}
if (!constructorFunction.details.docString && classType.details.docString) {
constructorFunction.details.docString = classType.details.docString;
if (!constructorFunction.shared.docString && classType.shared.docString) {
constructorFunction.shared.docString = classType.shared.docString;
}
return constructorFunction;
@ -1104,14 +1104,14 @@ function createFunctionFromInitMethod(
// If this is a generic type, self-specialize the class (i.e. fill in
// 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));
// 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.
const typeVarsInParams: TypeVarType[] = [];
convertedInit.details.parameters.forEach((param, index) => {
convertedInit.shared.parameters.forEach((param, index) => {
const paramType = FunctionType.getEffectiveParameterType(convertedInit, index);
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) {
convertedInit.specializedTypes.returnType = returnType;
if (convertedInit.priv.specializedTypes) {
convertedInit.priv.specializedTypes.returnType = returnType;
}
if (!convertedInit.details.docString && classType.details.docString) {
convertedInit.details.docString = classType.details.docString;
if (!convertedInit.shared.docString && classType.shared.docString) {
convertedInit.shared.docString = classType.shared.docString;
}
convertedInit.details.flags &= ~FunctionTypeFlags.StaticMethod;
convertedInit.constructorTypeVarScopeId = getTypeVarScopeId(classType);
convertedInit.shared.flags &= ~FunctionTypeFlags.StaticMethod;
convertedInit.priv.constructorTypeVarScopeId = getTypeVarScopeId(classType);
return convertedInit;
}
@ -1156,7 +1156,7 @@ function createFunctionFromInitMethod(
}
const initOverloads: FunctionType[] = [];
initType.overloads.forEach((overload) => {
initType.priv.overloads.forEach((overload) => {
const converted = convertInitToConstructor(overload);
if (converted) {
initOverloads.push(converted);
@ -1234,7 +1234,7 @@ function isDefaultNewMethod(newMethod?: Type): boolean {
return false;
}
const params = newMethod.details.parameters;
const params = newMethod.shared.parameters;
if (params.length !== 2) {
return false;
}
@ -1243,8 +1243,8 @@ function isDefaultNewMethod(newMethod?: Type): boolean {
return false;
}
const returnType = newMethod.details.declaredReturnType ?? newMethod.inferredReturnType;
if (!returnType || !isTypeVar(returnType) || !returnType.details.isSynthesizedSelf) {
const returnType = newMethod.shared.declaredReturnType ?? newMethod.priv.inferredReturnType;
if (!returnType || !isTypeVar(returnType) || !returnType.shared.isSynthesizedSelf) {
return false;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -32,7 +32,7 @@ export function isTypedKwargs(param: FunctionParam): boolean {
isClassInstance(param.type) &&
isUnpackedClass(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 {
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
@ -88,13 +88,13 @@ export function getParameterListDetails(type: FunctionType): ParameterListDetail
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
// parameters by naming them with "__".
if (positionOnlyIndex < 0) {
for (let i = 0; i < type.details.parameters.length; i++) {
const p = type.details.parameters[i];
for (let i = 0; i < type.shared.parameters.length; i++) {
const p = type.shared.parameters[i];
if (p.category !== ParameterCategory.Simple) {
break;
}
@ -117,7 +117,7 @@ export function getParameterListDetails(type: FunctionType): ParameterListDetail
}
for (let i = 0; i < positionOnlyIndex; i++) {
if (type.details.parameters[i].defaultType) {
if (type.shared.parameters[i].defaultType) {
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 this is an unpacked tuple, expand the entries.
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;
paramType.tupleTypeArguments.forEach((tupleArg, tupleIndex) => {
paramType.priv.tupleTypeArguments.forEach((tupleArg, tupleIndex) => {
const category =
isVariadicTypeVar(tupleArg.type) || tupleArg.isUnbounded
? ParameterCategory.ArgsList
@ -237,13 +237,13 @@ export function getParameterListDetails(type: FunctionType): ParameterListDetail
const paramType = FunctionType.getEffectiveParameterType(type, index);
// 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) {
result.firstKeywordOnlyIndex = result.params.length;
}
const typedDictType = paramType;
paramType.details.typedDictEntries.knownItems.forEach((entry, name) => {
paramType.shared.typedDictEntries.knownItems.forEach((entry, name) => {
const specializedParamType = partiallySpecializeType(entry.valueType, typedDictType);
addVirtualParameter(
@ -259,16 +259,16 @@ export function getParameterListDetails(type: FunctionType): ParameterListDetail
);
});
if (paramType.details.typedDictEntries.extraItems) {
if (paramType.shared.typedDictEntries.extraItems) {
addVirtualParameter(
FunctionParam.create(
ParameterCategory.KwargsDict,
paramType.details.typedDictEntries.extraItems.valueType,
paramType.shared.typedDictEntries.extraItems.valueType,
FunctionParamFlags.TypeDeclared,
'kwargs'
),
index,
paramType.details.typedDictEntries.extraItems.valueType
paramType.shared.typedDictEntries.extraItems.valueType
);
result.kwargsIndex = result.params.length - 1;
@ -296,8 +296,8 @@ export function getParameterListDetails(type: FunctionType): ParameterListDetail
param,
index,
/* typeOverride */ undefined,
type.specializedTypes?.parameterDefaultArgs
? type.specializedTypes?.parameterDefaultArgs[index]
type.priv.specializedTypes?.parameterDefaultArgs
? type.priv.specializedTypes?.parameterDefaultArgs[index]
: undefined
);
}
@ -323,7 +323,7 @@ export function isParamSpecArgsArgument(paramSpec: TypeVarType, argType: Type) {
doForEachSubtype(argType, (argSubtype) => {
if (
isParamSpec(argSubtype) &&
argSubtype.paramSpecAccess === 'args' &&
argSubtype.priv.paramSpecAccess === 'args' &&
isTypeSame(argSubtype, paramSpec, { ignoreTypeFlags: true })
) {
return;
@ -331,10 +331,10 @@ export function isParamSpecArgsArgument(paramSpec: TypeVarType, argType: Type) {
if (
isClassInstance(argSubtype) &&
argSubtype.tupleTypeArguments &&
argSubtype.tupleTypeArguments.length === 1 &&
argSubtype.tupleTypeArguments[0].isUnbounded &&
isAnyOrUnknown(argSubtype.tupleTypeArguments[0].type)
argSubtype.priv.tupleTypeArguments &&
argSubtype.priv.tupleTypeArguments.length === 1 &&
argSubtype.priv.tupleTypeArguments[0].isUnbounded &&
isAnyOrUnknown(argSubtype.priv.tupleTypeArguments[0].type)
) {
return;
}
@ -357,7 +357,7 @@ export function isParamSpecKwargsArgument(paramSpec: TypeVarType, argType: Type)
doForEachSubtype(argType, (argSubtype) => {
if (
isParamSpec(argSubtype) &&
argSubtype.paramSpecAccess === 'kwargs' &&
argSubtype.priv.paramSpecAccess === 'kwargs' &&
isTypeSame(argSubtype, paramSpec, { ignoreTypeFlags: true })
) {
return;
@ -366,11 +366,11 @@ export function isParamSpecKwargsArgument(paramSpec: TypeVarType, argType: Type)
if (
isClassInstance(argSubtype) &&
ClassType.isBuiltIn(argSubtype, 'dict') &&
argSubtype.typeArguments &&
argSubtype.typeArguments.length === 2 &&
isClassInstance(argSubtype.typeArguments[0]) &&
ClassType.isBuiltIn(argSubtype.typeArguments[0], 'str') &&
isAnyOrUnknown(argSubtype.typeArguments[1])
argSubtype.priv.typeArguments &&
argSubtype.priv.typeArguments.length === 2 &&
isClassInstance(argSubtype.priv.typeArguments[0]) &&
ClassType.isBuiltIn(argSubtype.priv.typeArguments[0], 'str') &&
isAnyOrUnknown(argSubtype.priv.typeArguments[1])
) {
return;
}

View File

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

View File

@ -60,11 +60,11 @@ export function createProperty(
const typeMetaclass = evaluator.getBuiltInType(decoratorNode, 'type');
const typeSourceId = ClassType.isBuiltIn(decoratorType, 'property')
? getTypeSourceId(decoratorNode)
: decoratorType.details.typeSourceId;
: decoratorType.shared.typeSourceId;
const propertyClass = ClassType.createInstantiable(
decoratorType.details.name,
getClassFullName(decoratorNode, fileInfo.moduleName, `__property_${fget.details.name}`),
decoratorType.shared.name,
getClassFullName(decoratorNode, fileInfo.moduleName, `__property_${fget.shared.name}`),
fileInfo.moduleName,
fileInfo.fileUri,
ClassTypeFlags.PropertyClass | ClassTypeFlags.BuiltIn,
@ -73,10 +73,10 @@ export function createProperty(
isInstantiableClass(typeMetaclass) ? typeMetaclass : UnknownType.create()
);
propertyClass.details.declaration = decoratorType.details.declaration;
propertyClass.details.typeVarScopeId = decoratorType.details.typeVarScopeId;
propertyClass.shared.declaration = decoratorType.shared.declaration;
propertyClass.shared.typeVarScopeId = decoratorType.shared.typeVarScopeId;
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);
// Clone the symbol table of the old class type.
@ -92,19 +92,19 @@ export function createProperty(
});
const propertyObject = ClassType.cloneAsInstance(propertyClass);
propertyClass.isAsymmetricDescriptor = false;
propertyClass.priv.isAsymmetricDescriptor = false;
// Update the __set__ and __delete__ methods if present.
updateGetSetDelMethodForClonedProperty(evaluator, propertyObject);
// Fill in the fget method.
propertyObject.fgetInfo = {
methodType: FunctionType.cloneWithNewFlags(fget, fget.details.flags | FunctionTypeFlags.StaticMethod),
classType: fget.details.methodClass,
propertyObject.priv.fgetInfo = {
methodType: FunctionType.cloneWithNewFlags(fget, fget.shared.flags | FunctionTypeFlags.StaticMethod),
classType: fget.shared.methodClass,
};
if (FunctionType.isClassMethod(fget)) {
propertyClass.details.flags |= ClassTypeFlags.ClassProperty;
propertyClass.shared.flags |= ClassTypeFlags.ClassProperty;
}
// Fill in the __get__ method with an overload.
@ -127,8 +127,8 @@ export function clonePropertyWithSetter(
}
const classType = prop as ClassType;
const flagsToClone = classType.details.flags;
let isAsymmetricDescriptor = !!classType.isAsymmetricDescriptor;
const flagsToClone = classType.shared.flags;
let isAsymmetricDescriptor = !!classType.priv.isAsymmetricDescriptor;
// Verify parameters for fset.
// We'll skip this test if the diagnostic rule is disabled because it
@ -164,25 +164,25 @@ export function clonePropertyWithSetter(
}
const propertyClass = ClassType.createInstantiable(
classType.details.name,
classType.details.fullName,
classType.details.moduleName,
classType.shared.name,
classType.shared.fullName,
classType.shared.moduleName,
getFileInfo(errorNode).fileUri,
flagsToClone,
classType.details.typeSourceId,
classType.details.declaredMetaclass,
classType.details.effectiveMetaclass
classType.shared.typeSourceId,
classType.shared.declaredMetaclass,
classType.shared.effectiveMetaclass
);
propertyClass.details.declaration = classType.details.declaration;
propertyClass.details.typeVarScopeId = classType.details.typeVarScopeId;
propertyClass.shared.declaration = classType.shared.declaration;
propertyClass.shared.typeVarScopeId = classType.shared.typeVarScopeId;
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);
propertyClass.fgetInfo = classType.fgetInfo;
propertyClass.fdelInfo = classType.fdelInfo;
propertyClass.isAsymmetricDescriptor = isAsymmetricDescriptor;
propertyClass.priv.fgetInfo = classType.priv.fgetInfo;
propertyClass.priv.fdelInfo = classType.priv.fdelInfo;
propertyClass.priv.isAsymmetricDescriptor = isAsymmetricDescriptor;
const propertyObject = ClassType.cloneAsInstance(propertyClass);
// Clone the symbol table of the old class type.
@ -197,9 +197,9 @@ export function clonePropertyWithSetter(
updateGetSetDelMethodForClonedProperty(evaluator, propertyObject);
// Fill in the new fset method.
propertyObject.fsetInfo = {
methodType: FunctionType.cloneWithNewFlags(fset, fset.details.flags | FunctionTypeFlags.StaticMethod),
classType: fset.details.methodClass,
propertyObject.priv.fsetInfo = {
methodType: FunctionType.cloneWithNewFlags(fset, fset.shared.flags | FunctionTypeFlags.StaticMethod),
classType: fset.shared.methodClass,
};
// Fill in the __set__ method.
@ -223,26 +223,26 @@ export function clonePropertyWithDeleter(
const classType = prop as ClassType;
const propertyClass = ClassType.createInstantiable(
classType.details.name,
classType.details.fullName,
classType.details.moduleName,
classType.shared.name,
classType.shared.fullName,
classType.shared.moduleName,
getFileInfo(errorNode).fileUri,
classType.details.flags,
classType.details.typeSourceId,
classType.details.declaredMetaclass,
classType.details.effectiveMetaclass
classType.shared.flags,
classType.shared.typeSourceId,
classType.shared.declaredMetaclass,
classType.shared.effectiveMetaclass
);
propertyClass.details.declaration = classType.details.declaration;
propertyClass.details.typeVarScopeId = classType.details.typeVarScopeId;
propertyClass.shared.declaration = classType.shared.declaration;
propertyClass.shared.typeVarScopeId = classType.shared.typeVarScopeId;
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);
propertyClass.fgetInfo = classType.fgetInfo;
propertyClass.fsetInfo = classType.fsetInfo;
propertyClass.priv.fgetInfo = classType.priv.fgetInfo;
propertyClass.priv.fsetInfo = classType.priv.fsetInfo;
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.
const fields = ClassType.getSymbolTable(propertyClass);
@ -256,9 +256,9 @@ export function clonePropertyWithDeleter(
updateGetSetDelMethodForClonedProperty(evaluator, propertyObject);
// Fill in the fdel method.
propertyObject.fdelInfo = {
methodType: FunctionType.cloneWithNewFlags(fdel, fdel.details.flags | FunctionTypeFlags.StaticMethod),
classType: fdel.details.methodClass,
propertyObject.priv.fdelInfo = {
methodType: FunctionType.cloneWithNewFlags(fdel, fdel.shared.flags | FunctionTypeFlags.StaticMethod),
classType: fdel.shared.methodClass,
};
// Fill in the __delete__ method.
@ -294,15 +294,15 @@ function addGetMethodToPropertySymbolTable(evaluator: TypeEvaluator, propertyObj
AnyType.create(/* isEllipsis */ true)
)
);
getFunction1.details.declaredReturnType = FunctionType.isClassMethod(fget)
getFunction1.shared.declaredReturnType = FunctionType.isClassMethod(fget)
? FunctionType.getEffectiveReturnType(fget)
: propertyObject;
getFunction1.details.declaration = fget.details.declaration;
getFunction1.details.deprecatedMessage = fget.details.deprecatedMessage;
getFunction1.shared.declaration = fget.shared.declaration;
getFunction1.shared.deprecatedMessage = fget.shared.deprecatedMessage;
// Override the scope ID since we're using parameter types from the
// decorated function.
getFunction1.details.typeVarScopeId = getTypeVarScopeId(fget);
getFunction1.shared.typeVarScopeId = getTypeVarScopeId(fget);
// The second overload is for accesses through a class instance.
const getFunction2 = FunctionType.createSynthesizedInstance('__get__', FunctionTypeFlags.Overloaded);
@ -312,7 +312,7 @@ function addGetMethodToPropertySymbolTable(evaluator: TypeEvaluator, propertyObj
);
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(
getFunction2,
@ -329,13 +329,13 @@ function addGetMethodToPropertySymbolTable(evaluator: TypeEvaluator, propertyObj
AnyType.create(/* isEllipsis */ true)
)
);
getFunction2.details.declaredReturnType = FunctionType.getEffectiveReturnType(fget);
getFunction2.details.declaration = fget.details.declaration;
getFunction2.details.deprecatedMessage = fget.details.deprecatedMessage;
getFunction2.shared.declaredReturnType = FunctionType.getEffectiveReturnType(fget);
getFunction2.shared.declaration = fget.shared.declaration;
getFunction2.shared.deprecatedMessage = fget.shared.deprecatedMessage;
// Override the scope ID since we're using parameter types from the
// decorated function.
getFunction2.details.typeVarScopeId = getTypeVarScopeId(fget);
getFunction2.shared.typeVarScopeId = getTypeVarScopeId(fget);
// We previously placed getFunction1 before getFunction2, but this creates
// problems specifically for the `NoneType` class because None.__class__
@ -356,8 +356,8 @@ function addSetMethodToPropertySymbolTable(evaluator: TypeEvaluator, propertyObj
);
let objType =
fset.details.parameters.length > 0 ? FunctionType.getEffectiveParameterType(fset, 0) : AnyType.create();
if (isTypeVar(objType) && objType.details.isSynthesizedSelf) {
fset.shared.parameters.length > 0 ? FunctionType.getEffectiveParameterType(fset, 0) : AnyType.create();
if (isTypeVar(objType) && objType.shared.isSynthesizedSelf) {
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
// TypeVars that need to be solved.
setFunction.details.typeVarScopeId = getTypeVarScopeId(fset);
setFunction.details.deprecatedMessage = fset.details.deprecatedMessage;
setFunction.shared.typeVarScopeId = getTypeVarScopeId(fset);
setFunction.shared.deprecatedMessage = fset.shared.deprecatedMessage;
let setParamType: Type = UnknownType.create();
if (
fset.details.parameters.length >= 2 &&
fset.details.parameters[1].category === ParameterCategory.Simple &&
fset.details.parameters[1].name
fset.shared.parameters.length >= 2 &&
fset.shared.parameters[1].category === ParameterCategory.Simple &&
fset.shared.parameters[1].name
) {
setParamType = fset.details.parameters[1].type;
setParamType = fset.shared.parameters[1].type;
}
FunctionType.addParameter(
setFunction,
@ -406,13 +406,13 @@ function addDelMethodToPropertySymbolTable(evaluator: TypeEvaluator, propertyObj
// Adopt the TypeVarScopeId of the fdel function in case it has any
// TypeVars that need to be solved.
delFunction.details.typeVarScopeId = getTypeVarScopeId(fdel);
delFunction.details.deprecatedMessage = fdel.details.deprecatedMessage;
delFunction.shared.typeVarScopeId = getTypeVarScopeId(fdel);
delFunction.shared.deprecatedMessage = fdel.shared.deprecatedMessage;
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);
}
@ -425,23 +425,23 @@ function addDelMethodToPropertySymbolTable(evaluator: TypeEvaluator, propertyObj
'obj'
)
);
delFunction.details.declaredReturnType = evaluator.getNoneType();
delFunction.shared.declaredReturnType = evaluator.getNoneType();
const delSymbol = Symbol.createWithType(SymbolFlags.ClassMember, delFunction);
fields.set('__delete__', delSymbol);
}
function updateGetSetDelMethodForClonedProperty(evaluator: TypeEvaluator, propertyObject: ClassType) {
const fgetInfo = propertyObject.fgetInfo;
const fgetInfo = propertyObject.priv.fgetInfo;
if (fgetInfo && isFunction(fgetInfo.methodType)) {
addGetMethodToPropertySymbolTable(evaluator, propertyObject, fgetInfo.methodType);
}
const fsetInfo = propertyObject.fsetInfo;
const fsetInfo = propertyObject.priv.fsetInfo;
if (fsetInfo && isFunction(fsetInfo.methodType)) {
addSetMethodToPropertySymbolTable(evaluator, propertyObject, fsetInfo.methodType);
}
const fdelInfo = propertyObject.fdelInfo;
const fdelInfo = propertyObject.priv.fdelInfo;
if (fdelInfo && isFunction(fdelInfo.methodType)) {
addDelMethodToPropertySymbolTable(evaluator, propertyObject, fdelInfo.methodType);
}
@ -466,7 +466,7 @@ function addDecoratorMethodsToPropertySymbolTable(propertyObject: ClassType) {
'accessor'
)
);
accessorFunction.details.declaredReturnType = propertyObject;
accessorFunction.shared.declaredReturnType = propertyObject;
const accessorSymbol = Symbol.createWithType(SymbolFlags.ClassMember, accessorFunction);
fields.set(accessorName, accessorSymbol);
});
@ -492,17 +492,17 @@ export function assignProperty(
incompatibleDiagMsg: () => string;
}[] = [
{
getFunction: (c: ClassType) => c.fgetInfo?.methodType,
getFunction: (c: ClassType) => c.priv.fgetInfo?.methodType,
missingDiagMsg: LocAddendum.missingGetter,
incompatibleDiagMsg: LocAddendum.incompatibleGetter,
},
{
getFunction: (c: ClassType) => c.fsetInfo?.methodType,
getFunction: (c: ClassType) => c.priv.fsetInfo?.methodType,
missingDiagMsg: LocAddendum.missingSetter,
incompatibleDiagMsg: LocAddendum.incompatibleSetter,
},
{
getFunction: (c: ClassType) => c.fdelInfo?.methodType,
getFunction: (c: ClassType) => c.priv.fdelInfo?.methodType,
missingDiagMsg: LocAddendum.missingDeleter,
incompatibleDiagMsg: LocAddendum.incompatibleDeleter,
},
@ -535,12 +535,12 @@ export function assignProperty(
// here and bind them to the associated objects.
destAccessType = FunctionType.cloneWithNewFlags(
destAccessType,
destAccessType.details.flags & ~FunctionTypeFlags.StaticMethod
destAccessType.shared.flags & ~FunctionTypeFlags.StaticMethod
);
srcAccessType = FunctionType.cloneWithNewFlags(
srcAccessType,
srcAccessType.details.flags & ~FunctionTypeFlags.StaticMethod
srcAccessType.shared.flags & ~FunctionTypeFlags.StaticMethod
);
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.
for (const baseClass of classType.details.baseClasses) {
for (const baseClass of classType.shared.baseClasses) {
if (isClass(baseClass) && ClassType.isProtocolClass(baseClass) && !isMethodOnlyProtocol(baseClass)) {
return false;
}
@ -208,7 +208,7 @@ export function isProtocolUnsafeOverlap(evaluator: TypeEvaluator, protocol: Clas
let isUnsafeOverlap = true;
protocol.details.mro.forEach((mroClass) => {
protocol.shared.mro.forEach((mroClass) => {
if (!isUnsafeOverlap || !isInstantiableClass(mroClass) || !ClassType.isProtocolClass(mroClass)) {
return;
}
@ -237,8 +237,8 @@ function getProtocolCompatibility(
flags: AssignTypeFlags,
typeVarContext: TypeVarContext | undefined
): boolean | undefined {
const map = srcType.details.protocolCompatibility as Map<string, ProtocolCompatibility[]> | undefined;
const entries = map?.get(destType.details.fullName);
const map = srcType.shared.protocolCompatibility as Map<string, ProtocolCompatibility[]> | undefined;
const entries = map?.get(destType.shared.fullName);
if (entries === undefined) {
return undefined;
}
@ -262,16 +262,16 @@ function setProtocolCompatibility(
typeVarContext: TypeVarContext | undefined,
isCompatible: boolean
) {
let map = srcType.details.protocolCompatibility as Map<string, ProtocolCompatibility[]> | undefined;
let map = srcType.shared.protocolCompatibility as Map<string, ProtocolCompatibility[]> | undefined;
if (!map) {
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) {
entries = [];
map.set(destType.details.fullName, entries);
map.set(destType.shared.fullName, entries);
}
entries.push({
@ -319,7 +319,7 @@ function assignClassToProtocolInternal(
if (isClass(srcType)) {
// If the srcType is conditioned on "self", use "Self" as the 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(
TypeBase.cloneForCondition(srcType, undefined),
/* isClsType */ false
@ -349,7 +349,7 @@ function assignClassToProtocolInternal(
? AssignTypeFlags.RetainLiteralsForTypeVar
: AssignTypeFlags.Default;
destType.details.mro.forEach((mroClass) => {
destType.shared.mro.forEach((mroClass) => {
if (!isInstantiableClass(mroClass) || !ClassType.isProtocolClass(mroClass)) {
return;
}
@ -403,10 +403,10 @@ function assignClassToProtocolInternal(
// Look in the metaclass first if we're treating the source as an instantiable class.
if (
sourceIsClassObject &&
srcType.details.effectiveMetaclass &&
isInstantiableClass(srcType.details.effectiveMetaclass)
srcType.shared.effectiveMetaclass &&
isInstantiableClass(srcType.shared.effectiveMetaclass)
) {
srcMemberInfo = lookUpClassMember(srcType.details.effectiveMetaclass, name);
srcMemberInfo = lookUpClassMember(srcType.shared.effectiveMetaclass, name);
if (srcMemberInfo) {
isMemberFromMetaclass = true;
}
@ -490,7 +490,7 @@ function assignClassToProtocolInternal(
isSrcReadOnly = true;
}
} else {
srcSymbol = srcType.fields.get(name);
srcSymbol = srcType.priv.fields.get(name);
if (!srcSymbol) {
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 (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
// make sure the resulting type args can be assigned.
const genericProtocolType = ClassType.cloneForSpecialization(
@ -726,7 +726,7 @@ function assignClassToProtocolInternal(
);
const specializedProtocolType = applySolvedTypeVars(genericProtocolType, protocolTypeVarContext) as ClassType;
if (destType.typeArguments) {
if (destType.priv.typeArguments) {
if (
!evaluator.assignTypeArguments(
destType,
@ -741,7 +741,7 @@ function assignClassToProtocolInternal(
typesAreConsistent = false;
}
} 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);
if (typeArgEntry) {
@ -769,7 +769,7 @@ function createProtocolTypeVarContext(
): TypeVarContext {
const protocolTypeVarContext = new TypeVarContext(getTypeVarScopeId(destType));
destType.details.typeParameters.forEach((typeParam, index) => {
destType.shared.typeParameters.forEach((typeParam, index) => {
const entry = destTypeVarContext?.getPrimarySignature().getTypeVar(typeParam);
if (entry) {
@ -779,8 +779,8 @@ function createProtocolTypeVarContext(
entry.narrowBoundNoLiterals,
entry.wideBound
);
} else if (destType.typeArguments && index < destType.typeArguments.length) {
let typeArg = destType.typeArguments[index];
} else if (destType.priv.typeArguments && index < destType.priv.typeArguments.length) {
let typeArg = destType.priv.typeArguments[index];
let flags: AssignTypeFlags;
let hasUnsolvedTypeVars = requiresSpecialization(typeArg);

View File

@ -518,10 +518,10 @@ export class SourceMapper {
return;
}
if (isFunction(type) && type.details.declaration) {
this._addClassOrFunctionDeclarations(type.details.declaration, result, recursiveDeclCache);
if (isFunction(type) && type.shared.declaration) {
this._addClassOrFunctionDeclarations(type.shared.declaration, result, recursiveDeclCache);
} 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);
}
} else if (isInstantiableClass(type)) {
@ -601,13 +601,13 @@ export class SourceMapper {
useTypeAlias = false
) {
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 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 =
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 */);
for (const sourceFile of sourceFiles) {

View File

@ -63,31 +63,31 @@ export function createTracePrinter(roots: Uri[]): TracePrinter {
case TypeCategory.Class:
if (TypeBase.isInstantiable(type)) {
return `Class '${type.details.name}' (${type.details.moduleName})`;
return `Class '${type.shared.name}' (${type.shared.moduleName})`;
} else {
return `Object '${type.details.name}' (${type.details.moduleName})`;
return `Object '${type.shared.name}' (${type.shared.moduleName})`;
}
case TypeCategory.Function:
return `Function '${type.details.name}' (${type.details.moduleName})`;
return `Function '${type.shared.name}' (${type.shared.moduleName})`;
case TypeCategory.Module:
return `Module '${type.moduleName}' (${type.moduleName})`;
return `Module '${type.priv.moduleName}' (${type.priv.moduleName})`;
case TypeCategory.Never:
return `Never ${wrap(type.props?.typeAliasInfo?.fullName)}`;
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:
return `TypeVar '${type.details.name}' ${wrap(type.props?.typeAliasInfo?.fullName)}`;
return `TypeVar '${type.shared.name}' ${wrap(type.props?.typeAliasInfo?.fullName)}`;
case TypeCategory.Unbound:
return `Unbound ${wrap(type.props?.typeAliasInfo?.fullName)}`;
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:
return `Unknown ${wrap(type.props?.typeAliasInfo?.fullName)}`;

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

@ -137,9 +137,9 @@ export class TypeWalker {
}
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.
if (type.details.parameters[i].name) {
if (type.shared.parameters[i].name) {
const paramType = FunctionType.getEffectiveParameterType(type, i);
this.walk(paramType);
if (this._isWalkCanceled) {
@ -149,7 +149,7 @@ export class TypeWalker {
}
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) {
this.walk(returnType);
}
@ -157,7 +157,7 @@ export class TypeWalker {
}
visitOverloadedFunction(type: OverloadedFunctionType): void {
for (const overload of type.overloads) {
for (const overload of type.priv.overloads) {
this.walk(overload);
if (this._isWalkCanceled) {
break;
@ -167,7 +167,7 @@ export class TypeWalker {
visitClass(type: ClassType): void {
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) {
for (const argType of typeArgs) {
this.walk(argType);
@ -184,7 +184,7 @@ export class TypeWalker {
}
visitUnion(type: UnionType): void {
for (const subtype of type.subtypes) {
for (const subtype of type.priv.subtypes) {
this.walk(subtype);
if (this._isWalkCanceled) {
break;

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -20,7 +20,7 @@ import {
TypeBase,
TypeCategory,
TypeFlags,
TypeVarDetails,
TypeVarDetailsShared,
TypeVarType,
Variance,
} from '../analyzer/types';
@ -337,15 +337,15 @@ function getTypeEvaluatorString(
if (!isNumber(value) && !isString(value)) {
if (set.has(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)) {
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)) {
return `<cycle> function '${value.details.name}' scope id:${value.nameWithScope}`;
return `<cycle> function '${value.shared.name}' scope id:${value.priv.nameWithScope}`;
}
return undefined;
@ -417,7 +417,7 @@ function getTypeEvaluatorString(
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;
}

View File

@ -425,8 +425,8 @@ export class CompletionProvider {
}
const symbolTable = new Map<string, Symbol>();
for (let i = 1; i < classResults.classType.details.mro.length; i++) {
const mroClass = classResults.classType.details.mro[i];
for (let i = 1; i < classResults.classType.shared.mro.length; i++) {
const mroClass = classResults.classType.shared.mro[i];
if (isInstantiableClass(mroClass)) {
getMembersForClass(mroClass, symbolTable, /* includeInstanceVars */ false);
}
@ -523,9 +523,9 @@ export class CompletionProvider {
let sb = this.parseResults.tokenizerOutput.predominantTabSequence;
if (
classType.details.baseClasses.length === 1 &&
isClass(classType.details.baseClasses[0]) &&
classType.details.baseClasses[0].details.fullName === 'builtins.object'
classType.shared.baseClasses.length === 1 &&
isClass(classType.shared.baseClasses[0]) &&
classType.shared.baseClasses[0].shared.fullName === 'builtins.object'
) {
sb += this.options.snippet ? '${0:pass}' : 'pass';
return sb;
@ -744,8 +744,8 @@ export class CompletionProvider {
// If this is an unknown type with a "possible type" associated with
// it, use the possible type.
if (isUnknown(leftType) && leftType.possibleType) {
leftType = this.evaluator.makeTopLevelTypeVarsConcrete(leftType.possibleType);
if (isUnknown(leftType) && leftType.priv.possibleType) {
leftType = this.evaluator.makeTopLevelTypeVarsConcrete(leftType.priv.possibleType);
}
doForEachSubtype(leftType, (subtype) => {
@ -1657,7 +1657,7 @@ export class CompletionProvider {
// If we can't do that using semantic info, then try syntactic info.
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) {
// Ignore current type.
continue;
@ -1717,7 +1717,7 @@ export class CompletionProvider {
}
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)) {
getMembersForClass(mroClass, symbolTable, /* includeInstanceVars */ false);
}
@ -1799,7 +1799,7 @@ export class CompletionProvider {
}
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)) {
getMembersForClass(mroClass, symbolTable, /* includeInstanceVars */ false);
}
@ -1826,7 +1826,7 @@ export class CompletionProvider {
if (isStubFile(this.fileUri)) {
// In stubs, always use "...".
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.
ellipsisForDefault = false;
}
@ -2035,13 +2035,13 @@ export class CompletionProvider {
}
const type = signature.type;
const paramIndex = type.details.parameters.indexOf(signature.activeParam);
const paramIndex = type.shared.parameters.indexOf(signature.activeParam);
if (paramIndex < 0) {
return undefined;
}
const paramType = type.details.parameters[paramIndex].type;
const paramType = type.shared.parameters[paramIndex].type;
this._addLiteralValuesForTargetType(paramType, priorWord, priorText, postText, completionMap);
return undefined;
});
@ -2060,7 +2060,7 @@ export class CompletionProvider {
const value = printLiteralValue(v, quoteValue.quoteCharacter);
if (quoteValue.stringValue === undefined) {
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 {
this._addStringLiteralToCompletions(
@ -2131,8 +2131,8 @@ export class CompletionProvider {
// Handle both overloaded and non-overloaded functions.
doForEachSignature(getItemType, (signature) => {
if (
signature.details.parameters.length >= 1 &&
signature.details.parameters[0].category === ParameterCategory.Simple
signature.shared.parameters.length >= 1 &&
signature.shared.parameters[0].category === ParameterCategory.Simple
) {
typesToCombine.push(FunctionType.getEffectiveParameterType(signature, 0));
}
@ -2816,8 +2816,10 @@ export class CompletionProvider {
// Add keys from typed dict outside signatures.
signatureInfo.signatures.forEach((signature) => {
if (signature.type.boundToType) {
const keys = Array.from(signature.type.boundToType.details.typedDictEntries?.knownItems.keys() || []);
if (signature.type.priv.boundToType) {
const keys = Array.from(
signature.type.priv.boundToType.shared.typedDictEntries?.knownItems.keys() || []
);
keys.forEach((key: string) => argNameSet.add(key));
}
});
@ -2889,7 +2891,7 @@ export class CompletionProvider {
if (curNode.nodeType === ParseNodeType.Class) {
const classType = this.evaluator.getTypeOfClass(curNode);
if (classType && isInstantiableClass(classType.classType)) {
classType.classType.details.mro.forEach((baseClass, index) => {
classType.classType.shared.mro.forEach((baseClass, index) => {
if (isInstantiableClass(baseClass)) {
this._addSymbolsForSymbolTable(
ClassType.getSymbolTable(baseClass),
@ -3148,7 +3150,7 @@ export class CompletionProvider {
symbolType &&
isClassInstance(symbolType) &&
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 { convertPositionToOffset } from '../common/positionUtils';
import { ServiceKeys } from '../common/serviceKeys';
import { ServiceProvider } from '../common/serviceProvider';
import { DocumentRange, Position, rangesAreEqual } from '../common/textRange';
import { Uri } from '../common/uri/uri';
import { ParseNode, ParseNodeType } from '../parser/parseNodes';
import { ParseFileResults } from '../parser/parser';
import { ServiceProvider } from '../common/serviceProvider';
export enum DefinitionFilter {
All = 'all',
@ -89,7 +89,9 @@ export function addDeclarationsToDefinitions(
// Handle overloaded function case
const functionType = evaluator.getTypeForDeclaration(resolvedDecl)?.type;
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, {
uri: overloadDecl.uri,
range: overloadDecl.range,

View File

@ -450,7 +450,7 @@ function _getDeclarationsForNonModuleNameNode(
const type = evaluator.getType(node);
if (type?.category === TypeCategory.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);
if (typeAliasInfo?.name === typeNode.value) {
if (isTypeVar(type)) {
label = type.details.isParamSpec ? 'param spec' : 'type variable';
typeVarName = type.details.name;
label = type.shared.isParamSpec ? 'param spec' : 'type variable';
typeVarName = type.shared.name;
} else {
// Handle type aliases specially.
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.
doForEachSubtype(type, (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 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.

View File

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

View File

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

View File

@ -137,11 +137,11 @@ test('property', () => {
assert(isProperty(result.decoratedType));
assert(isClassInstance(result.decoratedType));
assert(result.decoratedType.details.declaration);
assert(isClassDeclaration(result.decoratedType.details.declaration));
assert(result.decoratedType.shared.declaration);
assert(isClassDeclaration(result.decoratedType.shared.declaration));
assert(result.decoratedType.details.declaration.moduleName === 'builtins');
assert(result.decoratedType.details.declaration.node.name.value === 'property');
assert(result.decoratedType.shared.declaration.moduleName === 'builtins');
assert(result.decoratedType.shared.declaration.node.name.value === 'property');
});
});
@ -154,13 +154,13 @@ function checkSpecialBuiltInClassDetail(code: string) {
const type = state.program.evaluator!.getType(node);
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);
if (type.aliasName) {
assert(isClassDeclaration(type.details.declaration));
assert(type.shared.declaration);
if (type.priv.aliasName) {
assert(isClassDeclaration(type.shared.declaration));
} 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);
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) {
assert(type.details.declaration);
assert(isClassDeclaration(type.details.declaration));
assert(type.shared.declaration);
assert(isClassDeclaration(type.shared.declaration));
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)
);
} else {
// 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);
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.moduleName, 'test');

View File

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