mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-17 11:17:17 +03:00
Renamed some internal functions and constants for consistency and clarity.
This commit is contained in:
parent
e2adef6b88
commit
7c5495c1b4
@ -2685,8 +2685,8 @@ export class Checker extends ParseTreeWalker {
|
||||
for (let i = 0; i < prevOverloads.length; i++) {
|
||||
const prevOverload = prevOverloads[i];
|
||||
if (this._isOverlappingOverload(prevOverload, functionType, /* partialOverlap */ true)) {
|
||||
const prevReturnType = FunctionType.getSpecializedReturnType(prevOverload);
|
||||
const returnType = FunctionType.getSpecializedReturnType(functionType);
|
||||
const prevReturnType = FunctionType.getEffectiveReturnType(prevOverload);
|
||||
const returnType = FunctionType.getEffectiveReturnType(functionType);
|
||||
|
||||
if (
|
||||
prevReturnType &&
|
||||
@ -5601,15 +5601,11 @@ export class Checker extends ParseTreeWalker {
|
||||
// because we don't care about the return type for this check.
|
||||
initMemberType = FunctionType.cloneWithNewFlags(
|
||||
initMemberType,
|
||||
initMemberType.details.flags |
|
||||
FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck |
|
||||
FunctionTypeFlags.ParamSpecValue
|
||||
initMemberType.details.flags | FunctionTypeFlags.GradualCallableForm | FunctionTypeFlags.ParamSpecValue
|
||||
);
|
||||
newMemberType = FunctionType.cloneWithNewFlags(
|
||||
newMemberType,
|
||||
initMemberType.details.flags |
|
||||
FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck |
|
||||
FunctionTypeFlags.ParamSpecValue
|
||||
initMemberType.details.flags | FunctionTypeFlags.GradualCallableForm | FunctionTypeFlags.ParamSpecValue
|
||||
);
|
||||
|
||||
if (
|
||||
@ -7158,7 +7154,7 @@ export class Checker extends ParseTreeWalker {
|
||||
return;
|
||||
}
|
||||
|
||||
const declaredReturnType = FunctionType.getSpecializedReturnType(functionTypeResult.functionType);
|
||||
const declaredReturnType = FunctionType.getEffectiveReturnType(functionTypeResult.functionType);
|
||||
if (!declaredReturnType) {
|
||||
return;
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ export function assignTypeToTypeVar(
|
||||
destType.details.isParamSpec &&
|
||||
isFunction(srcType) &&
|
||||
FunctionType.isParamSpecValue(srcType) &&
|
||||
FunctionType.shouldSkipArgsKwargsCompatibilityCheck(srcType)
|
||||
FunctionType.isGradualCallableForm(srcType)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
@ -971,7 +971,7 @@ function assignTypeToParamSpec(
|
||||
// "..." (which is the ParamSpec equivalent of "Any"). If only one has
|
||||
// the type "...", we'll prefer the other one. This is analogous to
|
||||
// what we do with regular TypeVars, where we prefer non-Any values.
|
||||
if (!FunctionType.shouldSkipArgsKwargsCompatibilityCheck(newFunction)) {
|
||||
if (!FunctionType.isGradualCallableForm(newFunction)) {
|
||||
updateContextWithNewFunction = true;
|
||||
} else {
|
||||
return;
|
||||
|
@ -474,7 +474,7 @@ function applyPartialTransformToFunction(
|
||||
});
|
||||
|
||||
newCallMemberType.details.declaredReturnType = specializedFunctionType.details.declaredReturnType
|
||||
? FunctionType.getSpecializedReturnType(specializedFunctionType)
|
||||
? FunctionType.getEffectiveReturnType(specializedFunctionType)
|
||||
: specializedFunctionType.inferredReturnType;
|
||||
newCallMemberType.details.declaration = partialCallMemberType.details.declaration;
|
||||
newCallMemberType.details.typeVarScopeId = specializedFunctionType.details.typeVarScopeId;
|
||||
|
@ -858,7 +858,7 @@ export function createFunctionFromConstructor(
|
||||
let skipInitMethod = false;
|
||||
|
||||
doForEachSignature(fromNew, (signature) => {
|
||||
const newMethodReturnType = FunctionType.getSpecializedReturnType(signature);
|
||||
const newMethodReturnType = FunctionType.getEffectiveReturnType(signature);
|
||||
if (newMethodReturnType && shouldSkipInitEvaluation(evaluator, classType, newMethodReturnType)) {
|
||||
skipInitMethod = true;
|
||||
}
|
||||
@ -932,7 +932,7 @@ function createFunctionFromMetaclassCall(
|
||||
// constructed.
|
||||
doForEachSignature(boundCallType, (signature) => {
|
||||
if (signature.details.declaredReturnType) {
|
||||
const returnType = FunctionType.getSpecializedReturnType(signature);
|
||||
const returnType = FunctionType.getEffectiveReturnType(signature);
|
||||
if (returnType && shouldSkipNewAndInitEvaluation(evaluator, classType, returnType)) {
|
||||
useMetaclassCall = true;
|
||||
}
|
||||
|
@ -806,7 +806,7 @@ function getConverterInputType(
|
||||
|
||||
if (
|
||||
evaluator.assignType(
|
||||
FunctionType.getSpecializedReturnType(signature) ?? UnknownType.create(),
|
||||
FunctionType.getEffectiveReturnType(signature) ?? UnknownType.create(),
|
||||
fieldType,
|
||||
/* diag */ undefined,
|
||||
returnTypeVarContext
|
||||
|
@ -818,7 +818,7 @@ function narrowTypeBasedOnClassPattern(
|
||||
// Convert to an unknown callable type.
|
||||
const unknownCallable = FunctionType.createSynthesizedInstance(
|
||||
'',
|
||||
FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck
|
||||
FunctionTypeFlags.GradualCallableForm
|
||||
);
|
||||
FunctionType.addDefaultParameters(
|
||||
unknownCallable,
|
||||
|
@ -295,7 +295,7 @@ function addGetMethodToPropertySymbolTable(evaluator: TypeEvaluator, propertyObj
|
||||
defaultType: AnyType.create(),
|
||||
});
|
||||
getFunction1.details.declaredReturnType = FunctionType.isClassMethod(fget)
|
||||
? FunctionType.getSpecializedReturnType(fget)
|
||||
? FunctionType.getEffectiveReturnType(fget)
|
||||
: propertyObject;
|
||||
getFunction1.details.declaration = fget.details.declaration;
|
||||
getFunction1.details.deprecatedMessage = fget.details.deprecatedMessage;
|
||||
@ -331,7 +331,7 @@ function addGetMethodToPropertySymbolTable(evaluator: TypeEvaluator, propertyObj
|
||||
hasDefault: true,
|
||||
defaultType: AnyType.create(),
|
||||
});
|
||||
getFunction2.details.declaredReturnType = FunctionType.getSpecializedReturnType(fget);
|
||||
getFunction2.details.declaredReturnType = FunctionType.getEffectiveReturnType(fget);
|
||||
getFunction2.details.declaration = fget.details.declaration;
|
||||
getFunction2.details.deprecatedMessage = fget.details.deprecatedMessage;
|
||||
|
||||
|
@ -6275,7 +6275,7 @@ export function createTypeEvaluator(
|
||||
// If there's no declared return type on the getter, assume it's symmetric.
|
||||
if (setterType.details.parameters.length >= 3 && getterType.details.declaredReturnType) {
|
||||
const setterValueType = FunctionType.getEffectiveParameterType(setterType, 2);
|
||||
const getterReturnType = FunctionType.getSpecializedReturnType(getterType) ?? UnknownType.create();
|
||||
const getterReturnType = FunctionType.getEffectiveReturnType(getterType) ?? UnknownType.create();
|
||||
|
||||
if (!isTypeSame(setterValueType, getterReturnType)) {
|
||||
isAsymmetric = true;
|
||||
@ -6312,7 +6312,7 @@ export function createTypeEvaluator(
|
||||
// If there's no declared return type on the getter, assume it's symmetric.
|
||||
if (setterType.details.parameters.length >= 3 && getterType.details.declaredReturnType) {
|
||||
const setterValueType = FunctionType.getEffectiveParameterType(setterType, 2);
|
||||
const getterReturnType = FunctionType.getSpecializedReturnType(getterType) ?? UnknownType.create();
|
||||
const getterReturnType = FunctionType.getEffectiveReturnType(getterType) ?? UnknownType.create();
|
||||
|
||||
if (!isTypeSame(setterValueType, getterReturnType)) {
|
||||
isAsymmetric = true;
|
||||
@ -6797,7 +6797,7 @@ export function createTypeEvaluator(
|
||||
FunctionType.addParamSpecVariadics(functionType, typeArg);
|
||||
} else if (isEllipsisType(typeArg)) {
|
||||
FunctionType.addDefaultParameters(functionType);
|
||||
functionType.details.flags |= FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck;
|
||||
functionType.details.flags |= FunctionTypeFlags.GradualCallableForm;
|
||||
}
|
||||
} else {
|
||||
FunctionType.addParameter(functionType, {
|
||||
@ -6822,7 +6822,7 @@ export function createTypeEvaluator(
|
||||
} else if (isEllipsisType(typeArgType)) {
|
||||
const functionType = FunctionType.createSynthesizedInstance(
|
||||
'',
|
||||
FunctionTypeFlags.ParamSpecValue | FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck
|
||||
FunctionTypeFlags.ParamSpecValue | FunctionTypeFlags.GradualCallableForm
|
||||
);
|
||||
FunctionType.addDefaultParameters(functionType);
|
||||
assignTypeToTypeVar(evaluatorInterface, param, functionType, diag, typeVarContext);
|
||||
@ -11240,7 +11240,7 @@ export function createTypeEvaluator(
|
||||
isAnyOrUnknown(inferenceContext.expectedType) ||
|
||||
isNever(inferenceContext.expectedType) ||
|
||||
!type.details.declaredReturnType ||
|
||||
!requiresSpecialization(FunctionType.getSpecializedReturnType(type) ?? UnknownType.create())
|
||||
!requiresSpecialization(FunctionType.getEffectiveReturnType(type) ?? UnknownType.create())
|
||||
) {
|
||||
return validateFunctionArgumentTypes(
|
||||
errorNode,
|
||||
@ -12733,7 +12733,7 @@ export function createTypeEvaluator(
|
||||
|
||||
if (node.nodeType === ParseNodeType.Ellipsis) {
|
||||
FunctionType.addDefaultParameters(functionType);
|
||||
functionType.details.flags |= FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck;
|
||||
functionType.details.flags |= FunctionTypeFlags.GradualCallableForm;
|
||||
return functionType;
|
||||
}
|
||||
|
||||
@ -14225,7 +14225,7 @@ export function createTypeEvaluator(
|
||||
if (enclosingFunction) {
|
||||
const functionTypeInfo = getTypeOfFunction(enclosingFunction);
|
||||
if (functionTypeInfo) {
|
||||
const returnType = FunctionType.getSpecializedReturnType(functionTypeInfo.functionType);
|
||||
const returnType = FunctionType.getEffectiveReturnType(functionTypeInfo.functionType);
|
||||
if (returnType) {
|
||||
expectedYieldType = getGeneratorYieldType(returnType, !!enclosingFunction.isAsync);
|
||||
|
||||
@ -14871,7 +14871,7 @@ export function createTypeEvaluator(
|
||||
}
|
||||
} else if (isEllipsisType(typeArgs[0].type)) {
|
||||
FunctionType.addDefaultParameters(functionType);
|
||||
functionType.details.flags |= FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck;
|
||||
functionType.details.flags |= FunctionTypeFlags.GradualCallableForm;
|
||||
} else if (isParamSpec(typeArgs[0].type)) {
|
||||
paramSpec = typeArgs[0].type;
|
||||
} else {
|
||||
@ -14886,7 +14886,7 @@ export function createTypeEvaluator(
|
||||
paramSpec = typeArg;
|
||||
} else if (isEllipsisType(typeArg)) {
|
||||
FunctionType.addDefaultParameters(functionType);
|
||||
functionType.details.flags |= FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck;
|
||||
functionType.details.flags |= FunctionTypeFlags.GradualCallableForm;
|
||||
}
|
||||
} else {
|
||||
FunctionType.addParameter(functionType, {
|
||||
@ -14921,7 +14921,7 @@ export function createTypeEvaluator(
|
||||
}
|
||||
} else {
|
||||
FunctionType.addDefaultParameters(functionType, /* useUnknown */ true);
|
||||
functionType.details.flags |= FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck;
|
||||
functionType.details.flags |= FunctionTypeFlags.GradualCallableForm;
|
||||
}
|
||||
|
||||
if (paramSpec) {
|
||||
@ -18117,7 +18117,7 @@ export function createTypeEvaluator(
|
||||
isParamSpec(paramType2) &&
|
||||
paramType2.paramSpecAccess === 'kwargs'
|
||||
) {
|
||||
functionType.details.flags |= FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck;
|
||||
functionType.details.flags |= FunctionTypeFlags.GradualCallableForm;
|
||||
}
|
||||
}
|
||||
|
||||
@ -18128,7 +18128,7 @@ export function createTypeEvaluator(
|
||||
(param) => param.category !== ParameterCategory.Simple && param.name && isAnyOrUnknown(param.type)
|
||||
);
|
||||
if (variadicsWithAnyType.length >= 2) {
|
||||
functionType.details.flags |= FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck;
|
||||
functionType.details.flags |= FunctionTypeFlags.GradualCallableForm;
|
||||
}
|
||||
|
||||
// If there was a defined return type, analyze that first so when we
|
||||
@ -20283,7 +20283,7 @@ export function createTypeEvaluator(
|
||||
|
||||
if (isEllipsisType(typeArg.type)) {
|
||||
FunctionType.addDefaultParameters(functionType);
|
||||
functionType.details.flags |= FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck;
|
||||
functionType.details.flags |= FunctionTypeFlags.GradualCallableForm;
|
||||
typeArgTypes.push(functionType);
|
||||
typeVarContext.setTypeVarType(typeParam, convertTypeToParamSpecValue(functionType));
|
||||
return;
|
||||
@ -20318,8 +20318,7 @@ export function createTypeEvaluator(
|
||||
FunctionType.addParamSpecVariadics(functionType, typeArg);
|
||||
} else if (isEllipsisType(typeArg)) {
|
||||
FunctionType.addDefaultParameters(functionType);
|
||||
functionType.details.flags |=
|
||||
FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck;
|
||||
functionType.details.flags |= FunctionTypeFlags.GradualCallableForm;
|
||||
}
|
||||
} else {
|
||||
FunctionType.addParameter(functionType, {
|
||||
@ -21994,7 +21993,7 @@ export function createTypeEvaluator(
|
||||
callSiteInfo?: CallSiteEvaluationInfo,
|
||||
inferTypeIfNeeded = true
|
||||
) {
|
||||
const specializedReturnType = FunctionType.getSpecializedReturnType(type, /* includeInferred */ false);
|
||||
const specializedReturnType = FunctionType.getEffectiveReturnType(type, /* includeInferred */ false);
|
||||
if (specializedReturnType && !isUnknown(specializedReturnType)) {
|
||||
const liveTypeVarScopes = callSiteInfo?.errorNode
|
||||
? ParseTreeUtils.getTypeVarScopesForNode(callSiteInfo?.errorNode)
|
||||
@ -23566,7 +23565,7 @@ export function createTypeEvaluator(
|
||||
if (
|
||||
isParamSpec(srcType) &&
|
||||
isFunction(destType) &&
|
||||
FunctionType.shouldSkipArgsKwargsCompatibilityCheck(destType) &&
|
||||
FunctionType.isGradualCallableForm(destType) &&
|
||||
destType.details.parameters.length <= 2
|
||||
) {
|
||||
return true;
|
||||
@ -25267,7 +25266,7 @@ export function createTypeEvaluator(
|
||||
}
|
||||
|
||||
if (
|
||||
!FunctionType.shouldSkipArgsKwargsCompatibilityCheck(destType) &&
|
||||
!FunctionType.isGradualCallableForm(destType) &&
|
||||
destParamDetails.firstPositionOrKeywordIndex < srcParamDetails.positionOnlyParamCount &&
|
||||
!targetIncludesParamSpec
|
||||
) {
|
||||
@ -25426,7 +25425,7 @@ export function createTypeEvaluator(
|
||||
if (
|
||||
srcParamDetails.argsIndex !== undefined &&
|
||||
destParamDetails.argsIndex !== undefined &&
|
||||
!FunctionType.shouldSkipArgsKwargsCompatibilityCheck(destType)
|
||||
!FunctionType.isGradualCallableForm(destType)
|
||||
) {
|
||||
let destArgsType = destParamDetails.params[destParamDetails.argsIndex].type;
|
||||
let srcArgsType = srcParamDetails.params[srcParamDetails.argsIndex].type;
|
||||
@ -25458,7 +25457,7 @@ export function createTypeEvaluator(
|
||||
// If the dest has an "*args" but the source doesn't, report the incompatibility.
|
||||
// The converse situation is OK.
|
||||
if (
|
||||
!FunctionType.shouldSkipArgsKwargsCompatibilityCheck(destType) &&
|
||||
!FunctionType.isGradualCallableForm(destType) &&
|
||||
srcParamDetails.argsIndex === undefined &&
|
||||
srcParamSpec === undefined &&
|
||||
destParamDetails.argsIndex !== undefined &&
|
||||
@ -25650,7 +25649,7 @@ export function createTypeEvaluator(
|
||||
// If the dest has a "**kwargs" but the source doesn't, report the incompatibility.
|
||||
// The converse situation is OK.
|
||||
if (
|
||||
!FunctionType.shouldSkipArgsKwargsCompatibilityCheck(destType) &&
|
||||
!FunctionType.isGradualCallableForm(destType) &&
|
||||
srcParamDetails.kwargsIndex === undefined &&
|
||||
srcParamSpec === undefined &&
|
||||
destParamDetails.kwargsIndex !== undefined
|
||||
@ -26258,10 +26257,7 @@ export function createTypeEvaluator(
|
||||
|
||||
let canOverride = true;
|
||||
|
||||
if (
|
||||
!FunctionType.shouldSkipArgsKwargsCompatibilityCheck(baseMethod) &&
|
||||
!FunctionType.shouldSkipArgsKwargsCompatibilityCheck(overrideMethod)
|
||||
) {
|
||||
if (!FunctionType.isGradualCallableForm(baseMethod) && !FunctionType.isGradualCallableForm(overrideMethod)) {
|
||||
// Verify that we're not overriding a static, class or instance method with
|
||||
// an incompatible type.
|
||||
if (FunctionType.isStaticMethod(baseMethod)) {
|
||||
|
@ -2338,7 +2338,7 @@ export function narrowTypeForDiscriminatedLiteralFieldComparison(
|
||||
if (isClassInstance(subtype) && isClassInstance(memberType) && isProperty(memberType)) {
|
||||
const getterType = memberType.fgetInfo?.methodType;
|
||||
if (getterType && getterType.details.declaredReturnType) {
|
||||
const getterReturnType = FunctionType.getSpecializedReturnType(getterType);
|
||||
const getterReturnType = FunctionType.getEffectiveReturnType(getterType);
|
||||
if (getterReturnType) {
|
||||
memberType = getterReturnType;
|
||||
}
|
||||
|
@ -1227,7 +1227,7 @@ function printFunctionPartsInternal(
|
||||
}
|
||||
|
||||
// If this is a (...) signature, replace the *args, **kwargs with "...".
|
||||
if (FunctionType.shouldSkipArgsKwargsCompatibilityCheck(type) && !isParamSpecArgsKwargsParam) {
|
||||
if (FunctionType.isGradualCallableForm(type) && !isParamSpecArgsKwargsParam) {
|
||||
if (param.category === ParameterCategory.ArgsList) {
|
||||
paramString = '...';
|
||||
} else if (param.category === ParameterCategory.KwargsDict) {
|
||||
|
@ -632,8 +632,8 @@ function compareTypes(a: Type, b: Type, recursionCount = 0): number {
|
||||
}
|
||||
|
||||
const returnTypeComparison = compareTypes(
|
||||
FunctionType.getSpecializedReturnType(a) ?? UnknownType.create(),
|
||||
FunctionType.getSpecializedReturnType(bFunc) ?? UnknownType.create()
|
||||
FunctionType.getEffectiveReturnType(a) ?? UnknownType.create(),
|
||||
FunctionType.getEffectiveReturnType(bFunc) ?? UnknownType.create()
|
||||
);
|
||||
|
||||
if (returnTypeComparison !== 0) {
|
||||
@ -854,11 +854,11 @@ export function derivesFromAnyOrUnknown(type: Type): boolean {
|
||||
if (isAnyOrUnknown(type)) {
|
||||
anyOrUnknown = true;
|
||||
} else if (isInstantiableClass(subtype)) {
|
||||
if (ClassType.hasUnknownBaseClass(subtype)) {
|
||||
if (ClassType.derivesFromAnyOrUnknown(subtype)) {
|
||||
anyOrUnknown = true;
|
||||
}
|
||||
} else if (isClassInstance(subtype)) {
|
||||
if (ClassType.hasUnknownBaseClass(subtype)) {
|
||||
if (ClassType.derivesFromAnyOrUnknown(subtype)) {
|
||||
anyOrUnknown = true;
|
||||
}
|
||||
}
|
||||
@ -1124,7 +1124,7 @@ export function getUnknownTypeForParamSpec(): FunctionType {
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
FunctionTypeFlags.ParamSpecValue | FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck
|
||||
FunctionTypeFlags.ParamSpecValue | FunctionTypeFlags.GradualCallableForm
|
||||
);
|
||||
FunctionType.addDefaultParameters(newFunction);
|
||||
return newFunction;
|
||||
@ -1132,7 +1132,7 @@ export function getUnknownTypeForParamSpec(): FunctionType {
|
||||
|
||||
// Returns the equivalent of "Callable[..., Unknown]".
|
||||
export function getUnknownTypeForCallable(): FunctionType {
|
||||
const newFunction = FunctionType.createSynthesizedInstance('', FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck);
|
||||
const newFunction = FunctionType.createSynthesizedInstance('', FunctionTypeFlags.GradualCallableForm);
|
||||
FunctionType.addDefaultParameters(newFunction);
|
||||
newFunction.details.declaredReturnType = UnknownType.create();
|
||||
return newFunction;
|
||||
@ -2034,7 +2034,7 @@ export function getTypeVarArgumentsRecursive(type: Type, recursionCount = 0): Ty
|
||||
);
|
||||
}
|
||||
|
||||
const returnType = FunctionType.getSpecializedReturnType(type);
|
||||
const returnType = FunctionType.getEffectiveReturnType(type);
|
||||
if (returnType) {
|
||||
addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(returnType, recursionCount));
|
||||
}
|
||||
@ -2269,7 +2269,7 @@ export function synthesizeTypeVarForSelfCls(classType: ClassType, isClsParam: bo
|
||||
// Returns the declared "return" type (the type returned from a return statement)
|
||||
// if it was declared, or undefined otherwise.
|
||||
export function getDeclaredGeneratorReturnType(functionType: FunctionType): Type | undefined {
|
||||
const returnType = FunctionType.getSpecializedReturnType(functionType);
|
||||
const returnType = FunctionType.getEffectiveReturnType(functionType);
|
||||
if (returnType) {
|
||||
const generatorTypeArgs = getGeneratorTypeArgs(returnType);
|
||||
|
||||
@ -2595,7 +2595,7 @@ export function containsAnyOrUnknown(type: Type, recurse: boolean): AnyType | Un
|
||||
override visitFunction(type: FunctionType) {
|
||||
if (this._recurse) {
|
||||
// A function with a "..." type is effectively an "Any".
|
||||
if (FunctionType.shouldSkipArgsKwargsCompatibilityCheck(type)) {
|
||||
if (FunctionType.isGradualCallableForm(type)) {
|
||||
this.anyOrUnknownType = this.anyOrUnknownType
|
||||
? preserveUnknown(this.anyOrUnknownType, AnyType.create())
|
||||
: AnyType.create();
|
||||
@ -3762,7 +3762,7 @@ class TypeVarTransformer {
|
||||
return this.doForEachSignatureContext(() => {
|
||||
let functionType = sourceType;
|
||||
|
||||
const declaredReturnType = FunctionType.getSpecializedReturnType(functionType);
|
||||
const declaredReturnType = FunctionType.getEffectiveReturnType(functionType);
|
||||
const specializedReturnType = declaredReturnType
|
||||
? this.apply(declaredReturnType, recursionCount)
|
||||
: undefined;
|
||||
|
@ -1044,10 +1044,6 @@ export namespace ClassType {
|
||||
return true;
|
||||
}
|
||||
|
||||
export function derivesFromAnyOrUnknown(classType: ClassType) {
|
||||
return classType.details.mro.some((mroClass) => !isClass(mroClass));
|
||||
}
|
||||
|
||||
export function supportsAbstractMethods(classType: ClassType) {
|
||||
return !!(classType.details.flags & ClassTypeFlags.SupportsAbstractMethods);
|
||||
}
|
||||
@ -1178,7 +1174,7 @@ export namespace ClassType {
|
||||
return classType.details.typeParameters;
|
||||
}
|
||||
|
||||
export function hasUnknownBaseClass(classType: ClassType) {
|
||||
export function derivesFromAnyOrUnknown(classType: ClassType) {
|
||||
return classType.details.mro.some((baseClass) => isAnyOrUnknown(baseClass));
|
||||
}
|
||||
|
||||
@ -1441,7 +1437,7 @@ export const enum FunctionTypeFlags {
|
||||
// The *args and **kwargs parameters do not need to be present for this
|
||||
// function to be compatible. This is used for Callable[..., x] and
|
||||
// ... type arguments to ParamSpec and Concatenate.
|
||||
SkipArgsKwargsCompatibilityCheck = 1 << 15,
|
||||
GradualCallableForm = 1 << 15,
|
||||
|
||||
// This function represents the value bound to a ParamSpec, so its return
|
||||
// type is not meaningful.
|
||||
@ -1774,7 +1770,7 @@ export namespace FunctionType {
|
||||
}
|
||||
|
||||
// Use the "..." flag from the param spec.
|
||||
newFunction.details.flags |= paramSpecValue.details.flags & FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck;
|
||||
newFunction.details.flags |= paramSpecValue.details.flags & FunctionTypeFlags.GradualCallableForm;
|
||||
|
||||
// Mark the function as synthesized since there is no user-defined declaration for it.
|
||||
newFunction.details.flags |= FunctionTypeFlags.SynthesizedMethod;
|
||||
@ -2113,8 +2109,8 @@ export namespace FunctionType {
|
||||
return (type.details.flags & FunctionTypeFlags.UnannotatedParams) !== 0;
|
||||
}
|
||||
|
||||
export function shouldSkipArgsKwargsCompatibilityCheck(type: FunctionType) {
|
||||
return (type.details.flags & FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck) !== 0;
|
||||
export function isGradualCallableForm(type: FunctionType) {
|
||||
return (type.details.flags & FunctionTypeFlags.GradualCallableForm) !== 0;
|
||||
}
|
||||
|
||||
export function isParamSpecValue(type: FunctionType) {
|
||||
@ -2174,7 +2170,7 @@ export namespace FunctionType {
|
||||
});
|
||||
}
|
||||
|
||||
export function getSpecializedReturnType(type: FunctionType, includeInferred = true) {
|
||||
export function getEffectiveReturnType(type: FunctionType, includeInferred = true) {
|
||||
if (type.specializedTypes?.returnType) {
|
||||
return type.specializedTypes.returnType;
|
||||
}
|
||||
@ -2546,7 +2542,7 @@ export interface TypeVarDetails {
|
||||
synthesizedIndex?: number | undefined;
|
||||
isExemptFromBoundCheck?: boolean;
|
||||
|
||||
// Does this type variable originate from new type parameter syntax?
|
||||
// Does this type variable originate from PEP 695 type parameter syntax?
|
||||
isTypeParamSyntax?: boolean;
|
||||
|
||||
// Used for recursive type aliases.
|
||||
@ -3029,10 +3025,7 @@ export function isTypeSame(type1: Type, type2: Type, options: TypeSameOptions =
|
||||
}
|
||||
|
||||
// If one function is ... and the other is not, they are not the same.
|
||||
if (
|
||||
FunctionType.shouldSkipArgsKwargsCompatibilityCheck(type1) !==
|
||||
FunctionType.shouldSkipArgsKwargsCompatibilityCheck(functionType2)
|
||||
) {
|
||||
if (FunctionType.isGradualCallableForm(type1) !== FunctionType.isGradualCallableForm(functionType2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -468,7 +468,7 @@ const FunctionTypeFlagsToString: [FunctionTypeFlags, string][] = [
|
||||
[FunctionTypeFlags.ParamSpecValue, 'ParamSpecValue'],
|
||||
[FunctionTypeFlags.PartiallyEvaluated, 'PartiallyEvaluated'],
|
||||
[FunctionTypeFlags.PyTypedDefinition, 'PyTypedDefinition'],
|
||||
[FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck, 'SkipArgsKwargsCompatibilityCheck'],
|
||||
[FunctionTypeFlags.GradualCallableForm, 'SkipArgsKwargsCompatibilityCheck'],
|
||||
[FunctionTypeFlags.StaticMethod, 'StaticMethod'],
|
||||
[FunctionTypeFlags.StubDefinition, 'StubDefinition'],
|
||||
[FunctionTypeFlags.SynthesizedMethod, 'SynthesizedMethod'],
|
||||
|
Loading…
Reference in New Issue
Block a user