mirror of
https://github.com/microsoft/pyright.git
synced 2024-10-06 12:57:14 +03:00
Renamed some internal symbol names for brevity (argument => arg). No functional change.
This commit is contained in:
parent
31df557056
commit
8cab57e657
@ -29,7 +29,7 @@ import { TextRange, getEmptyRange } from '../common/textRange';
|
||||
import { Uri } from '../common/uri/uri';
|
||||
import { LocMessage } from '../localization/localize';
|
||||
import {
|
||||
ArgumentCategory,
|
||||
ArgCategory,
|
||||
AssertNode,
|
||||
AssignmentExpressionNode,
|
||||
AssignmentNode,
|
||||
@ -649,7 +649,7 @@ export class Binder extends ParseTreeWalker {
|
||||
this._disableTrueFalseTargets(() => {
|
||||
this.walk(node.d.leftExpr);
|
||||
|
||||
const sortedArgs = ParseTreeUtils.getArgumentsByRuntimeOrder(node);
|
||||
const sortedArgs = ParseTreeUtils.getArgsByRuntimeOrder(node);
|
||||
|
||||
sortedArgs.forEach((argNode) => {
|
||||
if (this._currentFlowNode) {
|
||||
@ -3002,7 +3002,7 @@ export class Binder extends ParseTreeWalker {
|
||||
expression.nodeType === ParseNodeType.Index &&
|
||||
expression.d.items.length === 1 &&
|
||||
!expression.d.trailingComma &&
|
||||
expression.d.items[0].d.argCategory === ArgumentCategory.Simple
|
||||
expression.d.items[0].d.argCategory === ArgCategory.Simple
|
||||
) {
|
||||
if (isCodeFlowSupportedForReference(expression.d.leftExpr)) {
|
||||
expressionList.push(expression.d.leftExpr);
|
||||
@ -3054,7 +3054,7 @@ export class Binder extends ParseTreeWalker {
|
||||
expression.d.leftExpr.d.leftExpr.nodeType === ParseNodeType.Name &&
|
||||
expression.d.leftExpr.d.leftExpr.d.value === 'type' &&
|
||||
expression.d.leftExpr.d.args.length === 1 &&
|
||||
expression.d.leftExpr.d.args[0].d.argCategory === ArgumentCategory.Simple
|
||||
expression.d.leftExpr.d.args[0].d.argCategory === ArgCategory.Simple
|
||||
) {
|
||||
return this._isNarrowingExpression(
|
||||
expression.d.leftExpr.d.args[0].d.valueExpr,
|
||||
@ -3929,7 +3929,7 @@ export class Binder extends ParseTreeWalker {
|
||||
const finalInfo = this._isAnnotationFinal(typeAnnotation.d.leftExpr);
|
||||
if (
|
||||
finalInfo.isFinal &&
|
||||
typeAnnotation.d.items[0].d.argCategory === ArgumentCategory.Simple &&
|
||||
typeAnnotation.d.items[0].d.argCategory === ArgCategory.Simple &&
|
||||
!typeAnnotation.d.items[0].d.name &&
|
||||
!typeAnnotation.d.trailingComma
|
||||
) {
|
||||
@ -3969,7 +3969,7 @@ export class Binder extends ParseTreeWalker {
|
||||
const finalInfo = this._isAnnotationClassVar(typeAnnotation.d.leftExpr);
|
||||
if (
|
||||
finalInfo.isClassVar &&
|
||||
typeAnnotation.d.items[0].d.argCategory === ArgumentCategory.Simple &&
|
||||
typeAnnotation.d.items[0].d.argCategory === ArgCategory.Simple &&
|
||||
!typeAnnotation.d.items[0].d.name &&
|
||||
!typeAnnotation.d.trailingComma
|
||||
) {
|
||||
|
@ -26,7 +26,7 @@ import { Uri } from '../common/uri/uri';
|
||||
import { DefinitionProvider } from '../languageService/definitionProvider';
|
||||
import { LocAddendum, LocMessage } from '../localization/localize';
|
||||
import {
|
||||
ArgumentCategory,
|
||||
ArgCategory,
|
||||
AssertNode,
|
||||
AssignmentExpressionNode,
|
||||
AssignmentNode,
|
||||
@ -118,7 +118,7 @@ import * as SymbolNameUtils from './symbolNameUtils';
|
||||
import { getLastTypedDeclarationForSymbol } from './symbolUtils';
|
||||
import { maxCodeComplexity } from './typeEvaluator';
|
||||
import {
|
||||
FunctionArgument,
|
||||
Arg,
|
||||
FunctionTypeResult,
|
||||
MemberAccessDeprecationInfo,
|
||||
Reachability,
|
||||
@ -146,7 +146,7 @@ import {
|
||||
getGeneratorTypeArgs,
|
||||
getProtocolSymbolsRecursive,
|
||||
getSpecializedTupleType,
|
||||
getTypeVarArgumentsRecursive,
|
||||
getTypeVarArgsRecursive,
|
||||
getTypeVarScopeId,
|
||||
isLiteralType,
|
||||
isLiteralTypeOrUnion,
|
||||
@ -976,7 +976,7 @@ export class Checker extends ParseTreeWalker {
|
||||
} else {
|
||||
// See if the declared return type includes one or more constrained TypeVars. If so,
|
||||
// try to narrow these TypeVars to a single type.
|
||||
const uniqueTypeVars = getTypeVarArgumentsRecursive(declaredReturnType);
|
||||
const uniqueTypeVars = getTypeVarArgsRecursive(declaredReturnType);
|
||||
|
||||
if (uniqueTypeVars && uniqueTypeVars.some((typeVar) => typeVar.shared.constraints.length > 0)) {
|
||||
const typeVarContext = new TypeVarContext();
|
||||
@ -1157,8 +1157,8 @@ export class Checker extends ParseTreeWalker {
|
||||
// assert (x > 3, "bad value x")
|
||||
const type = this._evaluator.getType(node.d.testExpr);
|
||||
if (type && isClassInstance(type)) {
|
||||
if (isTupleClass(type) && type.priv.tupleTypeArguments) {
|
||||
if (type.priv.tupleTypeArguments.length > 0) {
|
||||
if (isTupleClass(type) && type.priv.tupleTypeArgs) {
|
||||
if (type.priv.tupleTypeArgs.length > 0) {
|
||||
if (!isUnboundedTupleClass(type)) {
|
||||
this._evaluator.addDiagnosticForTextRange(
|
||||
this._fileInfo,
|
||||
@ -1237,20 +1237,16 @@ export class Checker extends ParseTreeWalker {
|
||||
doForEachSubtype(baseType, (subtype) => {
|
||||
const tupleType = getSpecializedTupleType(subtype);
|
||||
|
||||
if (
|
||||
!isClassInstance(subtype) ||
|
||||
!tupleType?.priv.tupleTypeArguments ||
|
||||
isUnboundedTupleClass(tupleType)
|
||||
) {
|
||||
if (!isClassInstance(subtype) || !tupleType?.priv.tupleTypeArgs || isUnboundedTupleClass(tupleType)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const tupleLength = tupleType.priv.tupleTypeArguments.length;
|
||||
const tupleLength = tupleType.priv.tupleTypeArgs.length;
|
||||
|
||||
if (
|
||||
node.d.items.length !== 1 ||
|
||||
node.d.trailingComma ||
|
||||
node.d.items[0].d.argCategory !== ArgumentCategory.Simple ||
|
||||
node.d.items[0].d.argCategory !== ArgCategory.Simple ||
|
||||
node.d.items[0].d.name
|
||||
) {
|
||||
return;
|
||||
@ -2227,13 +2223,13 @@ export class Checker extends ParseTreeWalker {
|
||||
) {
|
||||
const genericLeftType = ClassType.cloneForSpecialization(
|
||||
leftType,
|
||||
/* typeArguments */ undefined,
|
||||
/* isTypeArgumentExplicit */ false
|
||||
/* typeArgs */ undefined,
|
||||
/* isTypeArgExplicit */ false
|
||||
);
|
||||
const genericRightType = ClassType.cloneForSpecialization(
|
||||
rightType,
|
||||
/* typeArguments */ undefined,
|
||||
/* isTypeArgumentExplicit */ false
|
||||
/* typeArgs */ undefined,
|
||||
/* isTypeArgExplicit */ false
|
||||
);
|
||||
|
||||
if (
|
||||
@ -2259,13 +2255,13 @@ export class Checker extends ParseTreeWalker {
|
||||
if (isClassInstance(rightType)) {
|
||||
const genericLeftType = ClassType.cloneForSpecialization(
|
||||
leftType,
|
||||
/* typeArguments */ undefined,
|
||||
/* isTypeArgumentExplicit */ false
|
||||
/* typeArgs */ undefined,
|
||||
/* isTypeArgExplicit */ false
|
||||
);
|
||||
const genericRightType = ClassType.cloneForSpecialization(
|
||||
rightType,
|
||||
/* typeArguments */ undefined,
|
||||
/* isTypeArgumentExplicit */ false
|
||||
/* typeArgs */ undefined,
|
||||
/* isTypeArgsExplicit */ false
|
||||
);
|
||||
|
||||
if (
|
||||
@ -2347,7 +2343,7 @@ export class Checker extends ParseTreeWalker {
|
||||
ClassType.cloneForSpecialization(
|
||||
generatorType,
|
||||
[AnyType.create(), AnyType.create(), AnyType.create()],
|
||||
/* isTypeArgumentExplicit */ true
|
||||
/* isTypeExplicit */ true
|
||||
)
|
||||
);
|
||||
|
||||
@ -2975,8 +2971,8 @@ export class Checker extends ParseTreeWalker {
|
||||
return;
|
||||
}
|
||||
|
||||
if (allowTuple && exceptionSubtype.priv.tupleTypeArguments) {
|
||||
exceptionSubtype.priv.tupleTypeArguments.forEach((typeArg) => {
|
||||
if (allowTuple && exceptionSubtype.priv.tupleTypeArgs) {
|
||||
exceptionSubtype.priv.tupleTypeArgs.forEach((typeArg) => {
|
||||
this._validateExceptionTypeRecursive(
|
||||
typeArg.type,
|
||||
diag,
|
||||
@ -3799,13 +3795,9 @@ export class Checker extends ParseTreeWalker {
|
||||
let isValidType = true;
|
||||
const diag = new DiagnosticAddendum();
|
||||
doForEachSubtype(arg1Type, (arg1Subtype) => {
|
||||
if (isClassInstance(arg1Subtype) && ClassType.isTupleClass(arg1Subtype) && arg1Subtype.priv.tupleTypeArgs) {
|
||||
if (
|
||||
isClassInstance(arg1Subtype) &&
|
||||
ClassType.isTupleClass(arg1Subtype) &&
|
||||
arg1Subtype.priv.tupleTypeArguments
|
||||
) {
|
||||
if (
|
||||
arg1Subtype.priv.tupleTypeArguments.some(
|
||||
arg1Subtype.priv.tupleTypeArgs.some(
|
||||
(typeArg) => !this._isTypeSupportedTypeForIsInstance(typeArg.type, isInstanceCheck, diag)
|
||||
)
|
||||
) {
|
||||
@ -3841,9 +3833,9 @@ export class Checker extends ParseTreeWalker {
|
||||
if (
|
||||
isClassInstance(arg1Subtype) &&
|
||||
ClassType.isTupleClass(arg1Subtype) &&
|
||||
arg1Subtype.priv.tupleTypeArguments
|
||||
arg1Subtype.priv.tupleTypeArgs
|
||||
) {
|
||||
arg1Subtype.priv.tupleTypeArguments.forEach((typeArg) => {
|
||||
arg1Subtype.priv.tupleTypeArgs.forEach((typeArg) => {
|
||||
this._validateNotDataProtocol(typeArg.type, diag);
|
||||
});
|
||||
} else {
|
||||
@ -3913,8 +3905,8 @@ export class Checker extends ParseTreeWalker {
|
||||
// The isinstance and issubclass call supports a variation where the second
|
||||
// parameter is a tuple of classes.
|
||||
if (isTupleClass(arg1Subtype)) {
|
||||
if (arg1Subtype.priv.tupleTypeArguments) {
|
||||
arg1Subtype.priv.tupleTypeArguments.forEach((typeArg) => {
|
||||
if (arg1Subtype.priv.tupleTypeArgs) {
|
||||
arg1Subtype.priv.tupleTypeArgs.forEach((typeArg) => {
|
||||
if (isInstantiableClass(typeArg.type)) {
|
||||
classTypeList.push(typeArg.type);
|
||||
|
||||
@ -4136,7 +4128,7 @@ export class Checker extends ParseTreeWalker {
|
||||
} else if (ClassType.isTypedDictClass(subtype)) {
|
||||
diag.addMessage(LocAddendum.typedDictClassNotAllowed());
|
||||
isSupported = false;
|
||||
} else if (subtype.priv.isTypeArgumentExplicit && !subtype.priv.includeSubclasses) {
|
||||
} else if (subtype.priv.isTypeArgExplicit && !subtype.priv.includeSubclasses) {
|
||||
// If it's a class, make sure that it has not been given explicit
|
||||
// type arguments. This will result in a TypeError exception.
|
||||
diag.addMessage(LocAddendum.genericClassNotAllowed());
|
||||
@ -4743,11 +4735,7 @@ export class Checker extends ParseTreeWalker {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
!isClassInstance(returnType) ||
|
||||
!returnType.priv.typeArguments ||
|
||||
returnType.priv.typeArguments.length < 1
|
||||
) {
|
||||
if (!isClassInstance(returnType) || !returnType.priv.typeArgs || returnType.priv.typeArgs.length < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -4779,7 +4767,7 @@ export class Checker extends ParseTreeWalker {
|
||||
}
|
||||
|
||||
if (isTypeIs) {
|
||||
const typeGuardType = returnType.priv.typeArguments[0];
|
||||
const typeGuardType = returnType.priv.typeArgs[0];
|
||||
|
||||
// Determine the type of the first parameter.
|
||||
const paramIndex = isMethod && !FunctionType.isStaticMethod(functionType) ? 1 : 0;
|
||||
@ -5107,18 +5095,18 @@ export class Checker extends ParseTreeWalker {
|
||||
if (!isAnyOrUnknown(assignedValueType)) {
|
||||
// Construct an argument list. If the assigned type is a tuple, we'll
|
||||
// unpack it. Otherwise, only one argument is passed.
|
||||
const argList: FunctionArgument[] = [
|
||||
const argList: Arg[] = [
|
||||
{
|
||||
argumentCategory:
|
||||
argCategory:
|
||||
isClassInstance(assignedValueType) && isTupleClass(assignedValueType)
|
||||
? ArgumentCategory.UnpackedList
|
||||
: ArgumentCategory.Simple,
|
||||
? ArgCategory.UnpackedList
|
||||
: ArgCategory.Simple,
|
||||
typeResult: { type: assignedValueType },
|
||||
},
|
||||
];
|
||||
|
||||
if (newMemberTypeResult) {
|
||||
this._evaluator.validateCallArguments(
|
||||
this._evaluator.validateCallArgs(
|
||||
errorNode,
|
||||
argList,
|
||||
newMemberTypeResult,
|
||||
@ -5129,7 +5117,7 @@ export class Checker extends ParseTreeWalker {
|
||||
}
|
||||
|
||||
if (initMemberTypeResult) {
|
||||
this._evaluator.validateCallArguments(
|
||||
this._evaluator.validateCallArgs(
|
||||
errorNode,
|
||||
argList,
|
||||
initMemberTypeResult,
|
||||
@ -5530,12 +5518,8 @@ export class Checker extends ParseTreeWalker {
|
||||
return i === paramIndex || p.shared.isVariadic ? p : dummyTypeObject;
|
||||
});
|
||||
|
||||
const srcType = ClassType.cloneForSpecialization(classType, srcTypeArgs, /* isTypeArgumentExplicit */ true);
|
||||
const destType = ClassType.cloneForSpecialization(
|
||||
classType,
|
||||
destTypeArgs,
|
||||
/* isTypeArgumentExplicit */ true
|
||||
);
|
||||
const srcType = ClassType.cloneForSpecialization(classType, srcTypeArgs, /* isTypeArgExplicit */ true);
|
||||
const destType = ClassType.cloneForSpecialization(classType, destTypeArgs, /* isTypeArgExplicit */ true);
|
||||
|
||||
const isDestSubtypeOfSrc = this._evaluator.assignClassToSelf(srcType, destType, Variance.Covariant);
|
||||
|
||||
@ -7332,7 +7316,7 @@ export class Checker extends ParseTreeWalker {
|
||||
// use of class-scoped TypeVars, which are not allowed in this context
|
||||
// according to the typing spec.
|
||||
if (functionType.shared.name === '__init__' && functionType.shared.methodClass) {
|
||||
const typeVars = getTypeVarArgumentsRecursive(paramInfo.type);
|
||||
const typeVars = getTypeVarArgsRecursive(paramInfo.type);
|
||||
|
||||
if (
|
||||
typeVars.some(
|
||||
@ -7471,7 +7455,7 @@ export class Checker extends ParseTreeWalker {
|
||||
|
||||
const generatorTypeArgs = [yieldType, sendType ?? UnknownType.create(), UnknownType.create()];
|
||||
const specializedGenerator = ClassType.cloneAsInstance(
|
||||
ClassType.cloneForSpecialization(generatorType, generatorTypeArgs, /* isTypeArgumentExplicit */ true)
|
||||
ClassType.cloneForSpecialization(generatorType, generatorTypeArgs, /* isTypeArgExplicit */ true)
|
||||
);
|
||||
|
||||
const diagAddendum = new DiagnosticAddendum();
|
||||
|
@ -14,7 +14,7 @@
|
||||
import { ConsoleInterface } from '../common/console';
|
||||
import { assert, fail } from '../common/debug';
|
||||
import { convertOffsetToPosition } from '../common/positionUtils';
|
||||
import { ArgumentCategory, ExpressionNode, ParseNode, ParseNodeType } from '../parser/parseNodes';
|
||||
import { ArgCategory, ExpressionNode, ParseNode, ParseNodeType } from '../parser/parseNodes';
|
||||
import { getFileInfo, getImportInfo } from './analyzerNodeInfo';
|
||||
import {
|
||||
CodeFlowReferenceExpressionNode,
|
||||
@ -65,7 +65,7 @@ import {
|
||||
} from './types';
|
||||
import {
|
||||
cleanIncompleteUnknown,
|
||||
convertArgumentNodeToFunctionArgument,
|
||||
convertNodeToArg,
|
||||
derivesFromStdlibClass,
|
||||
doForEachSubtype,
|
||||
isIncompleteUnknown,
|
||||
@ -559,7 +559,7 @@ export function getCodeFlowEngine(
|
||||
targetNode.d.items.length === 1 &&
|
||||
!targetNode.d.trailingComma &&
|
||||
!targetNode.d.items[0].d.name &&
|
||||
targetNode.d.items[0].d.argCategory === ArgumentCategory.Simple &&
|
||||
targetNode.d.items[0].d.argCategory === ArgCategory.Simple &&
|
||||
targetNode.d.items[0].d.valueExpr.nodeType === ParseNodeType.StringList &&
|
||||
targetNode.d.items[0].d.valueExpr.d.strings.length === 1 &&
|
||||
targetNode.d.items[0].d.valueExpr.d.strings[0].nodeType === ParseNodeType.String
|
||||
@ -1763,7 +1763,7 @@ export function getCodeFlowEngine(
|
||||
// the applicable overload returns a NoReturn.
|
||||
const callResult = evaluator.validateOverloadedArgTypes(
|
||||
node,
|
||||
node.d.args.map((arg) => convertArgumentNodeToFunctionArgument(arg)),
|
||||
node.d.args.map((arg) => convertNodeToArg(arg)),
|
||||
{ type: callSubtype, isIncomplete: callTypeResult.isIncomplete },
|
||||
/* typeVarContext */ undefined,
|
||||
/* skipUnknownArgCheck */ false,
|
||||
@ -1800,10 +1800,10 @@ export function getCodeFlowEngine(
|
||||
if (
|
||||
isClassInstance(returnType) &&
|
||||
ClassType.isBuiltIn(returnType, 'Coroutine') &&
|
||||
returnType.priv.typeArguments &&
|
||||
returnType.priv.typeArguments.length >= 3
|
||||
returnType.priv.typeArgs &&
|
||||
returnType.priv.typeArgs.length >= 3
|
||||
) {
|
||||
if (isNever(returnType.priv.typeArguments[2]) && isCallAwaited) {
|
||||
if (isNever(returnType.priv.typeArgs[2]) && isCallAwaited) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -1909,10 +1909,10 @@ export function getCodeFlowEngine(
|
||||
if (
|
||||
isClassInstance(returnType) &&
|
||||
ClassType.isBuiltIn(returnType, 'Coroutine') &&
|
||||
returnType.priv.typeArguments &&
|
||||
returnType.priv.typeArguments.length >= 3
|
||||
returnType.priv.typeArgs &&
|
||||
returnType.priv.typeArgs.length >= 3
|
||||
) {
|
||||
returnType = returnType.priv.typeArguments[2];
|
||||
returnType = returnType.priv.typeArgs[2];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
import { assert, fail } from '../common/debug';
|
||||
import {
|
||||
ArgumentCategory,
|
||||
ArgCategory,
|
||||
CallNode,
|
||||
CaseNode,
|
||||
ExpressionNode,
|
||||
@ -183,7 +183,7 @@ export function isCodeFlowSupportedForReference(
|
||||
reference.d.items.length !== 1 ||
|
||||
reference.d.trailingComma ||
|
||||
reference.d.items[0].d.name !== undefined ||
|
||||
reference.d.items[0].d.argCategory !== ArgumentCategory.Simple
|
||||
reference.d.items[0].d.argCategory !== ArgCategory.Simple
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ import {
|
||||
isUnpacked,
|
||||
isUnpackedClass,
|
||||
isVariadicTypeVar,
|
||||
TupleTypeArgument,
|
||||
TupleTypeArg,
|
||||
Type,
|
||||
TypeBase,
|
||||
TypeVarScopeId,
|
||||
@ -127,9 +127,9 @@ export function assignTypeToTypeVar(
|
||||
// Handle a type[Any] as a source.
|
||||
if (isClassInstance(srcType) && ClassType.isBuiltIn(srcType, 'type')) {
|
||||
if (
|
||||
!srcType.priv.typeArguments ||
|
||||
srcType.priv.typeArguments.length < 1 ||
|
||||
isAnyOrUnknown(srcType.priv.typeArguments[0])
|
||||
!srcType.priv.typeArgs ||
|
||||
srcType.priv.typeArgs.length < 1 ||
|
||||
isAnyOrUnknown(srcType.priv.typeArgs[0])
|
||||
) {
|
||||
if (TypeBase.isInstantiable(destType)) {
|
||||
return true;
|
||||
@ -202,7 +202,7 @@ export function assignTypeToTypeVar(
|
||||
specializeTupleClass(
|
||||
tupleClassType,
|
||||
[{ type: srcType, isUnbounded: false }],
|
||||
/* isTypeArgumentExplicit */ true,
|
||||
/* isTypeArgExplicit */ true,
|
||||
/* isUnpackedTuple */ true
|
||||
)
|
||||
);
|
||||
@ -257,7 +257,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 ((flags & AssignTypeFlags.AllowUnspecifiedTypeArgs) === 0) {
|
||||
if (isClass(adjSrcType) && adjSrcType.priv.includeSubclasses) {
|
||||
adjSrcType = specializeWithDefaultTypeArgs(adjSrcType);
|
||||
}
|
||||
@ -1021,7 +1021,7 @@ export function addConstraintsForExpectedType(
|
||||
}
|
||||
|
||||
// If the expected type is generic (but not specialized), we can't proceed.
|
||||
const expectedTypeArgs = expectedType.priv.typeArguments;
|
||||
const expectedTypeArgs = expectedType.priv.typeArgs;
|
||||
if (!expectedTypeArgs) {
|
||||
return evaluator.assignType(
|
||||
type,
|
||||
@ -1081,7 +1081,7 @@ export function addConstraintsForExpectedType(
|
||||
const genericExpectedType = ClassType.cloneForSpecialization(
|
||||
expectedType,
|
||||
synthExpectedTypeArgs,
|
||||
/* isTypeArgumentExplicit */ true
|
||||
/* isTypeArgExplicit */ true
|
||||
);
|
||||
|
||||
// For each type param in the target type, create a placeholder type variable.
|
||||
@ -1096,7 +1096,7 @@ export function addConstraintsForExpectedType(
|
||||
return TypeVarType.cloneAsInScopePlaceholder(typeVar);
|
||||
});
|
||||
|
||||
const specializedType = ClassType.cloneForSpecialization(type, typeArgs, /* isTypeArgumentExplicit */ true);
|
||||
const specializedType = ClassType.cloneForSpecialization(type, typeArgs, /* isTypeArgExplicit */ true);
|
||||
const syntheticTypeVarContext = new TypeVarContext(expectedTypeScopeId);
|
||||
if (
|
||||
evaluator.assignType(
|
||||
@ -1211,9 +1211,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.priv.tupleTypeArguments ||
|
||||
!type2.priv.tupleTypeArguments ||
|
||||
type1.priv.tupleTypeArguments.length !== type2.priv.tupleTypeArguments.length
|
||||
!type1.priv.tupleTypeArgs ||
|
||||
!type2.priv.tupleTypeArgs ||
|
||||
type1.priv.tupleTypeArgs.length !== type2.priv.tupleTypeArgs.length
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
@ -1231,12 +1231,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.priv.tupleTypeArguments) {
|
||||
if (!isUnpackedClass(type) || !type.priv.tupleTypeArgs) {
|
||||
return type;
|
||||
}
|
||||
|
||||
let strippedLiteral = false;
|
||||
const tupleTypeArgs: TupleTypeArgument[] = type.priv.tupleTypeArguments.map((arg) => {
|
||||
const tupleTypeArgs: TupleTypeArg[] = type.priv.tupleTypeArgs.map((arg) => {
|
||||
const strippedType = evaluator.stripLiteralValue(arg.type);
|
||||
|
||||
if (strippedType !== arg.type) {
|
||||
@ -1254,7 +1254,7 @@ function stripLiteralValueForUnpackedTuple(evaluator: TypeEvaluator, type: Type)
|
||||
return type;
|
||||
}
|
||||
|
||||
return specializeTupleClass(type, tupleTypeArgs, /* isTypeArgumentExplicit */ true, /* isUnpackedTuple */ true);
|
||||
return specializeTupleClass(type, tupleTypeArgs, /* isTypeArgExplicit */ true, /* isUnpackedTuple */ true);
|
||||
}
|
||||
|
||||
// This function is used for debugging only. It dumps the current contents of
|
||||
|
@ -14,11 +14,11 @@ import { appendArray } from '../common/collectionUtils';
|
||||
import { DiagnosticAddendum } from '../common/diagnostic';
|
||||
import { DiagnosticRule } from '../common/diagnosticRules';
|
||||
import { LocMessage } from '../localization/localize';
|
||||
import { ArgumentCategory, ExpressionNode, ParameterCategory } from '../parser/parseNodes';
|
||||
import { ArgCategory, ExpressionNode, ParameterCategory } from '../parser/parseNodes';
|
||||
import { createFunctionFromConstructor } from './constructors';
|
||||
import { getParameterListDetails, ParameterKind } from './parameterUtils';
|
||||
import { Symbol, SymbolFlags } from './symbol';
|
||||
import { FunctionArgument, FunctionResult, TypeEvaluator } from './typeEvaluatorTypes';
|
||||
import { Arg, FunctionResult, TypeEvaluator } from './typeEvaluatorTypes';
|
||||
import {
|
||||
AnyType,
|
||||
ClassType,
|
||||
@ -55,7 +55,7 @@ export function hasConstructorTransform(classType: ClassType): boolean {
|
||||
export function applyConstructorTransform(
|
||||
evaluator: TypeEvaluator,
|
||||
errorNode: ExpressionNode,
|
||||
argList: FunctionArgument[],
|
||||
argList: Arg[],
|
||||
classType: ClassType,
|
||||
result: FunctionResult
|
||||
): FunctionResult {
|
||||
@ -71,7 +71,7 @@ export function applyConstructorTransform(
|
||||
function applyPartialTransform(
|
||||
evaluator: TypeEvaluator,
|
||||
errorNode: ExpressionNode,
|
||||
argList: FunctionArgument[],
|
||||
argList: Arg[],
|
||||
result: FunctionResult
|
||||
): FunctionResult {
|
||||
// We assume that the normal return result is a functools.partial class instance.
|
||||
@ -93,7 +93,7 @@ function applyPartialTransform(
|
||||
return result;
|
||||
}
|
||||
|
||||
const origFunctionTypeResult = evaluator.getTypeOfArgument(argList[0], /* inferenceContext */ undefined);
|
||||
const origFunctionTypeResult = evaluator.getTypeOfArg(argList[0], /* inferenceContext */ undefined);
|
||||
let origFunctionType = origFunctionTypeResult.type;
|
||||
const origFunctionTypeConcrete = evaluator.makeTopLevelTypeVarsConcrete(origFunctionType);
|
||||
|
||||
@ -113,7 +113,7 @@ function applyPartialTransform(
|
||||
evaluator.inferReturnTypeIfNecessary(origFunctionType);
|
||||
|
||||
// We don't currently handle unpacked arguments.
|
||||
if (argList.some((arg) => arg.argumentCategory !== ArgumentCategory.Simple)) {
|
||||
if (argList.some((arg) => arg.argCategory !== ArgCategory.Simple)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -215,7 +215,7 @@ function applyPartialTransform(
|
||||
function applyPartialTransformToFunction(
|
||||
evaluator: TypeEvaluator,
|
||||
errorNode: ExpressionNode | undefined,
|
||||
argList: FunctionArgument[],
|
||||
argList: Arg[],
|
||||
partialCallMemberType: FunctionType,
|
||||
origFunctionType: FunctionType
|
||||
): FunctionResult | undefined {
|
||||
|
@ -17,7 +17,7 @@ import { DiagnosticAddendum } from '../common/diagnostic';
|
||||
import { DiagnosticRule } from '../common/diagnosticRules';
|
||||
import { ExpressionNode, ParameterCategory } from '../parser/parseNodes';
|
||||
import { applyConstructorTransform, hasConstructorTransform } from './constructorTransform';
|
||||
import { CallResult, FunctionArgument, TypeEvaluator, TypeResult } from './typeEvaluatorTypes';
|
||||
import { Arg, CallResult, TypeEvaluator, TypeResult } from './typeEvaluatorTypes';
|
||||
import {
|
||||
InferenceContext,
|
||||
MemberAccessFlags,
|
||||
@ -28,7 +28,7 @@ import {
|
||||
convertTypeToParamSpecValue,
|
||||
doForEachSignature,
|
||||
doForEachSubtype,
|
||||
getTypeVarArgumentsRecursive,
|
||||
getTypeVarArgsRecursive,
|
||||
getTypeVarScopeId,
|
||||
getTypeVarScopeIds,
|
||||
isTupleClass,
|
||||
@ -110,10 +110,10 @@ export function getBoundCallMethod(evaluator: TypeEvaluator, errorNode: Expressi
|
||||
// Matches the arguments of a call to the constructor for a class.
|
||||
// If successful, it returns the resulting (specialized) object type that
|
||||
// is allocated by the constructor. If unsuccessful, it reports diagnostics.
|
||||
export function validateConstructorArguments(
|
||||
export function validateConstructorArgs(
|
||||
evaluator: TypeEvaluator,
|
||||
errorNode: ExpressionNode,
|
||||
argList: FunctionArgument[],
|
||||
argList: Arg[],
|
||||
type: ClassType,
|
||||
skipUnknownArgCheck: boolean | undefined,
|
||||
inferenceContext: InferenceContext | undefined
|
||||
@ -121,7 +121,7 @@ export function validateConstructorArguments(
|
||||
// If this is an unspecialized generic type alias, specialize it now
|
||||
// using default type argument values.
|
||||
const aliasInfo = type.props?.typeAliasInfo;
|
||||
if (aliasInfo?.typeParameters && !aliasInfo.typeArguments) {
|
||||
if (aliasInfo?.typeParameters && !aliasInfo.typeArgs) {
|
||||
const typeAliasTypeVarContext = new TypeVarContext(aliasInfo.typeVarScopeId);
|
||||
type = applySolvedTypeVars(type, typeAliasTypeVarContext, { unknownIfNotFound: true }) as ClassType;
|
||||
}
|
||||
@ -226,7 +226,7 @@ export function validateConstructorArguments(
|
||||
function validateNewAndInitMethods(
|
||||
evaluator: TypeEvaluator,
|
||||
errorNode: ExpressionNode,
|
||||
argList: FunctionArgument[],
|
||||
argList: Arg[],
|
||||
type: ClassType,
|
||||
skipUnknownArgCheck: boolean | undefined,
|
||||
inferenceContext: InferenceContext | undefined,
|
||||
@ -304,8 +304,8 @@ function validateNewAndInitMethods(
|
||||
// type and rely on the __init__ method to supply the type arguments instead.
|
||||
let initMethodBindToType = newMethodReturnType;
|
||||
if (
|
||||
initMethodBindToType.priv.typeArguments &&
|
||||
initMethodBindToType.priv.typeArguments.some((typeArg) => isUnknown(typeArg))
|
||||
initMethodBindToType.priv.typeArgs &&
|
||||
initMethodBindToType.priv.typeArgs.some((typeArg) => isUnknown(typeArg))
|
||||
) {
|
||||
initMethodBindToType = ClassType.cloneAsInstance(type);
|
||||
}
|
||||
@ -392,7 +392,7 @@ function validateNewAndInitMethods(
|
||||
function validateNewMethod(
|
||||
evaluator: TypeEvaluator,
|
||||
errorNode: ExpressionNode,
|
||||
argList: FunctionArgument[],
|
||||
argList: Arg[],
|
||||
type: ClassType,
|
||||
skipUnknownArgCheck: boolean | undefined,
|
||||
inferenceContext: InferenceContext | undefined,
|
||||
@ -408,7 +408,7 @@ function validateNewMethod(
|
||||
typeVarContext.addSolveForScope(getTypeVarScopeId(newMethodTypeResult.type));
|
||||
|
||||
const callResult = evaluator.useSpeculativeMode(useSpeculativeModeForArgs ? errorNode : undefined, () => {
|
||||
return evaluator.validateCallArguments(
|
||||
return evaluator.validateCallArgs(
|
||||
errorNode,
|
||||
argList,
|
||||
newMethodTypeResult,
|
||||
@ -427,7 +427,7 @@ function validateNewMethod(
|
||||
|
||||
// Evaluate the arguments in a non-speculative manner to generate any diagnostics.
|
||||
typeVarContext.unlock();
|
||||
evaluator.validateCallArguments(
|
||||
evaluator.validateCallArgs(
|
||||
errorNode,
|
||||
argList,
|
||||
newMethodTypeResult,
|
||||
@ -446,10 +446,10 @@ function validateNewMethod(
|
||||
if (newReturnType) {
|
||||
// Special-case the 'tuple' type specialization to use the homogenous
|
||||
// arbitrary-length form.
|
||||
if (isClassInstance(newReturnType) && isTupleClass(newReturnType) && !newReturnType.priv.tupleTypeArguments) {
|
||||
if (newReturnType.priv.typeArguments && newReturnType.priv.typeArguments.length === 1) {
|
||||
if (isClassInstance(newReturnType) && isTupleClass(newReturnType) && !newReturnType.priv.tupleTypeArgs) {
|
||||
if (newReturnType.priv.typeArgs && newReturnType.priv.typeArgs.length === 1) {
|
||||
newReturnType = specializeTupleClass(newReturnType, [
|
||||
{ type: newReturnType.priv.typeArguments[0], isUnbounded: true },
|
||||
{ type: newReturnType.priv.typeArgs[0], isUnbounded: true },
|
||||
]);
|
||||
}
|
||||
|
||||
@ -465,7 +465,7 @@ function validateNewMethod(
|
||||
function validateInitMethod(
|
||||
evaluator: TypeEvaluator,
|
||||
errorNode: ExpressionNode,
|
||||
argList: FunctionArgument[],
|
||||
argList: Arg[],
|
||||
type: ClassType,
|
||||
skipUnknownArgCheck: boolean | undefined,
|
||||
inferenceContext: InferenceContext | undefined,
|
||||
@ -475,13 +475,13 @@ function validateInitMethod(
|
||||
let argumentErrors = false;
|
||||
const overloadsUsedForCall: FunctionType[] = [];
|
||||
|
||||
const typeVarContext = type.priv.typeArguments
|
||||
const typeVarContext = type.priv.typeArgs
|
||||
? buildTypeVarContextFromSpecializedClass(type)
|
||||
: new TypeVarContext(getTypeVarScopeId(type));
|
||||
typeVarContext.addSolveForScope(getTypeVarScopeId(initMethodType));
|
||||
|
||||
const returnTypeOverride = selfSpecializeClass(type);
|
||||
const callResult = evaluator.validateCallArguments(
|
||||
const callResult = evaluator.validateCallArgs(
|
||||
errorNode,
|
||||
argList,
|
||||
{ type: initMethodType },
|
||||
@ -522,7 +522,7 @@ function validateInitMethod(
|
||||
function validateFallbackConstructorCall(
|
||||
evaluator: TypeEvaluator,
|
||||
errorNode: ExpressionNode,
|
||||
argList: FunctionArgument[],
|
||||
argList: Arg[],
|
||||
type: ClassType,
|
||||
inferenceContext: InferenceContext | undefined
|
||||
): CallResult {
|
||||
@ -557,7 +557,7 @@ function validateFallbackConstructorCall(
|
||||
function validateMetaclassCall(
|
||||
evaluator: TypeEvaluator,
|
||||
errorNode: ExpressionNode,
|
||||
argList: FunctionArgument[],
|
||||
argList: Arg[],
|
||||
type: ClassType,
|
||||
skipUnknownArgCheck: boolean | undefined,
|
||||
inferenceContext: InferenceContext | undefined
|
||||
@ -568,7 +568,7 @@ function validateMetaclassCall(
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const callResult = evaluator.validateCallArguments(
|
||||
const callResult = evaluator.validateCallArgs(
|
||||
errorNode,
|
||||
argList,
|
||||
metaclassCallMethodInfo,
|
||||
@ -625,7 +625,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.shared.typeParameters.length === 0 || type.priv.typeArguments) {
|
||||
if (type.shared.typeParameters.length === 0 || type.priv.typeArgs) {
|
||||
return applySolvedTypeVars(ClassType.cloneAsInstance(type), typeVarContext, { applyInScopePlaceholders: true });
|
||||
}
|
||||
|
||||
@ -641,7 +641,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.priv.typeArguments) {
|
||||
if (type.priv.typeArgs) {
|
||||
unsolvedTypeVarsAreUnknown = false;
|
||||
}
|
||||
}
|
||||
@ -662,9 +662,9 @@ function applyExpectedTypeForTupleConstructor(type: ClassType, inferenceContext:
|
||||
inferenceContext &&
|
||||
isClassInstance(inferenceContext.expectedType) &&
|
||||
isTupleClass(inferenceContext.expectedType) &&
|
||||
inferenceContext.expectedType.priv.tupleTypeArguments
|
||||
inferenceContext.expectedType.priv.tupleTypeArgs
|
||||
) {
|
||||
specializedType = specializeTupleClass(type, inferenceContext.expectedType.priv.tupleTypeArguments);
|
||||
specializedType = specializeTupleClass(type, inferenceContext.expectedType.priv.tupleTypeArgs);
|
||||
}
|
||||
|
||||
return specializedType;
|
||||
@ -803,7 +803,7 @@ function createFunctionFromNewMethod(
|
||||
}
|
||||
|
||||
const paramType = FunctionType.getEffectiveParameterType(newSubtype, index);
|
||||
const typeVars = getTypeVarArgumentsRecursive(paramType);
|
||||
const typeVars = getTypeVarArgsRecursive(paramType);
|
||||
return typeVars.some((typeVar) => typeVar.priv.scopeId === getTypeVarScopeId(classType));
|
||||
});
|
||||
|
||||
@ -923,7 +923,7 @@ 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.shared.typeParameters.length > 0 && !objectType.priv.typeArguments) {
|
||||
if (objectType.shared.typeParameters.length > 0 && !objectType.priv.typeArgs) {
|
||||
const typeVarContext = new TypeVarContext(getTypeVarScopeIds(objectType));
|
||||
|
||||
// If a TypeVar is not used in any of the parameter types, it should take
|
||||
@ -932,7 +932,7 @@ function createFunctionFromInitMethod(
|
||||
|
||||
convertedInit.shared.parameters.forEach((param, index) => {
|
||||
const paramType = FunctionType.getEffectiveParameterType(convertedInit, index);
|
||||
addTypeVarsToListIfUnique(typeVarsInParams, getTypeVarArgumentsRecursive(paramType));
|
||||
addTypeVarsToListIfUnique(typeVarsInParams, getTypeVarArgsRecursive(paramType));
|
||||
});
|
||||
|
||||
typeVarsInParams.forEach((typeVar) => {
|
||||
|
@ -14,7 +14,7 @@ import { DiagnosticRule } from '../common/diagnosticRules';
|
||||
import { pythonVersion3_13 } from '../common/pythonVersion';
|
||||
import { LocMessage } from '../localization/localize';
|
||||
import {
|
||||
ArgumentCategory,
|
||||
ArgCategory,
|
||||
ArgumentNode,
|
||||
CallNode,
|
||||
ClassNode,
|
||||
@ -34,7 +34,7 @@ import { getClassFullName, getEnclosingClassOrFunction, getScopeIdForNode, getTy
|
||||
import { evaluateStaticBoolExpression } from './staticExpressions';
|
||||
import { Symbol, SymbolFlags } from './symbol';
|
||||
import { isPrivateName } from './symbolNameUtils';
|
||||
import { EvalFlags, FunctionArgument, TypeEvaluator, TypeResult } from './typeEvaluatorTypes';
|
||||
import { Arg, EvalFlags, TypeEvaluator, TypeResult } from './typeEvaluatorTypes';
|
||||
import {
|
||||
AnyType,
|
||||
ClassType,
|
||||
@ -53,7 +53,7 @@ import {
|
||||
isOverloadedFunction,
|
||||
isUnion,
|
||||
OverloadedFunctionType,
|
||||
TupleTypeArgument,
|
||||
TupleTypeArg,
|
||||
Type,
|
||||
TypeVarType,
|
||||
UnknownType,
|
||||
@ -62,7 +62,7 @@ import {
|
||||
applySolvedTypeVars,
|
||||
buildTypeVarContextFromSpecializedClass,
|
||||
computeMroLinearization,
|
||||
convertArgumentNodeToFunctionArgument,
|
||||
convertNodeToArg,
|
||||
convertToInstance,
|
||||
doForEachSignature,
|
||||
getTypeVarScopeId,
|
||||
@ -592,7 +592,7 @@ export function synthesizeDataClassMethods(
|
||||
matchArgsNames.push(entry.name);
|
||||
}
|
||||
});
|
||||
const literalTypes: TupleTypeArgument[] = matchArgsNames.map((name) => {
|
||||
const literalTypes: TupleTypeArg[] = matchArgsNames.map((name) => {
|
||||
return { type: ClassType.cloneAsInstance(ClassType.cloneWithLiteral(strType, name)), isUnbounded: false };
|
||||
});
|
||||
const matchArgsType = ClassType.cloneAsInstance(specializeTupleClass(tupleClassType, literalTypes));
|
||||
@ -663,7 +663,7 @@ export function synthesizeDataClassMethods(
|
||||
ClassType.cloneForSpecialization(
|
||||
dictType,
|
||||
[evaluator.getBuiltInObject(node, 'str'), AnyType.create()],
|
||||
/* isTypeArgumentExplicit */ true
|
||||
/* isTypeArgExplicit */ true
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -688,7 +688,7 @@ export function synthesizeDataClassMethods(
|
||||
ClassType.cloneForSpecialization(
|
||||
iterableType,
|
||||
[evaluator.getBuiltInObject(node, 'str')],
|
||||
/* isTypeArgumentExplicit */ true
|
||||
/* isTypeArgExplicit */ true
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -705,7 +705,7 @@ export function synthesizeDataClassMethods(
|
||||
updateNamedTupleBaseClass(
|
||||
classType,
|
||||
fullDataClassEntries.map((entry) => entry.type),
|
||||
/* isTypeArgumentExplicit */ true
|
||||
/* isTypeArgExplicit */ true
|
||||
)
|
||||
) {
|
||||
// Recompute the MRO based on the updated NamedTuple base class.
|
||||
@ -729,10 +729,10 @@ function getDefaultArgValueForFieldSpecifier(
|
||||
if (isFunction(callType)) {
|
||||
callTarget = callType;
|
||||
} else if (isOverloadedFunction(callType)) {
|
||||
callTarget = evaluator.getBestOverloadForArguments(
|
||||
callTarget = evaluator.getBestOverloadForArgs(
|
||||
callNode,
|
||||
{ type: callType, isIncomplete: callTypeResult.isIncomplete },
|
||||
callNode.d.args.map((arg) => convertArgumentNodeToFunctionArgument(arg))
|
||||
callNode.d.args.map((arg) => convertNodeToArg(arg))
|
||||
);
|
||||
} else if (isInstantiableClass(callType)) {
|
||||
const initMethodResult = getBoundInitMethod(evaluator, callNode, callType);
|
||||
@ -740,10 +740,10 @@ function getDefaultArgValueForFieldSpecifier(
|
||||
if (isFunction(initMethodResult.type)) {
|
||||
callTarget = initMethodResult.type;
|
||||
} else if (isOverloadedFunction(initMethodResult.type)) {
|
||||
callTarget = evaluator.getBestOverloadForArguments(
|
||||
callTarget = evaluator.getBestOverloadForArgs(
|
||||
callNode,
|
||||
{ type: initMethodResult.type },
|
||||
callNode.d.args.map((arg) => convertArgumentNodeToFunctionArgument(arg))
|
||||
callNode.d.args.map((arg) => convertNodeToArg(arg))
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1072,7 +1072,7 @@ export function validateDataClassTransformDecorator(
|
||||
|
||||
// Parse the arguments to the call.
|
||||
node.d.args.forEach((arg) => {
|
||||
if (!arg.d.name || arg.d.argCategory !== ArgumentCategory.Simple) {
|
||||
if (!arg.d.name || arg.d.argCategory !== ArgCategory.Simple) {
|
||||
evaluator.addDiagnostic(
|
||||
DiagnosticRule.reportCallIssue,
|
||||
LocMessage.dataClassTransformPositionalParam(),
|
||||
@ -1173,8 +1173,8 @@ export function validateDataClassTransformDecorator(
|
||||
if (
|
||||
!isClassInstance(valueType) ||
|
||||
!ClassType.isBuiltIn(valueType, 'tuple') ||
|
||||
!valueType.priv.tupleTypeArguments ||
|
||||
valueType.priv.tupleTypeArguments.some(
|
||||
!valueType.priv.tupleTypeArgs ||
|
||||
valueType.priv.tupleTypeArgs.some(
|
||||
(entry) =>
|
||||
!isInstantiableClass(entry.type) &&
|
||||
!isFunction(entry.type) &&
|
||||
@ -1191,7 +1191,7 @@ export function validateDataClassTransformDecorator(
|
||||
return;
|
||||
}
|
||||
|
||||
valueType.priv.tupleTypeArguments.forEach((arg) => {
|
||||
valueType.priv.tupleTypeArgs.forEach((arg) => {
|
||||
if (isInstantiableClass(arg.type) || isFunction(arg.type)) {
|
||||
behaviors.fieldDescriptorNames.push(arg.type.shared.fullName);
|
||||
} else if (isOverloadedFunction(arg.type)) {
|
||||
@ -1371,7 +1371,7 @@ export function applyDataClassClassBehaviorOverrides(
|
||||
evaluator: TypeEvaluator,
|
||||
errorNode: ParseNode,
|
||||
classType: ClassType,
|
||||
args: FunctionArgument[],
|
||||
args: Arg[],
|
||||
defaultBehaviors: DataClassBehaviors
|
||||
) {
|
||||
let sawFrozenArg = false;
|
||||
@ -1427,7 +1427,7 @@ export function applyDataClassDecorator(
|
||||
evaluator,
|
||||
errorNode,
|
||||
classType,
|
||||
(callNode?.d.args ?? []).map((arg) => convertArgumentNodeToFunctionArgument(arg)),
|
||||
(callNode?.d.args ?? []).map((arg) => convertNodeToArg(arg)),
|
||||
defaultBehaviors
|
||||
);
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import { appendArray } from '../common/collectionUtils';
|
||||
import { DiagnosticRule } from '../common/diagnosticRules';
|
||||
import { LocMessage } from '../localization/localize';
|
||||
import {
|
||||
ArgumentCategory,
|
||||
ArgCategory,
|
||||
CallNode,
|
||||
DecoratorNode,
|
||||
FunctionNode,
|
||||
@ -33,7 +33,7 @@ import {
|
||||
createProperty,
|
||||
validatePropertyMethod,
|
||||
} from './properties';
|
||||
import { EvalFlags, FunctionArgument, TypeEvaluator } from './typeEvaluatorTypes';
|
||||
import { Arg, EvalFlags, TypeEvaluator } from './typeEvaluatorTypes';
|
||||
import { isPartlyUnknown, isProperty } from './typeUtils';
|
||||
import {
|
||||
ClassType,
|
||||
@ -410,14 +410,14 @@ function getTypeOfDecorator(evaluator: TypeEvaluator, node: DecoratorNode, funct
|
||||
return functionOrClassType;
|
||||
}
|
||||
|
||||
const argList: FunctionArgument[] = [
|
||||
const argList: Arg[] = [
|
||||
{
|
||||
argumentCategory: ArgumentCategory.Simple,
|
||||
argCategory: ArgCategory.Simple,
|
||||
typeResult: { type: functionOrClassType },
|
||||
},
|
||||
];
|
||||
|
||||
const callTypeResult = evaluator.validateCallArguments(
|
||||
const callTypeResult = evaluator.validateCallArgs(
|
||||
node.d.expr,
|
||||
argList,
|
||||
decoratorTypeResult,
|
||||
@ -582,7 +582,7 @@ export function addOverloadsToFunctionType(evaluator: TypeEvaluator, node: Funct
|
||||
export function getDeprecatedMessageFromCall(node: CallNode): string {
|
||||
if (
|
||||
node.d.args.length > 0 &&
|
||||
node.d.args[0].d.argCategory === ArgumentCategory.Simple &&
|
||||
node.d.args[0].d.argCategory === ArgCategory.Simple &&
|
||||
node.d.args[0].d.valueExpr.nodeType === ParseNodeType.StringList
|
||||
) {
|
||||
const stringListNode = node.d.args[0].d.valueExpr;
|
||||
|
@ -588,12 +588,12 @@ class DocStringConverter {
|
||||
}
|
||||
|
||||
// catch-all for styles except reST
|
||||
const hasArguments = !line?.endsWith(':') && !line?.endsWith('::') && !!line.match(/.*?\s*:\s*(.+)/gu);
|
||||
const hasArgs = !line?.endsWith(':') && !line?.endsWith('::') && !!line.match(/.*?\s*:\s*(.+)/gu);
|
||||
|
||||
// reSt params. Attempt to put directives lines into their own paragraphs.
|
||||
const restDirective = DirectivesExtraNewlineRegExp.test(line); //line.match(/^\s*:param/);
|
||||
|
||||
if (hasArguments || restDirective) {
|
||||
if (hasArgs || restDirective) {
|
||||
const prev = this._lineAt(this._lineNum - 1);
|
||||
// Force a line break, if previous line doesn't already have a break or is blank
|
||||
if (!this._builder.endsWith(MarkdownLineBreak) && !this._builder.endsWith(`\n\n`) && !_isHeader(prev)) {
|
||||
|
@ -9,13 +9,13 @@
|
||||
|
||||
import { assert } from '../common/debug';
|
||||
import { pythonVersion3_13 } from '../common/pythonVersion';
|
||||
import { ArgumentCategory, ExpressionNode, NameNode, ParseNode, ParseNodeType } from '../parser/parseNodes';
|
||||
import { ArgCategory, ExpressionNode, NameNode, ParseNode, ParseNodeType } from '../parser/parseNodes';
|
||||
import { getFileInfo } from './analyzerNodeInfo';
|
||||
import { VariableDeclaration } from './declaration';
|
||||
import { getClassFullName, getEnclosingClass, getTypeSourceId } from './parseTreeUtils';
|
||||
import { Symbol, SymbolFlags } from './symbol';
|
||||
import { isPrivateName, isSingleDunderName } from './symbolNameUtils';
|
||||
import { EvalFlags, FunctionArgument, TypeEvaluator, TypeResult } from './typeEvaluatorTypes';
|
||||
import { Arg, EvalFlags, TypeEvaluator, TypeResult } from './typeEvaluatorTypes';
|
||||
import { enumerateLiteralsForType } from './typeGuards';
|
||||
import { MemberAccessFlags, computeMroLinearization, lookUpClassMember, makeInferenceContext } from './typeUtils';
|
||||
import {
|
||||
@ -69,7 +69,7 @@ export function createEnumType(
|
||||
evaluator: TypeEvaluator,
|
||||
errorNode: ExpressionNode,
|
||||
enumClass: ClassType,
|
||||
argList: FunctionArgument[]
|
||||
argList: Arg[]
|
||||
): ClassType | undefined {
|
||||
const fileInfo = getFileInfo(errorNode);
|
||||
|
||||
@ -79,7 +79,7 @@ export function createEnumType(
|
||||
|
||||
const nameArg = argList[0];
|
||||
if (
|
||||
nameArg.argumentCategory !== ArgumentCategory.Simple ||
|
||||
nameArg.argCategory !== ArgCategory.Simple ||
|
||||
!nameArg.valueExpression ||
|
||||
nameArg.valueExpression.nodeType !== ParseNodeType.StringList ||
|
||||
nameArg.valueExpression.d.strings.length !== 1 ||
|
||||
@ -113,7 +113,7 @@ export function createEnumType(
|
||||
}
|
||||
|
||||
const initArg = argList[1];
|
||||
if (initArg.argumentCategory !== ArgumentCategory.Simple || !initArg.valueExpression) {
|
||||
if (initArg.argCategory !== ArgCategory.Simple || !initArg.valueExpression) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@ -445,8 +445,8 @@ export function transformTypeForEnumMember(
|
||||
if (assignedType && isClassInstance(assignedType) && ClassType.isBuiltIn(assignedType)) {
|
||||
if (assignedType.shared.fullName === 'enum.nonmember') {
|
||||
const nonMemberType =
|
||||
assignedType.priv.typeArguments && assignedType.priv.typeArguments.length > 0
|
||||
? assignedType.priv.typeArguments[0]
|
||||
assignedType.priv.typeArgs && assignedType.priv.typeArgs.length > 0
|
||||
? assignedType.priv.typeArgs[0]
|
||||
: UnknownType.create();
|
||||
|
||||
// If the type of the nonmember is declared and the assigned value has
|
||||
@ -460,8 +460,8 @@ export function transformTypeForEnumMember(
|
||||
|
||||
if (assignedType.shared.fullName === 'enum.member') {
|
||||
valueType =
|
||||
assignedType.priv.typeArguments && assignedType.priv.typeArguments.length > 0
|
||||
? assignedType.priv.typeArguments[0]
|
||||
assignedType.priv.typeArgs && assignedType.priv.typeArgs.length > 0
|
||||
? assignedType.priv.typeArgs[0]
|
||||
: UnknownType.create();
|
||||
isMemberOfEnumeration = true;
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import { DiagnosticRule } from '../common/diagnosticRules';
|
||||
import { LocMessage } from '../localization/localize';
|
||||
import { ExpressionNode, ParameterCategory } from '../parser/parseNodes';
|
||||
import { Symbol, SymbolFlags } from './symbol';
|
||||
import { FunctionArgument, FunctionResult, TypeEvaluator } from './typeEvaluatorTypes';
|
||||
import { Arg, FunctionResult, TypeEvaluator } from './typeEvaluatorTypes';
|
||||
import {
|
||||
ClassType,
|
||||
FunctionParam,
|
||||
@ -29,7 +29,7 @@ import { ClassMember, lookUpObjectMember, MemberAccessFlags, synthesizeTypeVarFo
|
||||
export function applyFunctionTransform(
|
||||
evaluator: TypeEvaluator,
|
||||
errorNode: ExpressionNode,
|
||||
argList: FunctionArgument[],
|
||||
argList: Arg[],
|
||||
functionType: FunctionType | OverloadedFunctionType,
|
||||
result: FunctionResult
|
||||
): FunctionResult {
|
||||
@ -46,7 +46,7 @@ export function applyFunctionTransform(
|
||||
function applyTotalOrderingTransform(
|
||||
evaluator: TypeEvaluator,
|
||||
errorNode: ExpressionNode,
|
||||
argList: FunctionArgument[],
|
||||
argList: Arg[],
|
||||
result: FunctionResult
|
||||
) {
|
||||
if (argList.length !== 1) {
|
||||
|
@ -12,20 +12,14 @@ import { DiagnosticRule } from '../common/diagnosticRules';
|
||||
import { convertOffsetsToRange } from '../common/positionUtils';
|
||||
import { TextRange } from '../common/textRange';
|
||||
import { LocMessage } from '../localization/localize';
|
||||
import {
|
||||
ArgumentCategory,
|
||||
ExpressionNode,
|
||||
ParameterCategory,
|
||||
ParseNodeType,
|
||||
StringListNode,
|
||||
} from '../parser/parseNodes';
|
||||
import { ArgCategory, ExpressionNode, ParameterCategory, ParseNodeType, StringListNode } from '../parser/parseNodes';
|
||||
import { Tokenizer } from '../parser/tokenizer';
|
||||
import { getFileInfo } from './analyzerNodeInfo';
|
||||
import { DeclarationType, VariableDeclaration } from './declaration';
|
||||
import * as ParseTreeUtils from './parseTreeUtils';
|
||||
import { evaluateStaticBoolExpression } from './staticExpressions';
|
||||
import { Symbol, SymbolFlags } from './symbol';
|
||||
import { FunctionArgument, TypeEvaluator } from './typeEvaluatorTypes';
|
||||
import { Arg, TypeEvaluator } from './typeEvaluatorTypes';
|
||||
import {
|
||||
computeMroLinearization,
|
||||
convertToInstance,
|
||||
@ -44,7 +38,7 @@ import {
|
||||
FunctionParamFlags,
|
||||
FunctionType,
|
||||
FunctionTypeFlags,
|
||||
TupleTypeArgument,
|
||||
TupleTypeArg,
|
||||
Type,
|
||||
UnknownType,
|
||||
combineTypes,
|
||||
@ -58,7 +52,7 @@ import {
|
||||
export function createNamedTupleType(
|
||||
evaluator: TypeEvaluator,
|
||||
errorNode: ExpressionNode,
|
||||
argList: FunctionArgument[],
|
||||
argList: Arg[],
|
||||
includesTypes: boolean
|
||||
): ClassType {
|
||||
const fileInfo = getFileInfo(errorNode);
|
||||
@ -68,7 +62,7 @@ export function createNamedTupleType(
|
||||
let allowRename = false;
|
||||
if (!includesTypes) {
|
||||
const renameArg = argList.find(
|
||||
(arg) => arg.argumentCategory === ArgumentCategory.Simple && arg.name?.d.value === 'rename'
|
||||
(arg) => arg.argCategory === ArgCategory.Simple && arg.name?.d.value === 'rename'
|
||||
);
|
||||
|
||||
if (renameArg?.valueExpression) {
|
||||
@ -87,7 +81,7 @@ export function createNamedTupleType(
|
||||
evaluator.addDiagnostic(DiagnosticRule.reportCallIssue, LocMessage.namedTupleFirstArg(), errorNode);
|
||||
} else {
|
||||
const nameArg = argList[0];
|
||||
if (nameArg.argumentCategory !== ArgumentCategory.Simple) {
|
||||
if (nameArg.argCategory !== ArgCategory.Simple) {
|
||||
evaluator.addDiagnostic(
|
||||
DiagnosticRule.reportArgumentType,
|
||||
LocMessage.namedTupleFirstArg(),
|
||||
@ -108,9 +102,9 @@ export function createNamedTupleType(
|
||||
isClassInstance(defaultsArgType) &&
|
||||
isTupleClass(defaultsArgType) &&
|
||||
!isUnboundedTupleClass(defaultsArgType) &&
|
||||
defaultsArgType.priv.tupleTypeArguments
|
||||
defaultsArgType.priv.tupleTypeArgs
|
||||
) {
|
||||
defaultArgCount = defaultsArgType.priv.tupleTypeArguments.length;
|
||||
defaultArgCount = defaultsArgType.priv.tupleTypeArgs.length;
|
||||
} else {
|
||||
defaultArgCount = undefined;
|
||||
}
|
||||
@ -167,7 +161,7 @@ export function createNamedTupleType(
|
||||
addGenericGetAttribute = true;
|
||||
} else {
|
||||
const entriesArg = argList[1];
|
||||
if (entriesArg.argumentCategory !== ArgumentCategory.Simple) {
|
||||
if (entriesArg.argCategory !== ArgCategory.Simple) {
|
||||
addGenericGetAttribute = true;
|
||||
} else {
|
||||
if (
|
||||
@ -414,7 +408,7 @@ export function createNamedTupleType(
|
||||
tupleClassType &&
|
||||
isInstantiableClass(tupleClassType)
|
||||
) {
|
||||
const literalTypes: TupleTypeArgument[] = matchArgsNames.map((name) => {
|
||||
const literalTypes: TupleTypeArg[] = matchArgsNames.map((name) => {
|
||||
return { type: ClassType.cloneAsInstance(ClassType.cloneWithLiteral(strType, name)), isUnbounded: false };
|
||||
});
|
||||
const matchArgsType = ClassType.cloneAsInstance(specializeTupleClass(tupleClassType, literalTypes));
|
||||
@ -428,11 +422,7 @@ export function createNamedTupleType(
|
||||
return classType;
|
||||
}
|
||||
|
||||
export function updateNamedTupleBaseClass(
|
||||
classType: ClassType,
|
||||
typeArgs: Type[],
|
||||
isTypeArgumentExplicit: boolean
|
||||
): boolean {
|
||||
export function updateNamedTupleBaseClass(classType: ClassType, typeArgs: Type[], isTypeArgExplicit: boolean): boolean {
|
||||
let isUpdateNeeded = false;
|
||||
|
||||
classType.shared.baseClasses = classType.shared.baseClasses.map((baseClass) => {
|
||||
@ -440,9 +430,9 @@ export function updateNamedTupleBaseClass(
|
||||
return baseClass;
|
||||
}
|
||||
|
||||
const tupleTypeArgs: TupleTypeArgument[] = [];
|
||||
const tupleTypeArgs: TupleTypeArg[] = [];
|
||||
|
||||
if (!isTypeArgumentExplicit) {
|
||||
if (!isTypeArgExplicit) {
|
||||
tupleTypeArgs.push({
|
||||
type: typeArgs.length > 0 ? combineTypes(typeArgs) : UnknownType.create(),
|
||||
isUnbounded: true,
|
||||
@ -456,8 +446,8 @@ export function updateNamedTupleBaseClass(
|
||||
// Create a copy of the NamedTuple class that replaces the tuple base class.
|
||||
const clonedNamedTupleClass = ClassType.cloneForSpecialization(
|
||||
baseClass,
|
||||
/* typeArguments */ undefined,
|
||||
isTypeArgumentExplicit
|
||||
/* typeArgs */ undefined,
|
||||
isTypeArgExplicit
|
||||
);
|
||||
clonedNamedTupleClass.shared = { ...clonedNamedTupleClass.shared };
|
||||
|
||||
@ -467,7 +457,7 @@ export function updateNamedTupleBaseClass(
|
||||
return namedTupleBaseClass;
|
||||
}
|
||||
|
||||
return specializeTupleClass(namedTupleBaseClass, tupleTypeArgs, isTypeArgumentExplicit);
|
||||
return specializeTupleClass(namedTupleBaseClass, tupleTypeArgs, isTypeArgExplicit);
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -277,10 +277,10 @@ export function validateBinaryOperation(
|
||||
operator === OperatorType.Add &&
|
||||
isClassInstance(leftSubtypeExpanded) &&
|
||||
isTupleClass(leftSubtypeExpanded) &&
|
||||
leftSubtypeExpanded.priv.tupleTypeArguments &&
|
||||
leftSubtypeExpanded.priv.tupleTypeArgs &&
|
||||
isClassInstance(rightSubtypeExpanded) &&
|
||||
isTupleClass(rightSubtypeExpanded) &&
|
||||
rightSubtypeExpanded.priv.tupleTypeArguments &&
|
||||
rightSubtypeExpanded.priv.tupleTypeArgs &&
|
||||
tupleClassType &&
|
||||
isInstantiableClass(tupleClassType)
|
||||
) {
|
||||
@ -295,8 +295,8 @@ export function validateBinaryOperation(
|
||||
) {
|
||||
return ClassType.cloneAsInstance(
|
||||
specializeTupleClass(tupleClassType, [
|
||||
...leftSubtypeExpanded.priv.tupleTypeArguments,
|
||||
...rightSubtypeExpanded.priv.tupleTypeArguments,
|
||||
...leftSubtypeExpanded.priv.tupleTypeArgs,
|
||||
...rightSubtypeExpanded.priv.tupleTypeArgs,
|
||||
])
|
||||
);
|
||||
}
|
||||
@ -449,8 +449,8 @@ export function getTypeOfBinaryOperation(
|
||||
inferenceContext &&
|
||||
isClassInstance(inferenceContext.expectedType) &&
|
||||
ClassType.isBuiltIn(inferenceContext.expectedType, 'list') &&
|
||||
inferenceContext.expectedType.priv.typeArguments &&
|
||||
inferenceContext.expectedType.priv.typeArguments.length >= 1 &&
|
||||
inferenceContext.expectedType.priv.typeArgs &&
|
||||
inferenceContext.expectedType.priv.typeArgs.length >= 1 &&
|
||||
node.d.leftExpr.nodeType === ParseNodeType.List
|
||||
) {
|
||||
expectedLeftOperandType = inferenceContext.expectedType;
|
||||
@ -551,12 +551,12 @@ export function getTypeOfBinaryOperation(
|
||||
return { type: UnknownType.create() };
|
||||
}
|
||||
|
||||
adjustedLeftType = evaluator.reportMissingTypeArguments(
|
||||
adjustedLeftType = evaluator.reportMissingTypeArgs(
|
||||
node.d.leftExpr,
|
||||
adjustedLeftType,
|
||||
flags | EvalFlags.InstantiableType
|
||||
);
|
||||
adjustedRightType = evaluator.reportMissingTypeArguments(
|
||||
adjustedRightType = evaluator.reportMissingTypeArgs(
|
||||
node.d.rightExpr,
|
||||
adjustedRightType,
|
||||
flags | EvalFlags.InstantiableType
|
||||
@ -590,7 +590,7 @@ export function getTypeOfBinaryOperation(
|
||||
if (stringNode && otherNode && otherType) {
|
||||
let isAllowed = true;
|
||||
if (isClass(otherType)) {
|
||||
if (!otherType.priv.isTypeArgumentExplicit || isClassInstance(otherType)) {
|
||||
if (!otherType.priv.isTypeArgExplicit || isClassInstance(otherType)) {
|
||||
isAllowed = false;
|
||||
}
|
||||
}
|
||||
|
@ -754,8 +754,8 @@ export class PackageTypeVerifier {
|
||||
let knownStatus = TypeKnownStatus.Known;
|
||||
|
||||
const aliasInfo = type.props?.typeAliasInfo;
|
||||
if (aliasInfo?.typeArguments) {
|
||||
aliasInfo.typeArguments.forEach((typeArg, index) => {
|
||||
if (aliasInfo?.typeArgs) {
|
||||
aliasInfo.typeArgs.forEach((typeArg, index) => {
|
||||
if (isUnknown(typeArg)) {
|
||||
this._addSymbolError(
|
||||
symbolInfo,
|
||||
@ -917,8 +917,8 @@ export class PackageTypeVerifier {
|
||||
}
|
||||
|
||||
// Analyze type arguments if present to make sure they are known.
|
||||
if (type.priv.typeArguments) {
|
||||
type.priv.typeArguments!.forEach((typeArg, index) => {
|
||||
if (type.priv.typeArgs) {
|
||||
type.priv.typeArgs!.forEach((typeArg, index) => {
|
||||
if (isUnknown(typeArg)) {
|
||||
this._addSymbolError(
|
||||
symbolInfo,
|
||||
@ -1297,8 +1297,8 @@ export class PackageTypeVerifier {
|
||||
let knownStatus = TypeKnownStatus.Known;
|
||||
|
||||
const aliasInfo = type.props?.typeAliasInfo;
|
||||
if (aliasInfo?.typeArguments) {
|
||||
aliasInfo.typeArguments.forEach((typeArg, index) => {
|
||||
if (aliasInfo?.typeArgs) {
|
||||
aliasInfo.typeArgs.forEach((typeArg, index) => {
|
||||
if (isUnknown(typeArg)) {
|
||||
diag.addMessage(`Type argument ${index + 1} for type alias "${aliasInfo!.name}" has unknown type`);
|
||||
knownStatus = this._updateKnownStatusIfWorse(knownStatus, TypeKnownStatus.Unknown);
|
||||
@ -1378,8 +1378,8 @@ export class PackageTypeVerifier {
|
||||
}
|
||||
|
||||
// Analyze type arguments if present to make sure they are known.
|
||||
if (type.priv.typeArguments) {
|
||||
type.priv.typeArguments!.forEach((typeArg, index) => {
|
||||
if (type.priv.typeArgs) {
|
||||
type.priv.typeArgs!.forEach((typeArg, index) => {
|
||||
if (isUnknown(typeArg)) {
|
||||
diag.addMessage(
|
||||
`Type argument ${index + 1} for class "${type.shared.name}" has unknown type`
|
||||
|
@ -161,10 +161,10 @@ export function getParameterListDetails(type: FunctionType): ParameterListDetail
|
||||
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.priv.tupleTypeArguments) {
|
||||
if (param.name && isUnpackedClass(paramType) && paramType.priv.tupleTypeArgs) {
|
||||
const addToPositionalOnly = index < result.positionOnlyParamCount;
|
||||
|
||||
paramType.priv.tupleTypeArguments.forEach((tupleArg, tupleIndex) => {
|
||||
paramType.priv.tupleTypeArgs.forEach((tupleArg, tupleIndex) => {
|
||||
const category =
|
||||
isVariadicTypeVar(tupleArg.type) || tupleArg.isUnbounded
|
||||
? ParameterCategory.ArgsList
|
||||
@ -321,7 +321,7 @@ export function getParameterListDetails(type: FunctionType): ParameterListDetail
|
||||
|
||||
// Returns true if the type of the argument type is "*args: P.args" or
|
||||
// "*args: Any". Both of these match a parameter of type "*args: P.args".
|
||||
export function isParamSpecArgsArgument(paramSpec: TypeVarType, argType: Type) {
|
||||
export function isParamSpecArgs(paramSpec: TypeVarType, argType: Type) {
|
||||
let isCompatible = true;
|
||||
|
||||
doForEachSubtype(argType, (argSubtype) => {
|
||||
@ -335,10 +335,10 @@ export function isParamSpecArgsArgument(paramSpec: TypeVarType, argType: Type) {
|
||||
|
||||
if (
|
||||
isClassInstance(argSubtype) &&
|
||||
argSubtype.priv.tupleTypeArguments &&
|
||||
argSubtype.priv.tupleTypeArguments.length === 1 &&
|
||||
argSubtype.priv.tupleTypeArguments[0].isUnbounded &&
|
||||
isAnyOrUnknown(argSubtype.priv.tupleTypeArguments[0].type)
|
||||
argSubtype.priv.tupleTypeArgs &&
|
||||
argSubtype.priv.tupleTypeArgs.length === 1 &&
|
||||
argSubtype.priv.tupleTypeArgs[0].isUnbounded &&
|
||||
isAnyOrUnknown(argSubtype.priv.tupleTypeArgs[0].type)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
@ -355,7 +355,7 @@ export function isParamSpecArgsArgument(paramSpec: TypeVarType, argType: Type) {
|
||||
|
||||
// Returns true if the type of the argument type is "**kwargs: P.kwargs" or
|
||||
// "*kwargs: Any". Both of these match a parameter of type "*kwargs: P.kwargs".
|
||||
export function isParamSpecKwargsArgument(paramSpec: TypeVarType, argType: Type) {
|
||||
export function isParamSpecKwargs(paramSpec: TypeVarType, argType: Type) {
|
||||
let isCompatible = true;
|
||||
|
||||
doForEachSubtype(argType, (argSubtype) => {
|
||||
@ -370,11 +370,11 @@ export function isParamSpecKwargsArgument(paramSpec: TypeVarType, argType: Type)
|
||||
if (
|
||||
isClassInstance(argSubtype) &&
|
||||
ClassType.isBuiltIn(argSubtype, 'dict') &&
|
||||
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])
|
||||
argSubtype.priv.typeArgs &&
|
||||
argSubtype.priv.typeArgs.length === 2 &&
|
||||
isClassInstance(argSubtype.priv.typeArgs[0]) &&
|
||||
ClassType.isBuiltIn(argSubtype.priv.typeArgs[0], 'str') &&
|
||||
isAnyOrUnknown(argSubtype.priv.typeArgs[1])
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import { convertPositionToOffset, convertTextRangeToRange } from '../common/posi
|
||||
import { Position, Range, TextRange } from '../common/textRange';
|
||||
import { TextRangeCollection, getIndexContaining } from '../common/textRangeCollection';
|
||||
import {
|
||||
ArgumentCategory,
|
||||
ArgCategory,
|
||||
ArgumentNode,
|
||||
AssignmentExpressionNode,
|
||||
AwaitNode,
|
||||
@ -195,11 +195,11 @@ export function getTypeSourceId(node: ParseNode): number {
|
||||
return node.start;
|
||||
}
|
||||
|
||||
export function printArgument(node: ArgumentNode, flags: PrintExpressionFlags) {
|
||||
export function printArg(node: ArgumentNode, flags: PrintExpressionFlags) {
|
||||
let argStr = '';
|
||||
if (node.d.argCategory === ArgumentCategory.UnpackedList) {
|
||||
if (node.d.argCategory === ArgCategory.UnpackedList) {
|
||||
argStr = '*';
|
||||
} else if (node.d.argCategory === ArgumentCategory.UnpackedDictionary) {
|
||||
} else if (node.d.argCategory === ArgCategory.UnpackedDictionary) {
|
||||
argStr = '**';
|
||||
}
|
||||
if (node.d.name) {
|
||||
@ -234,14 +234,14 @@ export function printExpression(node: ExpressionNode, flags = PrintExpressionFla
|
||||
lhs = `(${lhs})`;
|
||||
}
|
||||
|
||||
return lhs + '(' + node.d.args.map((arg) => printArgument(arg, flags)).join(', ') + ')';
|
||||
return lhs + '(' + node.d.args.map((arg) => printArg(arg, flags)).join(', ') + ')';
|
||||
}
|
||||
|
||||
case ParseNodeType.Index: {
|
||||
return (
|
||||
printExpression(node.d.leftExpr, flags) +
|
||||
'[' +
|
||||
node.d.items.map((item) => printArgument(item, flags)).join(', ') +
|
||||
node.d.items.map((item) => printArg(item, flags)).join(', ') +
|
||||
(node.d.trailingComma ? ',' : '') +
|
||||
']'
|
||||
);
|
||||
@ -1124,12 +1124,12 @@ export function getTypeAnnotationNode(node: ParseNode): TypeAnnotationNode | und
|
||||
// In general, arguments passed to a call are evaluated by the runtime in
|
||||
// left-to-right order. There is one exception, however, when an unpacked
|
||||
// iterable is used after a keyword argument.
|
||||
export function getArgumentsByRuntimeOrder(node: CallNode) {
|
||||
export function getArgsByRuntimeOrder(node: CallNode) {
|
||||
const positionalArgs = node.d.args.filter(
|
||||
(arg) => !arg.d.name && arg.d.argCategory !== ArgumentCategory.UnpackedDictionary
|
||||
(arg) => !arg.d.name && arg.d.argCategory !== ArgCategory.UnpackedDictionary
|
||||
);
|
||||
const keywordArgs = node.d.args.filter(
|
||||
(arg) => !!arg.d.name || arg.d.argCategory === ArgumentCategory.UnpackedDictionary
|
||||
(arg) => !!arg.d.name || arg.d.argCategory === ArgCategory.UnpackedDictionary
|
||||
);
|
||||
return positionalArgs.concat(keywordArgs);
|
||||
}
|
||||
@ -1332,7 +1332,7 @@ export function isMatchingExpression(reference: ExpressionNode, expression: Expr
|
||||
expression.d.items.length !== 1 ||
|
||||
expression.d.trailingComma ||
|
||||
expression.d.items[0].d.name ||
|
||||
expression.d.items[0].d.argCategory !== ArgumentCategory.Simple
|
||||
expression.d.items[0].d.argCategory !== ArgCategory.Simple
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ import { DiagnosticAddendum } from '../common/diagnostic';
|
||||
import { DiagnosticRule } from '../common/diagnosticRules';
|
||||
import { LocAddendum, LocMessage } from '../localization/localize';
|
||||
import {
|
||||
ArgumentCategory,
|
||||
ArgCategory,
|
||||
ExpressionNode,
|
||||
ParseNode,
|
||||
ParseNodeType,
|
||||
@ -230,10 +230,8 @@ function narrowTypeBasedOnSequencePattern(
|
||||
canNarrowTuple = false;
|
||||
}
|
||||
|
||||
if (isClassInstance(entry.subtype) && entry.subtype.priv.tupleTypeArguments) {
|
||||
const unboundedIndex = entry.subtype.priv.tupleTypeArguments.findIndex(
|
||||
(typeArg) => typeArg.isUnbounded
|
||||
);
|
||||
if (isClassInstance(entry.subtype) && entry.subtype.priv.tupleTypeArgs) {
|
||||
const unboundedIndex = entry.subtype.priv.tupleTypeArgs.findIndex((typeArg) => typeArg.isUnbounded);
|
||||
|
||||
if (unboundedIndex >= 0) {
|
||||
// If the pattern includes a "star" entry that aligns exactly with
|
||||
@ -274,13 +272,13 @@ function narrowTypeBasedOnSequencePattern(
|
||||
if (index === pattern.d.starEntryIndex) {
|
||||
if (
|
||||
isClassInstance(narrowedEntryType) &&
|
||||
narrowedEntryType.priv.tupleTypeArguments &&
|
||||
narrowedEntryType.priv.tupleTypeArgs &&
|
||||
!isUnboundedTupleClass(narrowedEntryType) &&
|
||||
narrowedEntryType.priv.tupleTypeArguments
|
||||
narrowedEntryType.priv.tupleTypeArgs
|
||||
) {
|
||||
appendArray(
|
||||
narrowedEntryTypes,
|
||||
narrowedEntryType.priv.tupleTypeArguments.map((t) => t.type)
|
||||
narrowedEntryType.priv.tupleTypeArgs.map((t) => t.type)
|
||||
);
|
||||
} else {
|
||||
narrowedEntryTypes.push(narrowedEntryType);
|
||||
@ -396,7 +394,7 @@ function narrowTypeBasedOnSequencePattern(
|
||||
typeArgType = containsAnyOrUnknown(typeArgType, /* recurse */ false) ?? typeArgType;
|
||||
|
||||
entry.subtype = ClassType.cloneAsInstance(
|
||||
ClassType.cloneForSpecialization(sequenceType, [typeArgType], /* isTypeArgumentExplicit */ true)
|
||||
ClassType.cloneForSpecialization(sequenceType, [typeArgType], /* isTypeArgExplicit */ true)
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -633,9 +631,9 @@ function getPositionalMatchArgNames(evaluator: TypeEvaluator, type: ClassType):
|
||||
isClassInstance(matchArgsType) &&
|
||||
isTupleClass(matchArgsType) &&
|
||||
!isUnboundedTupleClass(matchArgsType) &&
|
||||
matchArgsType.priv.tupleTypeArguments
|
||||
matchArgsType.priv.tupleTypeArgs
|
||||
) {
|
||||
const tupleArgs = matchArgsType.priv.tupleTypeArguments;
|
||||
const tupleArgs = matchArgsType.priv.tupleTypeArgs;
|
||||
|
||||
// Are all the args string literals?
|
||||
if (
|
||||
@ -750,8 +748,8 @@ function narrowTypeBasedOnClassPattern(
|
||||
if (classType.shared.typeParameters.length > 0) {
|
||||
classType = ClassType.cloneForSpecialization(
|
||||
classType,
|
||||
/* typeArguments */ undefined,
|
||||
/* isTypeArgumentExplicit */ false
|
||||
/* typeArgs */ undefined,
|
||||
/* isTypeArgExplicit */ false
|
||||
);
|
||||
}
|
||||
|
||||
@ -828,7 +826,7 @@ function narrowTypeBasedOnClassPattern(
|
||||
}
|
||||
|
||||
for (let index = 0; index < pattern.d.args.length; index++) {
|
||||
const narrowedArgType = narrowTypeOfClassPatternArgument(
|
||||
const narrowedArgType = narrowTypeOfClassPatternArg(
|
||||
evaluator,
|
||||
pattern.d.args[index],
|
||||
index,
|
||||
@ -959,8 +957,8 @@ function narrowTypeBasedOnClassPattern(
|
||||
const typeVarContext = new TypeVarContext(getTypeVarScopeId(unexpandedSubtype));
|
||||
const unspecializedMatchType = ClassType.cloneForSpecialization(
|
||||
unexpandedSubtype,
|
||||
/* typeArguments */ undefined,
|
||||
/* isTypeArgumentExplicit */ false
|
||||
/* typeArgs */ undefined,
|
||||
/* isTypeArgExplicit */ false
|
||||
);
|
||||
|
||||
const matchTypeInstance = ClassType.cloneAsInstance(unspecializedMatchType);
|
||||
@ -997,7 +995,7 @@ function narrowTypeBasedOnClassPattern(
|
||||
// Narrow the arg pattern. It's possible that the actual type of the object
|
||||
// being matched is a subtype of the resultType, so it might contain additional
|
||||
// attributes that we don't know about.
|
||||
const narrowedArgType = narrowTypeOfClassPatternArgument(
|
||||
const narrowedArgType = narrowTypeOfClassPatternArg(
|
||||
evaluator,
|
||||
arg,
|
||||
index,
|
||||
@ -1049,7 +1047,7 @@ function isClassSpecialCaseForClassPattern(classType: ClassType) {
|
||||
}
|
||||
|
||||
// Narrows the pattern provided for a class pattern argument.
|
||||
function narrowTypeOfClassPatternArgument(
|
||||
function narrowTypeOfClassPatternArg(
|
||||
evaluator: TypeEvaluator,
|
||||
arg: PatternClassArgumentNode,
|
||||
argIndex: number,
|
||||
@ -1268,14 +1266,14 @@ function getMappingPatternInfo(evaluator: TypeEvaluator, type: Type, node: Patte
|
||||
if (evaluator.assignType(mappingObject, subtype, /* diag */ undefined, typeVarContext)) {
|
||||
const specializedMapping = applySolvedTypeVars(mappingObject, typeVarContext) as ClassType;
|
||||
|
||||
if (specializedMapping.priv.typeArguments && specializedMapping.priv.typeArguments.length >= 2) {
|
||||
if (specializedMapping.priv.typeArgs && specializedMapping.priv.typeArgs.length >= 2) {
|
||||
mappingInfo.push({
|
||||
subtype,
|
||||
isDefinitelyMapping: true,
|
||||
isDefinitelyNotMapping: false,
|
||||
dictTypeArgs: {
|
||||
key: specializedMapping.priv.typeArguments[0],
|
||||
value: specializedMapping.priv.typeArguments[1],
|
||||
key: specializedMapping.priv.typeArgs[0],
|
||||
value: specializedMapping.priv.typeArgs[1],
|
||||
},
|
||||
});
|
||||
}
|
||||
@ -1365,7 +1363,7 @@ function getSequencePatternInfo(
|
||||
) as ClassType;
|
||||
|
||||
if (isTupleClass(specializedSequence)) {
|
||||
const typeArgs = specializedSequence.priv.tupleTypeArguments ?? [
|
||||
const typeArgs = specializedSequence.priv.tupleTypeArgs ?? [
|
||||
{ type: UnknownType.create(), isUnbounded: true },
|
||||
];
|
||||
|
||||
@ -1503,8 +1501,8 @@ function getSequencePatternInfo(
|
||||
sequenceInfo.push({
|
||||
subtype,
|
||||
entryTypes: [
|
||||
specializedSequence.priv.typeArguments && specializedSequence.priv.typeArguments.length > 0
|
||||
? specializedSequence.priv.typeArguments[0]
|
||||
specializedSequence.priv.typeArgs && specializedSequence.priv.typeArgs.length > 0
|
||||
? specializedSequence.priv.typeArgs[0]
|
||||
: UnknownType.create(),
|
||||
],
|
||||
isIndeterminateLength: true,
|
||||
@ -1526,10 +1524,10 @@ function getSequencePatternInfo(
|
||||
if (evaluator.assignType(sequenceObject, subtype, /* diag */ undefined, typeVarContext)) {
|
||||
const specializedSequence = applySolvedTypeVars(sequenceObject, typeVarContext) as ClassType;
|
||||
|
||||
if (specializedSequence.priv.typeArguments && specializedSequence.priv.typeArguments.length > 0) {
|
||||
if (specializedSequence.priv.typeArgs && specializedSequence.priv.typeArgs.length > 0) {
|
||||
sequenceInfo.push({
|
||||
subtype,
|
||||
entryTypes: [specializedSequence.priv.typeArguments[0]],
|
||||
entryTypes: [specializedSequence.priv.typeArgs[0]],
|
||||
isIndeterminateLength: true,
|
||||
isDefiniteNoMatch: false,
|
||||
isPotentialNoMatch: false,
|
||||
@ -1555,10 +1553,10 @@ function getSequencePatternInfo(
|
||||
sequenceTypeVarContext
|
||||
) as ClassType;
|
||||
|
||||
if (specializedSequence.priv.typeArguments && specializedSequence.priv.typeArguments.length > 0) {
|
||||
if (specializedSequence.priv.typeArgs && specializedSequence.priv.typeArgs.length > 0) {
|
||||
sequenceInfo.push({
|
||||
subtype,
|
||||
entryTypes: [specializedSequence.priv.typeArguments[0]],
|
||||
entryTypes: [specializedSequence.priv.typeArgs[0]],
|
||||
isIndeterminateLength: true,
|
||||
isDefiniteNoMatch: false,
|
||||
isPotentialNoMatch: true,
|
||||
@ -1573,7 +1571,7 @@ function getSequencePatternInfo(
|
||||
ClassType.cloneForSpecialization(
|
||||
ClassType.cloneAsInstance(sequenceType),
|
||||
[UnknownType.create()],
|
||||
/* isTypeArgumentExplicit */ true
|
||||
/* isTypeArgExplicit */ true
|
||||
)
|
||||
)
|
||||
) {
|
||||
@ -1831,7 +1829,7 @@ export function assignTypeToPatternTargets(
|
||||
ClassType.cloneForSpecialization(
|
||||
dictClass,
|
||||
[keyType, valueType],
|
||||
/* isTypeArgumentExplicit */ true
|
||||
/* isTypeArgExplicit */ true
|
||||
)
|
||||
)
|
||||
: UnknownType.create();
|
||||
@ -1869,7 +1867,7 @@ export function assignTypeToPatternTargets(
|
||||
}
|
||||
|
||||
pattern.d.args.forEach((arg, index) => {
|
||||
const narrowedArgType = narrowTypeOfClassPatternArgument(
|
||||
const narrowedArgType = narrowTypeOfClassPatternArg(
|
||||
evaluator,
|
||||
arg,
|
||||
index,
|
||||
@ -1918,7 +1916,7 @@ function wrapTypeInList(evaluator: TypeEvaluator, node: ParseNode, type: Type):
|
||||
// types before wrapping it in a list.
|
||||
type = containsAnyOrUnknown(type, /* recurse */ false) ?? type;
|
||||
|
||||
return ClassType.cloneForSpecialization(listObjectType, [type], /* isTypeArgumentExplicit */ true);
|
||||
return ClassType.cloneForSpecialization(listObjectType, [type], /* isTypeArgExplicit */ true);
|
||||
}
|
||||
|
||||
return UnknownType.create();
|
||||
@ -1941,8 +1939,8 @@ export function validateClassPattern(evaluator: TypeEvaluator, pattern: PatternC
|
||||
if (
|
||||
exprType.props?.typeAliasInfo &&
|
||||
isInstantiableClass(exprType) &&
|
||||
exprType.priv.typeArguments &&
|
||||
exprType.priv.isTypeArgumentExplicit
|
||||
exprType.priv.typeArgs &&
|
||||
exprType.priv.isTypeArgExplicit
|
||||
) {
|
||||
evaluator.addDiagnostic(
|
||||
DiagnosticRule.reportGeneralTypeIssues,
|
||||
@ -2017,7 +2015,7 @@ export function getPatternSubtypeNarrowingCallback(
|
||||
subjectExpression.nodeType === ParseNodeType.Index &&
|
||||
subjectExpression.d.items.length === 1 &&
|
||||
!subjectExpression.d.trailingComma &&
|
||||
subjectExpression.d.items[0].d.argCategory === ArgumentCategory.Simple &&
|
||||
subjectExpression.d.items[0].d.argCategory === ArgCategory.Simple &&
|
||||
isMatchingExpression(reference, subjectExpression.d.leftExpr)
|
||||
) {
|
||||
const indexTypeResult = evaluator.getTypeOfExpression(subjectExpression.d.items[0].d.valueExpr);
|
||||
@ -2094,11 +2092,11 @@ export function getPatternSubtypeNarrowingCallback(
|
||||
if (
|
||||
isClassInstance(subtype) &&
|
||||
ClassType.isBuiltIn(subtype, 'tuple') &&
|
||||
subtype.priv.tupleTypeArguments &&
|
||||
matchingEntryIndex < subtype.priv.tupleTypeArguments.length &&
|
||||
subtype.priv.tupleTypeArguments.every((e) => !e.isUnbounded)
|
||||
subtype.priv.tupleTypeArgs &&
|
||||
matchingEntryIndex < subtype.priv.tupleTypeArgs.length &&
|
||||
subtype.priv.tupleTypeArgs.every((e) => !e.isUnbounded)
|
||||
) {
|
||||
narrowedSubtypes.push(subtype.priv.tupleTypeArguments[matchingEntryIndex].type);
|
||||
narrowedSubtypes.push(subtype.priv.tupleTypeArgs[matchingEntryIndex].type);
|
||||
} else if (isNever(narrowedSubjectType)) {
|
||||
narrowedSubtypes.push(narrowedSubjectType);
|
||||
} else {
|
||||
|
@ -1540,7 +1540,7 @@ export class Program {
|
||||
}
|
||||
|
||||
if (configOptions.diagnosticRuleSet.omitTypeArgsIfUnknown) {
|
||||
flags |= PrintTypeFlags.OmitTypeArgumentsIfUnknown;
|
||||
flags |= PrintTypeFlags.OmitTypeArgsIfUnknown;
|
||||
}
|
||||
|
||||
if (configOptions.diagnosticRuleSet.omitUnannotatedParamType) {
|
||||
|
@ -737,13 +737,13 @@ function assignClassToProtocolInternal(
|
||||
const genericProtocolType = ClassType.cloneForSpecialization(
|
||||
destType,
|
||||
undefined,
|
||||
/* isTypeArgumentExplicit */ false
|
||||
/* isTypeArgExplicit */ false
|
||||
);
|
||||
const specializedProtocolType = applySolvedTypeVars(genericProtocolType, protocolTypeVarContext) as ClassType;
|
||||
|
||||
if (destType.priv.typeArguments) {
|
||||
if (destType.priv.typeArgs) {
|
||||
if (
|
||||
!evaluator.assignTypeArguments(
|
||||
!evaluator.assignTypeArgs(
|
||||
destType,
|
||||
specializedProtocolType,
|
||||
diag,
|
||||
@ -794,8 +794,8 @@ function createProtocolTypeVarContext(
|
||||
entry.narrowBoundNoLiterals,
|
||||
entry.wideBound
|
||||
);
|
||||
} else if (destType.priv.typeArguments && index < destType.priv.typeArguments.length) {
|
||||
let typeArg = destType.priv.typeArguments[index];
|
||||
} else if (destType.priv.typeArgs && index < destType.priv.typeArgs.length) {
|
||||
let typeArg = destType.priv.typeArgs[index];
|
||||
let flags: AssignTypeFlags;
|
||||
let hasUnsolvedTypeVars = requiresSpecialization(typeArg);
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
import { ExecutionEnvironment, PythonPlatform } from '../common/configOptions';
|
||||
import { PythonReleaseLevel, PythonVersion } from '../common/pythonVersion';
|
||||
import { ArgumentCategory, ExpressionNode, NameNode, NumberNode, ParseNodeType, TupleNode } from '../parser/parseNodes';
|
||||
import { ArgCategory, ExpressionNode, NameNode, NumberNode, ParseNodeType, TupleNode } from '../parser/parseNodes';
|
||||
import { KeywordType, OperatorType } from '../parser/tokenizerTypes';
|
||||
|
||||
// Returns undefined if the expression cannot be evaluated
|
||||
@ -89,7 +89,7 @@ export function evaluateStaticBoolExpression(
|
||||
node.d.leftExpr.d.items.length === 1 &&
|
||||
!node.d.leftExpr.d.trailingComma &&
|
||||
!node.d.leftExpr.d.items[0].d.name &&
|
||||
node.d.leftExpr.d.items[0].d.argCategory === ArgumentCategory.Simple &&
|
||||
node.d.leftExpr.d.items[0].d.argCategory === ArgCategory.Simple &&
|
||||
node.d.leftExpr.d.items[0].d.valueExpr.nodeType === ParseNodeType.Number &&
|
||||
!node.d.leftExpr.d.items[0].d.valueExpr.d.isImaginary &&
|
||||
node.d.leftExpr.d.items[0].d.valueExpr.d.value === 0 &&
|
||||
|
@ -21,7 +21,7 @@ import {
|
||||
isTypeVar,
|
||||
isUnpackedVariadicTypeVar,
|
||||
isVariadicTypeVar,
|
||||
TupleTypeArgument,
|
||||
TupleTypeArg,
|
||||
Type,
|
||||
TypeVarType,
|
||||
} from './types';
|
||||
@ -31,7 +31,7 @@ import { TypeVarContext } from './typeVarContext';
|
||||
// Assigns the source type arguments to the dest type arguments. It assumed
|
||||
// the the caller has already verified that both the dest and source are
|
||||
// tuple classes.
|
||||
export function assignTupleTypeArguments(
|
||||
export function assignTupleTypeArgs(
|
||||
evaluator: TypeEvaluator,
|
||||
destType: ClassType,
|
||||
srcType: ClassType,
|
||||
@ -41,8 +41,8 @@ export function assignTupleTypeArguments(
|
||||
flags: AssignTypeFlags,
|
||||
recursionCount: number
|
||||
) {
|
||||
const destTypeArgs = [...(destType.priv.tupleTypeArguments ?? [])];
|
||||
const srcTypeArgs = [...(srcType.priv.tupleTypeArguments ?? [])];
|
||||
const destTypeArgs = [...(destType.priv.tupleTypeArgs ?? [])];
|
||||
const srcTypeArgs = [...(srcType.priv.tupleTypeArgs ?? [])];
|
||||
|
||||
if (adjustTupleTypeArgs(evaluator, destTypeArgs, srcTypeArgs, flags)) {
|
||||
for (let argIndex = 0; argIndex < srcTypeArgs.length; argIndex++) {
|
||||
@ -129,8 +129,8 @@ export function assignTupleTypeArguments(
|
||||
// if the source is potentially compatible with the dest type, false otherwise.
|
||||
export function adjustTupleTypeArgs(
|
||||
evaluator: TypeEvaluator,
|
||||
destTypeArgs: TupleTypeArgument[],
|
||||
srcTypeArgs: TupleTypeArgument[],
|
||||
destTypeArgs: TupleTypeArg[],
|
||||
srcTypeArgs: TupleTypeArg[],
|
||||
flags: AssignTypeFlags
|
||||
): boolean {
|
||||
const destUnboundedOrVariadicIndex = destTypeArgs.findIndex((t) => t.isUnbounded || isVariadicTypeVar(t.type));
|
||||
@ -204,7 +204,7 @@ export function adjustTupleTypeArgs(
|
||||
isOptional: typeArg.isOptional,
|
||||
};
|
||||
}),
|
||||
/* isTypeArgumentExplicit */ true,
|
||||
/* isTypeArgExplicit */ true,
|
||||
/* isUnpackedTuple */ true
|
||||
)
|
||||
);
|
||||
@ -245,7 +245,7 @@ export function adjustTupleTypeArgs(
|
||||
isOptional: typeArg.isOptional,
|
||||
};
|
||||
}),
|
||||
/* isTypeArgumentExplicit */ true,
|
||||
/* isTypeArgExplicit */ true,
|
||||
/* isUnpackedTuple */ true
|
||||
)
|
||||
);
|
||||
@ -296,11 +296,11 @@ export function getSlicedTupleType(
|
||||
sliceNode: SliceNode
|
||||
): Type | undefined {
|
||||
// We don't handle step values.
|
||||
if (sliceNode.d.stepValue || !tupleType.priv.tupleTypeArguments) {
|
||||
if (sliceNode.d.stepValue || !tupleType.priv.tupleTypeArgs) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const tupleTypeArgs = tupleType.priv.tupleTypeArguments;
|
||||
const tupleTypeArgs = tupleType.priv.tupleTypeArgs;
|
||||
const startValue = getTupleSliceParameter(evaluator, sliceNode.d.startValue, 0, tupleTypeArgs);
|
||||
const endValue = getTupleSliceParameter(evaluator, sliceNode.d.endValue, tupleTypeArgs.length, tupleTypeArgs);
|
||||
|
||||
@ -316,7 +316,7 @@ function getTupleSliceParameter(
|
||||
evaluator: TypeEvaluator,
|
||||
expression: ExpressionNode | undefined,
|
||||
defaultValue: number,
|
||||
tupleTypeArgs: TupleTypeArgument[]
|
||||
tupleTypeArgs: TupleTypeArg[]
|
||||
): number | undefined {
|
||||
let value = defaultValue;
|
||||
|
||||
|
@ -69,13 +69,13 @@ function getComplexityScoreForClass(classType: ClassType, recursionCount: number
|
||||
let typeArgScoreSum = 0;
|
||||
let typeArgCount = 0;
|
||||
|
||||
if (classType.priv.tupleTypeArguments) {
|
||||
classType.priv.tupleTypeArguments.forEach((typeArg) => {
|
||||
if (classType.priv.tupleTypeArgs) {
|
||||
classType.priv.tupleTypeArgs.forEach((typeArg) => {
|
||||
typeArgScoreSum += getComplexityScoreForType(typeArg.type, recursionCount);
|
||||
typeArgCount++;
|
||||
});
|
||||
} else if (classType.priv.typeArguments) {
|
||||
classType.priv.typeArguments.forEach((type) => {
|
||||
} else if (classType.priv.typeArgs) {
|
||||
classType.priv.typeArgs.forEach((type) => {
|
||||
typeArgScoreSum += getComplexityScoreForType(type, recursionCount);
|
||||
typeArgCount++;
|
||||
});
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -14,7 +14,7 @@ import { Diagnostic, DiagnosticAddendum } from '../common/diagnostic';
|
||||
import { DiagnosticRule } from '../common/diagnosticRules';
|
||||
import { TextRange } from '../common/textRange';
|
||||
import {
|
||||
ArgumentCategory,
|
||||
ArgCategory,
|
||||
ArgumentNode,
|
||||
CallNode,
|
||||
CaseNode,
|
||||
@ -292,8 +292,8 @@ export interface AbstractSymbol {
|
||||
hasImplementation: boolean;
|
||||
}
|
||||
|
||||
export interface FunctionArgumentBase {
|
||||
argumentCategory: ArgumentCategory;
|
||||
export interface ArgBase {
|
||||
argCategory: ArgCategory;
|
||||
node?: ArgumentNode | undefined;
|
||||
name?: NameNode | undefined;
|
||||
typeResult?: TypeResult | undefined;
|
||||
@ -301,15 +301,15 @@ export interface FunctionArgumentBase {
|
||||
active?: boolean | undefined;
|
||||
}
|
||||
|
||||
export interface FunctionArgumentWithType extends FunctionArgumentBase {
|
||||
export interface ArgWithType extends ArgBase {
|
||||
typeResult: TypeResult;
|
||||
}
|
||||
|
||||
export interface FunctionArgumentWithExpression extends FunctionArgumentBase {
|
||||
export interface ArgWithExpression extends ArgBase {
|
||||
valueExpression: ExpressionNode;
|
||||
}
|
||||
|
||||
export type FunctionArgument = FunctionArgumentWithType | FunctionArgumentWithExpression;
|
||||
export type Arg = ArgWithType | ArgWithExpression;
|
||||
|
||||
export interface EffectiveTypeResult {
|
||||
type: Type;
|
||||
@ -325,7 +325,7 @@ export interface ValidateArgTypeParams {
|
||||
paramCategory: ParameterCategory;
|
||||
paramType: Type;
|
||||
requiresTypeVarMatching: boolean;
|
||||
argument: FunctionArgument;
|
||||
argument: Arg;
|
||||
isDefaultArg?: boolean;
|
||||
argType?: Type | undefined;
|
||||
errorNode: ExpressionNode;
|
||||
@ -385,7 +385,7 @@ export interface CallResult {
|
||||
argumentErrors?: boolean;
|
||||
|
||||
// Did one or more arguments evaluated to Any or Unknown?
|
||||
anyOrUnknownArgument?: UnknownType | AnyType;
|
||||
anyOrUnknownArg?: UnknownType | AnyType;
|
||||
|
||||
// The parameter associated with the "active" argument (used
|
||||
// for signature help provider)
|
||||
@ -451,7 +451,7 @@ export interface PrintTypeOptions {
|
||||
useTypingUnpack?: boolean;
|
||||
printUnknownWithAny?: boolean;
|
||||
printTypeVarVariance?: boolean;
|
||||
omitTypeArgumentsIfUnknown?: boolean;
|
||||
omitTypeArgsIfUnknown?: boolean;
|
||||
}
|
||||
|
||||
export interface DeclaredSymbolTypeInfo {
|
||||
@ -514,7 +514,7 @@ export interface TypeEvaluator {
|
||||
verifyDeleteExpression: (node: ExpressionNode) => void;
|
||||
validateOverloadedArgTypes: (
|
||||
errorNode: ExpressionNode,
|
||||
argList: FunctionArgument[],
|
||||
argList: Arg[],
|
||||
typeResult: TypeResult<OverloadedFunctionType>,
|
||||
typeVarContext: TypeVarContext | undefined,
|
||||
skipUnknownArgCheck: boolean,
|
||||
@ -557,7 +557,7 @@ export interface TypeEvaluator {
|
||||
emitNotIterableError?: boolean
|
||||
) => TypeResult | undefined;
|
||||
getGetterTypeFromProperty: (propertyClass: ClassType, inferTypeIfNeeded: boolean) => Type | undefined;
|
||||
getTypeOfArgument: (arg: FunctionArgument, inferenceContext: InferenceContext | undefined) => TypeResult;
|
||||
getTypeOfArg: (arg: Arg, inferenceContext: InferenceContext | undefined) => TypeResult;
|
||||
markNamesAccessed: (node: ParseNode, names: string[]) => void;
|
||||
expandPromotionTypes: (node: ParseNode, type: Type) => Type;
|
||||
makeTopLevelTypeVarsConcrete: (type: Type, makeParamSpecsConcrete?: boolean) => Type;
|
||||
@ -579,10 +579,10 @@ export interface TypeEvaluator {
|
||||
getDeclaredTypeForExpression: (expression: ExpressionNode, usage?: EvaluatorUsage) => Type | undefined;
|
||||
getFunctionDeclaredReturnType: (node: FunctionNode) => Type | undefined;
|
||||
getFunctionInferredReturnType: (type: FunctionType, callSiteInfo?: CallSiteEvaluationInfo) => Type;
|
||||
getBestOverloadForArguments: (
|
||||
getBestOverloadForArgs: (
|
||||
errorNode: ExpressionNode,
|
||||
typeResult: TypeResult<OverloadedFunctionType>,
|
||||
argList: FunctionArgument[]
|
||||
argList: Arg[]
|
||||
) => FunctionType | undefined;
|
||||
getBuiltInType: (node: ParseNode, name: string) => Type;
|
||||
getTypeOfMember: (member: ClassMember) => Type;
|
||||
@ -638,9 +638,9 @@ export interface TypeEvaluator {
|
||||
diag: DiagnosticAddendum,
|
||||
enforceParamNames?: boolean
|
||||
) => boolean;
|
||||
validateCallArguments: (
|
||||
validateCallArgs: (
|
||||
errorNode: ExpressionNode,
|
||||
argList: FunctionArgument[],
|
||||
argList: Arg[],
|
||||
callTypeResult: TypeResult,
|
||||
typeVarContext: TypeVarContext | undefined,
|
||||
skipUnknownArgCheck: boolean | undefined,
|
||||
@ -649,7 +649,7 @@ export interface TypeEvaluator {
|
||||
validateTypeArg: (argResult: TypeResultWithNode, options?: ValidateTypeArgsOptions) => boolean;
|
||||
assignTypeToExpression: (target: ExpressionNode, typeResult: TypeResult, srcExpr: ExpressionNode) => void;
|
||||
assignClassToSelf: (destType: ClassType, srcType: ClassType, assumedVariance: Variance) => boolean;
|
||||
getBuiltInObject: (node: ParseNode, name: string, typeArguments?: Type[]) => Type;
|
||||
getBuiltInObject: (node: ParseNode, name: string, typeArgs?: Type[]) => Type;
|
||||
getTypedDictClassType: () => ClassType | undefined;
|
||||
getTupleClassType: () => ClassType | undefined;
|
||||
getObjectType: () => Type;
|
||||
@ -659,7 +659,7 @@ export interface TypeEvaluator {
|
||||
getTypingType: (node: ParseNode, symbolName: string) => Type | undefined;
|
||||
inferReturnTypeIfNecessary: (type: Type) => void;
|
||||
inferTypeParameterVarianceForClass: (type: ClassType) => void;
|
||||
assignTypeArguments: (
|
||||
assignTypeArgs: (
|
||||
destType: ClassType,
|
||||
srcType: ClassType,
|
||||
diag: DiagnosticAddendum | undefined,
|
||||
@ -668,7 +668,7 @@ export interface TypeEvaluator {
|
||||
flags: AssignTypeFlags,
|
||||
recursionCount: number
|
||||
) => boolean;
|
||||
reportMissingTypeArguments: (node: ExpressionNode, type: Type, flags: EvalFlags) => Type;
|
||||
reportMissingTypeArgs: (node: ExpressionNode, type: Type, flags: EvalFlags) => Type;
|
||||
|
||||
isFinalVariable: (symbol: Symbol) => boolean;
|
||||
isFinalVariableDeclaration: (decl: Declaration) => boolean;
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
import { assert } from '../common/debug';
|
||||
import {
|
||||
ArgumentCategory,
|
||||
ArgCategory,
|
||||
AssignmentExpressionNode,
|
||||
ExpressionNode,
|
||||
isExpressionNode,
|
||||
@ -54,7 +54,7 @@ import {
|
||||
isUnpackedVariadicTypeVar,
|
||||
maxTypeRecursionCount,
|
||||
OverloadedFunctionType,
|
||||
TupleTypeArgument,
|
||||
TupleTypeArg,
|
||||
Type,
|
||||
TypeBase,
|
||||
TypeCategory,
|
||||
@ -174,7 +174,7 @@ export function getTypeNarrowingCallback(
|
||||
ParseTreeUtils.isMatchingExpression(reference, leftExpression.d.leftExpr) &&
|
||||
leftExpression.d.items.length === 1 &&
|
||||
!leftExpression.d.trailingComma &&
|
||||
leftExpression.d.items[0].d.argCategory === ArgumentCategory.Simple &&
|
||||
leftExpression.d.items[0].d.argCategory === ArgCategory.Simple &&
|
||||
!leftExpression.d.items[0].d.name &&
|
||||
leftExpression.d.items[0].d.valueExpr.nodeType === ParseNodeType.Number &&
|
||||
leftExpression.d.items[0].d.valueExpr.d.isInteger &&
|
||||
@ -215,7 +215,7 @@ export function getTypeNarrowingCallback(
|
||||
if (testExpression.d.leftExpr.nodeType === ParseNodeType.Call) {
|
||||
if (
|
||||
testExpression.d.leftExpr.d.args.length === 1 &&
|
||||
testExpression.d.leftExpr.d.args[0].d.argCategory === ArgumentCategory.Simple
|
||||
testExpression.d.leftExpr.d.args[0].d.argCategory === ArgCategory.Simple
|
||||
) {
|
||||
const arg0Expr = testExpression.d.leftExpr.d.args[0].d.valueExpr;
|
||||
if (ParseTreeUtils.isMatchingExpression(reference, arg0Expr)) {
|
||||
@ -282,7 +282,7 @@ export function getTypeNarrowingCallback(
|
||||
testExpression.d.leftExpr.nodeType === ParseNodeType.Index &&
|
||||
testExpression.d.leftExpr.d.items.length === 1 &&
|
||||
!testExpression.d.leftExpr.d.trailingComma &&
|
||||
testExpression.d.leftExpr.d.items[0].d.argCategory === ArgumentCategory.Simple &&
|
||||
testExpression.d.leftExpr.d.items[0].d.argCategory === ArgCategory.Simple &&
|
||||
ParseTreeUtils.isMatchingExpression(reference, testExpression.d.leftExpr.d.leftExpr)
|
||||
) {
|
||||
const indexTypeResult = evaluator.getTypeOfExpression(
|
||||
@ -376,7 +376,7 @@ export function getTypeNarrowingCallback(
|
||||
testExpression.d.leftExpr.nodeType === ParseNodeType.Index &&
|
||||
testExpression.d.leftExpr.d.items.length === 1 &&
|
||||
!testExpression.d.leftExpr.d.trailingComma &&
|
||||
testExpression.d.leftExpr.d.items[0].d.argCategory === ArgumentCategory.Simple &&
|
||||
testExpression.d.leftExpr.d.items[0].d.argCategory === ArgCategory.Simple &&
|
||||
ParseTreeUtils.isMatchingExpression(reference, testExpression.d.leftExpr.d.leftExpr)
|
||||
) {
|
||||
const indexTypeResult = evaluator.getTypeOfExpression(
|
||||
@ -757,11 +757,11 @@ export function getTypeNarrowingCallback(
|
||||
if (
|
||||
isClassInstance(functionReturnType) &&
|
||||
ClassType.isBuiltIn(functionReturnType, ['TypeGuard', 'TypeIs']) &&
|
||||
functionReturnType.priv.typeArguments &&
|
||||
functionReturnType.priv.typeArguments.length > 0
|
||||
functionReturnType.priv.typeArgs &&
|
||||
functionReturnType.priv.typeArgs.length > 0
|
||||
) {
|
||||
const isStrictTypeGuard = ClassType.isBuiltIn(functionReturnType, 'TypeIs');
|
||||
const typeGuardType = functionReturnType.priv.typeArguments[0];
|
||||
const typeGuardType = functionReturnType.priv.typeArgs[0];
|
||||
const isIncomplete = !!callTypeResult.isIncomplete || !!functionReturnTypeResult.isIncomplete;
|
||||
|
||||
return (type: Type) => {
|
||||
@ -1022,16 +1022,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.priv.tupleTypeArguments) {
|
||||
if (!tupleType || isUnboundedTupleClass(tupleType) || !tupleType.priv.tupleTypeArgs) {
|
||||
return subtype;
|
||||
}
|
||||
|
||||
const tupleLength = tupleType.priv.tupleTypeArguments.length;
|
||||
const tupleLength = tupleType.priv.tupleTypeArgs.length;
|
||||
if (indexValue < 0 || indexValue >= tupleLength) {
|
||||
return subtype;
|
||||
}
|
||||
|
||||
const typeOfEntry = evaluator.makeTopLevelTypeVarsConcrete(tupleType.priv.tupleTypeArguments[indexValue].type);
|
||||
const typeOfEntry = evaluator.makeTopLevelTypeVarsConcrete(tupleType.priv.tupleTypeArgs[indexValue].type);
|
||||
|
||||
if (isPositiveTest) {
|
||||
if (!evaluator.assignType(typeOfEntry, evaluator.getNoneType())) {
|
||||
@ -1194,8 +1194,8 @@ function getIsInstanceClassTypes(
|
||||
}
|
||||
|
||||
if (isClass(type) && TypeBase.isInstance(type) && isTupleClass(type)) {
|
||||
if (type.priv.tupleTypeArguments) {
|
||||
type.priv.tupleTypeArguments.forEach((tupleEntry) => {
|
||||
if (type.priv.tupleTypeArgs) {
|
||||
type.priv.tupleTypeArgs.forEach((tupleEntry) => {
|
||||
addClassTypesRecursive(tupleEntry.type, recursionCount + 1);
|
||||
});
|
||||
}
|
||||
@ -1373,12 +1373,12 @@ 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.priv.typeArguments && !concreteFilterType.priv.isTypeArgumentExplicit) {
|
||||
if (concreteFilterType.priv.typeArgs && !concreteFilterType.priv.isTypeArgExplicit) {
|
||||
concreteFilterType = specializeWithUnknownTypeArgs(
|
||||
ClassType.cloneForSpecialization(
|
||||
concreteFilterType,
|
||||
/* typeArguments */ undefined,
|
||||
/* isTypeArgumentExplicit */ false
|
||||
/* typeArgs */ undefined,
|
||||
/* isTypeArgExplicit */ false
|
||||
),
|
||||
evaluator.getTupleClassType()
|
||||
);
|
||||
@ -1458,14 +1458,14 @@ function narrowTypeForIsInstanceInternal(
|
||||
filterType.shared.typeParameters.length > 0
|
||||
) {
|
||||
if (
|
||||
!filterType.priv.isTypeArgumentExplicit &&
|
||||
!filterType.priv.isTypeArgExplicit &&
|
||||
!ClassType.isSameGenericClass(concreteVarType, filterType)
|
||||
) {
|
||||
const typeVarContext = new TypeVarContext(getTypeVarScopeId(filterType));
|
||||
const unspecializedFilterType = ClassType.cloneForSpecialization(
|
||||
filterType,
|
||||
/* typeArguments */ undefined,
|
||||
/* isTypeArgumentExplicit */ false
|
||||
/* typeArg */ undefined,
|
||||
/* isTypeArgExplicit */ false
|
||||
);
|
||||
|
||||
if (
|
||||
@ -1661,7 +1661,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.priv.isTypeArgumentExplicit) {
|
||||
if (ClassType.isBuiltIn(filterMetaclass, 'type') && !filterMetaclass.priv.isTypeArgExplicit) {
|
||||
if (!ClassType.isBuiltIn(metaclassType, 'type')) {
|
||||
isMetaclassOverlap = false;
|
||||
}
|
||||
@ -1919,11 +1919,11 @@ function intersectSameClassType(evaluator: TypeEvaluator, type1: ClassType, type
|
||||
}
|
||||
|
||||
function intersectTupleTypes(type1: ClassType, type2: ClassType) {
|
||||
if (!type2.priv.tupleTypeArguments || isTupleGradualForm(type2)) {
|
||||
if (!type2.priv.tupleTypeArgs || isTupleGradualForm(type2)) {
|
||||
return addConditionToType(type1, type2.props?.condition);
|
||||
}
|
||||
|
||||
if (!type1.priv.tupleTypeArguments || isTupleGradualForm(type1)) {
|
||||
if (!type1.priv.tupleTypeArgs || isTupleGradualForm(type1)) {
|
||||
return addConditionToType(type2, type1.props?.condition);
|
||||
}
|
||||
|
||||
@ -1947,28 +1947,28 @@ function narrowTypeForTupleLength(
|
||||
if (
|
||||
!isClassInstance(concreteSubtype) ||
|
||||
!isTupleClass(concreteSubtype) ||
|
||||
!concreteSubtype.priv.tupleTypeArguments
|
||||
!concreteSubtype.priv.tupleTypeArgs
|
||||
) {
|
||||
return subtype;
|
||||
}
|
||||
|
||||
// If the tuple contains a variadic TypeVar, we can't narrow it.
|
||||
if (concreteSubtype.priv.tupleTypeArguments.some((typeArg) => isUnpackedVariadicTypeVar(typeArg.type))) {
|
||||
if (concreteSubtype.priv.tupleTypeArgs.some((typeArg) => isUnpackedVariadicTypeVar(typeArg.type))) {
|
||||
return subtype;
|
||||
}
|
||||
|
||||
// If the tuple contains no unbounded elements, then we know its length exactly.
|
||||
if (!concreteSubtype.priv.tupleTypeArguments.some((typeArg) => typeArg.isUnbounded)) {
|
||||
if (!concreteSubtype.priv.tupleTypeArgs.some((typeArg) => typeArg.isUnbounded)) {
|
||||
const tupleLengthMatches = isLessThanCheck
|
||||
? concreteSubtype.priv.tupleTypeArguments.length < lengthValue
|
||||
: concreteSubtype.priv.tupleTypeArguments.length === lengthValue;
|
||||
? concreteSubtype.priv.tupleTypeArgs.length < lengthValue
|
||||
: concreteSubtype.priv.tupleTypeArgs.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.priv.tupleTypeArguments.length + 1;
|
||||
const elementsToAdd = lengthValue - concreteSubtype.priv.tupleTypeArgs.length + 1;
|
||||
|
||||
if (!isLessThanCheck) {
|
||||
// If the specified length is smaller than the minimum length of this tuple,
|
||||
@ -2018,9 +2018,9 @@ function narrowTypeForTupleLength(
|
||||
// multiple bounded elements of that same type in place of (or in addition
|
||||
// to) the unbounded element.
|
||||
function expandUnboundedTupleElement(tupleType: ClassType, elementsToAdd: number, keepUnbounded: boolean) {
|
||||
const tupleTypeArgs: TupleTypeArgument[] = [];
|
||||
const tupleTypeArgs: TupleTypeArg[] = [];
|
||||
|
||||
tupleType.priv.tupleTypeArguments!.forEach((typeArg) => {
|
||||
tupleType.priv.tupleTypeArgs!.forEach((typeArg) => {
|
||||
if (!typeArg.isUnbounded) {
|
||||
tupleTypeArgs.push(typeArg);
|
||||
} else {
|
||||
@ -2062,7 +2062,7 @@ function narrowTypeForContainerType(
|
||||
if (
|
||||
!isClassInstance(containerType) ||
|
||||
!ClassType.isBuiltIn(containerType, 'tuple') ||
|
||||
!containerType.priv.tupleTypeArguments
|
||||
!containerType.priv.tupleTypeArgs
|
||||
) {
|
||||
return referenceType;
|
||||
}
|
||||
@ -2070,7 +2070,7 @@ function narrowTypeForContainerType(
|
||||
// Determine which tuple types can be eliminated. Only "None" and
|
||||
// literal types can be handled here.
|
||||
const typesToEliminate: Type[] = [];
|
||||
containerType.priv.tupleTypeArguments.forEach((tupleEntry) => {
|
||||
containerType.priv.tupleTypeArgs.forEach((tupleEntry) => {
|
||||
if (!tupleEntry.isUnbounded) {
|
||||
if (isNoneInstance(tupleEntry.type)) {
|
||||
typesToEliminate.push(tupleEntry.type);
|
||||
@ -2112,13 +2112,13 @@ export function getElementTypeForContainerNarrowing(containerType: Type) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (!containerType.priv.typeArguments || containerType.priv.typeArguments.length < 1) {
|
||||
if (!containerType.priv.typeArgs || containerType.priv.typeArgs.length < 1) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let elementType = containerType.priv.typeArguments[0];
|
||||
if (isTupleClass(containerType) && containerType.priv.tupleTypeArguments) {
|
||||
elementType = combineTypes(containerType.priv.tupleTypeArguments.map((t) => t.type));
|
||||
let elementType = containerType.priv.typeArgs[0];
|
||||
if (isTupleClass(containerType) && containerType.priv.tupleTypeArgs) {
|
||||
elementType = combineTypes(containerType.priv.tupleTypeArgs.map((t) => t.type));
|
||||
}
|
||||
|
||||
return elementType;
|
||||
@ -2330,12 +2330,8 @@ export function narrowTypeForDiscriminatedTupleComparison(
|
||||
isClassInstance(literalType)
|
||||
) {
|
||||
const indexValue = indexLiteralType.priv.literalValue;
|
||||
if (
|
||||
subtype.priv.tupleTypeArguments &&
|
||||
indexValue >= 0 &&
|
||||
indexValue < subtype.priv.tupleTypeArguments.length
|
||||
) {
|
||||
const tupleEntryType = subtype.priv.tupleTypeArguments[indexValue]?.type;
|
||||
if (subtype.priv.tupleTypeArgs && indexValue >= 0 && indexValue < subtype.priv.tupleTypeArgs.length) {
|
||||
const tupleEntryType = subtype.priv.tupleTypeArgs[indexValue]?.type;
|
||||
if (tupleEntryType && isLiteralTypeOrUnion(tupleEntryType)) {
|
||||
if (isPositiveTest) {
|
||||
return evaluator.assignType(tupleEntryType, literalType) ? subtype : undefined;
|
||||
@ -2514,8 +2510,8 @@ function narrowTypeForClassComparison(
|
||||
ClassType.isBuiltIn(concreteSubtype, 'type')
|
||||
) {
|
||||
concreteSubtype =
|
||||
concreteSubtype.priv.typeArguments && concreteSubtype.priv.typeArguments.length > 0
|
||||
? convertToInstantiable(concreteSubtype.priv.typeArguments[0])
|
||||
concreteSubtype.priv.typeArgs && concreteSubtype.priv.typeArgs.length > 0
|
||||
? convertToInstantiable(concreteSubtype.priv.typeArgs[0])
|
||||
: UnknownType.create();
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ import {
|
||||
isVariadicTypeVar,
|
||||
maxTypeRecursionCount,
|
||||
OverloadedFunctionType,
|
||||
TupleTypeArgument,
|
||||
TupleTypeArg,
|
||||
Type,
|
||||
TypeBase,
|
||||
TypeCategory,
|
||||
@ -49,7 +49,7 @@ export const enum PrintTypeFlags {
|
||||
PrintUnknownWithAny = 1 << 0,
|
||||
|
||||
// Omit type arguments for generic classes if they are "Unknown".
|
||||
OmitTypeArgumentsIfUnknown = 1 << 1,
|
||||
OmitTypeArgsIfUnknown = 1 << 1,
|
||||
|
||||
// Omit printing type for param if type is not specified.
|
||||
OmitUnannotatedParamType = 1 << 2,
|
||||
@ -261,13 +261,13 @@ function printTypeInternal(
|
||||
let argumentStrings: string[] | undefined;
|
||||
|
||||
// If there is a type arguments array, it's a specialized type alias.
|
||||
if (aliasInfo.typeArguments) {
|
||||
if (aliasInfo.typeArgs) {
|
||||
if (
|
||||
(printTypeFlags & PrintTypeFlags.OmitTypeArgumentsIfUnknown) === 0 ||
|
||||
aliasInfo.typeArguments.some((typeArg) => !isUnknown(typeArg))
|
||||
(printTypeFlags & PrintTypeFlags.OmitTypeArgsIfUnknown) === 0 ||
|
||||
aliasInfo.typeArgs.some((typeArg) => !isUnknown(typeArg))
|
||||
) {
|
||||
argumentStrings = [];
|
||||
aliasInfo.typeArguments.forEach((typeArg, index) => {
|
||||
aliasInfo.typeArgs.forEach((typeArg, index) => {
|
||||
// Which type parameter does this map to?
|
||||
const typeParam =
|
||||
index < typeParams.length ? typeParams[index] : typeParams[typeParams.length - 1];
|
||||
@ -277,10 +277,10 @@ function printTypeInternal(
|
||||
isVariadicTypeVar(typeParam) &&
|
||||
isClassInstance(typeArg) &&
|
||||
isTupleClass(typeArg) &&
|
||||
typeArg.priv.tupleTypeArguments &&
|
||||
typeArg.priv.tupleTypeArguments.every((typeArg) => !typeArg.isUnbounded)
|
||||
typeArg.priv.tupleTypeArgs &&
|
||||
typeArg.priv.tupleTypeArgs.every((typeArg) => !typeArg.isUnbounded)
|
||||
) {
|
||||
typeArg.priv.tupleTypeArguments.forEach((tupleTypeArg) => {
|
||||
typeArg.priv.tupleTypeArgs.forEach((tupleTypeArg) => {
|
||||
argumentStrings!.push(
|
||||
printTypeInternal(
|
||||
tupleTypeArg.type,
|
||||
@ -308,7 +308,7 @@ function printTypeInternal(
|
||||
}
|
||||
} else {
|
||||
if (
|
||||
(printTypeFlags & PrintTypeFlags.OmitTypeArgumentsIfUnknown) === 0 ||
|
||||
(printTypeFlags & PrintTypeFlags.OmitTypeArgsIfUnknown) === 0 ||
|
||||
typeParams.some((typeParam) => !isUnknown(typeParam))
|
||||
) {
|
||||
argumentStrings = [];
|
||||
@ -937,9 +937,9 @@ function printObjectTypeForClassInternal(
|
||||
const isVariadic = lastTypeParam ? lastTypeParam.shared.isVariadic : false;
|
||||
|
||||
// If there is a type arguments array, it's a specialized class.
|
||||
const typeArgs: TupleTypeArgument[] | undefined =
|
||||
type.priv.tupleTypeArguments ??
|
||||
type.priv.typeArguments?.map((t) => {
|
||||
const typeArgs: TupleTypeArg[] | undefined =
|
||||
type.priv.tupleTypeArgs ??
|
||||
type.priv.typeArgs?.map((t) => {
|
||||
return { type: t, isUnbounded: false };
|
||||
});
|
||||
if (typeArgs) {
|
||||
@ -955,10 +955,10 @@ function printObjectTypeForClassInternal(
|
||||
typeParam.shared.isVariadic &&
|
||||
isClassInstance(typeArg.type) &&
|
||||
ClassType.isBuiltIn(typeArg.type, 'tuple') &&
|
||||
typeArg.type.priv.tupleTypeArguments
|
||||
typeArg.type.priv.tupleTypeArgs
|
||||
) {
|
||||
// Expand the tuple type that maps to the variadic type parameter.
|
||||
if (typeArg.type.priv.tupleTypeArguments.length === 0) {
|
||||
if (typeArg.type.priv.tupleTypeArgs.length === 0) {
|
||||
if (!isUnknown(typeArg.type)) {
|
||||
isAllUnknown = false;
|
||||
}
|
||||
@ -969,7 +969,7 @@ function printObjectTypeForClassInternal(
|
||||
} else {
|
||||
appendArray(
|
||||
typeArgStrings,
|
||||
typeArg.type.priv.tupleTypeArguments.map((typeArg) => {
|
||||
typeArg.type.priv.tupleTypeArgs.map((typeArg) => {
|
||||
if (!isUnknown(typeArg.type)) {
|
||||
isAllUnknown = false;
|
||||
}
|
||||
@ -1021,7 +1021,7 @@ function printObjectTypeForClassInternal(
|
||||
objName = _printUnpack(objName, printTypeFlags);
|
||||
}
|
||||
|
||||
if ((printTypeFlags & PrintTypeFlags.OmitTypeArgumentsIfUnknown) === 0 || !isAllUnknown) {
|
||||
if ((printTypeFlags & PrintTypeFlags.OmitTypeArgsIfUnknown) === 0 || !isAllUnknown) {
|
||||
objName += '[' + typeArgStrings.join(', ') + ']';
|
||||
}
|
||||
} else {
|
||||
@ -1040,7 +1040,7 @@ function printObjectTypeForClassInternal(
|
||||
|
||||
if (typeParams.length > 0) {
|
||||
if (
|
||||
(printTypeFlags & PrintTypeFlags.OmitTypeArgumentsIfUnknown) === 0 ||
|
||||
(printTypeFlags & PrintTypeFlags.OmitTypeArgsIfUnknown) === 0 ||
|
||||
typeParams.some((typeParam) => !isUnknown(typeParam))
|
||||
) {
|
||||
objName +=
|
||||
@ -1102,9 +1102,9 @@ function printFunctionPartsInternal(
|
||||
if (
|
||||
isClassInstance(specializedParamType) &&
|
||||
ClassType.isBuiltIn(specializedParamType, 'tuple') &&
|
||||
specializedParamType.priv.tupleTypeArguments
|
||||
specializedParamType.priv.tupleTypeArgs
|
||||
) {
|
||||
specializedParamType.priv.tupleTypeArguments.forEach((paramType) => {
|
||||
specializedParamType.priv.tupleTypeArgs.forEach((paramType) => {
|
||||
const paramString = printTypeInternal(
|
||||
paramType.type,
|
||||
printTypeFlags,
|
||||
@ -1208,7 +1208,7 @@ function printFunctionPartsInternal(
|
||||
// PEP8 indicates that the "=" for the default value should have surrounding
|
||||
// spaces when used with a type annotation.
|
||||
defaultValueAssignment = ' = ';
|
||||
} else if ((printTypeFlags & PrintTypeFlags.OmitTypeArgumentsIfUnknown) === 0) {
|
||||
} else if ((printTypeFlags & PrintTypeFlags.OmitTypeArgsIfUnknown) === 0) {
|
||||
if (!FunctionParam.isNameSynthesized(param)) {
|
||||
paramString += ': ';
|
||||
}
|
||||
@ -1359,11 +1359,11 @@ class UniqueNameMap {
|
||||
this._addIfUnique(typeAliasName, type, /* useTypeAliasName */ true);
|
||||
|
||||
// Recursively add the type arguments if present.
|
||||
if (aliasInfo.typeArguments) {
|
||||
if (aliasInfo.typeArgs) {
|
||||
recursionTypes.push(type);
|
||||
|
||||
try {
|
||||
aliasInfo.typeArguments.forEach((typeArg) => {
|
||||
aliasInfo.typeArgs.forEach((typeArg) => {
|
||||
this.build(typeArg, recursionTypes, recursionCount);
|
||||
});
|
||||
} finally {
|
||||
@ -1413,12 +1413,12 @@ class UniqueNameMap {
|
||||
this._addIfUnique(className, type);
|
||||
|
||||
if (!ClassType.isPseudoGenericClass(type)) {
|
||||
if (type.priv.tupleTypeArguments) {
|
||||
type.priv.tupleTypeArguments.forEach((typeArg) => {
|
||||
if (type.priv.tupleTypeArgs) {
|
||||
type.priv.tupleTypeArgs.forEach((typeArg) => {
|
||||
this.build(typeArg.type, recursionTypes, recursionCount);
|
||||
});
|
||||
} else if (type.priv.typeArguments) {
|
||||
type.priv.typeArguments.forEach((typeArg) => {
|
||||
} else if (type.priv.typeArgs) {
|
||||
type.priv.typeArgs.forEach((typeArg) => {
|
||||
this.build(typeArg, recursionTypes, recursionCount);
|
||||
});
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
import { Uri } from '../common/uri/uri';
|
||||
import {
|
||||
ArgumentCategory,
|
||||
ArgCategory,
|
||||
AssignmentNode,
|
||||
AugmentedAssignmentNode,
|
||||
ClassNode,
|
||||
@ -202,7 +202,7 @@ export class TypeStubWriter extends ParseTreeWalker {
|
||||
const args = node.d.arguments.filter(
|
||||
(arg) =>
|
||||
arg.d.name !== undefined ||
|
||||
arg.d.argCategory !== ArgumentCategory.Simple ||
|
||||
arg.d.argCategory !== ArgCategory.Simple ||
|
||||
arg.d.valueExpr.nodeType !== ParseNodeType.Name ||
|
||||
arg.d.valueExpr.d.value !== 'object'
|
||||
);
|
||||
|
@ -13,7 +13,7 @@ import { ArgumentNode, ParameterCategory } from '../parser/parseNodes';
|
||||
import { DeclarationType } from './declaration';
|
||||
import { Symbol, SymbolFlags, SymbolTable } from './symbol';
|
||||
import { isEffectivelyClassVar, isTypedDictMemberAccessedThroughIndex } from './symbolUtils';
|
||||
import { FunctionArgumentWithExpression } from './typeEvaluatorTypes';
|
||||
import { ArgWithExpression } from './typeEvaluatorTypes';
|
||||
import {
|
||||
AnyType,
|
||||
ClassType,
|
||||
@ -51,7 +51,7 @@ import {
|
||||
removeFromUnion,
|
||||
SignatureWithOffsets,
|
||||
SpecializedFunctionTypes,
|
||||
TupleTypeArgument,
|
||||
TupleTypeArg,
|
||||
Type,
|
||||
TypeBase,
|
||||
TypeCategory,
|
||||
@ -232,7 +232,7 @@ export const enum AssignTypeFlags {
|
||||
// hasn't previously been specialized, it will be specialized with
|
||||
// default type arguments (typically "Unknown"). This flag skips
|
||||
// this step.
|
||||
AllowUnspecifiedTypeArguments = 1 << 13,
|
||||
AllowUnspecifiedTypeArgs = 1 << 13,
|
||||
|
||||
// Normally all special form classes are incompatible with type[T],
|
||||
// but a few of them are allowed in the context of an isinstance
|
||||
@ -269,7 +269,7 @@ export interface RequiresSpecializationOptions {
|
||||
// Ignore Self type?
|
||||
ignoreSelf?: boolean;
|
||||
|
||||
// Ignore classes whose isTypeArgumentExplicit flag is false?
|
||||
// Ignore classes whose isTypeArgExplicit flag is false?
|
||||
ignoreImplicitTypeArgs?: boolean;
|
||||
}
|
||||
|
||||
@ -575,12 +575,11 @@ export function cleanIncompleteUnknown(type: Type, recursionCount = 0): Type {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (isClass(subtype) && subtype.priv.typeArguments) {
|
||||
if (isClass(subtype) && subtype.priv.typeArgs) {
|
||||
let typeChanged = false;
|
||||
|
||||
if (subtype.priv.tupleTypeArguments) {
|
||||
const updatedTupleTypeArgs: TupleTypeArgument[] = subtype.priv.tupleTypeArguments.map(
|
||||
(tupleTypeArg) => {
|
||||
if (subtype.priv.tupleTypeArgs) {
|
||||
const updatedTupleTypeArgs: TupleTypeArg[] = subtype.priv.tupleTypeArgs.map((tupleTypeArg) => {
|
||||
const newTypeArg = cleanIncompleteUnknown(tupleTypeArg.type, recursionCount);
|
||||
if (newTypeArg !== tupleTypeArg.type) {
|
||||
typeChanged = true;
|
||||
@ -590,19 +589,18 @@ export function cleanIncompleteUnknown(type: Type, recursionCount = 0): Type {
|
||||
isUnbounded: tupleTypeArg.isUnbounded,
|
||||
isOptional: tupleTypeArg.isOptional,
|
||||
};
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
if (typeChanged) {
|
||||
return specializeTupleClass(
|
||||
subtype,
|
||||
updatedTupleTypeArgs,
|
||||
!!subtype.priv.isTypeArgumentExplicit,
|
||||
!!subtype.priv.isTypeArgExplicit,
|
||||
!!subtype.priv.isUnpacked
|
||||
);
|
||||
}
|
||||
} else {
|
||||
const updatedTypeArgs = subtype.priv.typeArguments.map((typeArg) => {
|
||||
const updatedTypeArgs = subtype.priv.typeArgs.map((typeArg) => {
|
||||
const newTypeArg = cleanIncompleteUnknown(typeArg, recursionCount);
|
||||
if (newTypeArg !== typeArg) {
|
||||
typeChanged = true;
|
||||
@ -611,11 +609,7 @@ export function cleanIncompleteUnknown(type: Type, recursionCount = 0): Type {
|
||||
});
|
||||
|
||||
if (typeChanged) {
|
||||
return ClassType.cloneForSpecialization(
|
||||
subtype,
|
||||
updatedTypeArgs,
|
||||
!!subtype.priv.isTypeArgumentExplicit
|
||||
);
|
||||
return ClassType.cloneForSpecialization(subtype, updatedTypeArgs, !!subtype.priv.isTypeArgExplicit);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -767,8 +761,8 @@ function compareTypes(a: Type, b: Type, recursionCount = 0): number {
|
||||
}
|
||||
|
||||
// Sort by type argument count.
|
||||
const aTypeArgCount = a.priv.typeArguments ? a.priv.typeArguments.length : 0;
|
||||
const bTypeArgCount = bClass.priv.typeArguments ? bClass.priv.typeArguments.length : 0;
|
||||
const aTypeArgCount = a.priv.typeArgs ? a.priv.typeArgs.length : 0;
|
||||
const bTypeArgCount = bClass.priv.typeArgs ? bClass.priv.typeArgs.length : 0;
|
||||
|
||||
if (aTypeArgCount < bTypeArgCount) {
|
||||
return -1;
|
||||
@ -778,11 +772,7 @@ function compareTypes(a: Type, b: Type, recursionCount = 0): number {
|
||||
|
||||
// Sort by type argument.
|
||||
for (let i = 0; i < aTypeArgCount; i++) {
|
||||
const typeComparison = compareTypes(
|
||||
a.priv.typeArguments![i],
|
||||
bClass.priv.typeArguments![i],
|
||||
recursionCount
|
||||
);
|
||||
const typeComparison = compareTypes(a.priv.typeArgs![i], bClass.priv.typeArgs![i], recursionCount);
|
||||
if (typeComparison !== 0) {
|
||||
return typeComparison;
|
||||
}
|
||||
@ -1045,13 +1035,13 @@ export function transformPossibleRecursiveTypeAlias(type: Type | undefined): Typ
|
||||
? convertToInstance(type.shared.boundType)
|
||||
: type.shared.boundType;
|
||||
|
||||
if (!aliasInfo?.typeArguments || !type.shared.recursiveAlias.typeParameters) {
|
||||
if (!aliasInfo?.typeArgs || !type.shared.recursiveAlias.typeParameters) {
|
||||
return unspecializedType;
|
||||
}
|
||||
|
||||
const typeVarContext = buildTypeVarContext(
|
||||
type.shared.recursiveAlias.typeParameters,
|
||||
aliasInfo.typeArguments,
|
||||
aliasInfo.typeArgs,
|
||||
getTypeVarScopeId(type)
|
||||
);
|
||||
return applySolvedTypeVars(unspecializedType, typeVarContext);
|
||||
@ -1071,7 +1061,7 @@ export function transformPossibleRecursiveTypeAlias(type: Type | undefined): Typ
|
||||
aliasInfo.typeVarScopeId,
|
||||
aliasInfo.isPep695Syntax,
|
||||
aliasInfo.typeParameters,
|
||||
aliasInfo.typeArguments
|
||||
aliasInfo.typeArgs
|
||||
);
|
||||
}
|
||||
|
||||
@ -1125,14 +1115,14 @@ export function getTypeVarScopeIds(type: Type): TypeVarScopeId[] | undefined {
|
||||
// specified, specialize it with default type arguments (Unknown or the
|
||||
// default type if provided).
|
||||
export function specializeWithDefaultTypeArgs(type: ClassType): ClassType {
|
||||
if (type.shared.typeParameters.length === 0 || type.priv.typeArguments) {
|
||||
if (type.shared.typeParameters.length === 0 || type.priv.typeArgs) {
|
||||
return type;
|
||||
}
|
||||
|
||||
return ClassType.cloneForSpecialization(
|
||||
type,
|
||||
type.shared.typeParameters.map((param) => param.shared.defaultType),
|
||||
/* isTypeArgumentExplicit */ false,
|
||||
/* isTypeArgExplicit */ false,
|
||||
/* includeSubclasses */ type.priv.includeSubclasses
|
||||
);
|
||||
}
|
||||
@ -1149,7 +1139,7 @@ export function specializeWithUnknownTypeArgs(type: ClassType, tupleClassType?:
|
||||
specializeTupleClass(
|
||||
type,
|
||||
[{ type: UnknownType.create(), isUnbounded: true }],
|
||||
/* isTypeArgumentExplicit */ false
|
||||
/* isTypeArgExplicit */ false
|
||||
),
|
||||
!!type.priv.includeSubclasses
|
||||
);
|
||||
@ -1158,7 +1148,7 @@ export function specializeWithUnknownTypeArgs(type: ClassType, tupleClassType?:
|
||||
return ClassType.cloneForSpecialization(
|
||||
type,
|
||||
type.shared.typeParameters.map((param) => getUnknownTypeForTypeVar(param, tupleClassType)),
|
||||
/* isTypeArgumentExplicit */ false,
|
||||
/* isTypeArgExplicit */ false,
|
||||
/* includeSubclasses */ type.priv.includeSubclasses
|
||||
);
|
||||
}
|
||||
@ -1195,7 +1185,7 @@ export function getUnknownTypeForVariadicTypeVar(tupleClassType: ClassType): Typ
|
||||
specializeTupleClass(
|
||||
tupleClassType,
|
||||
[{ type: UnknownType.create(), isUnbounded: true }],
|
||||
/* isTypeArgumentExplicit */ true,
|
||||
/* isTypeArgExplicit */ true,
|
||||
/* isUnpackedTuple */ true
|
||||
)
|
||||
);
|
||||
@ -1217,14 +1207,14 @@ export function selfSpecializeClass(type: ClassType, options?: SelfSpecializeOpt
|
||||
return type;
|
||||
}
|
||||
|
||||
if (type.priv.typeArguments && !options?.overrideTypeArgs) {
|
||||
if (type.priv.typeArgs && !options?.overrideTypeArgs) {
|
||||
return type;
|
||||
}
|
||||
|
||||
const typeParams = type.shared.typeParameters.map((typeParam) => {
|
||||
return options?.useInternalTypeVars ? TypeVarType.cloneWithInternalScopeId(typeParam) : typeParam;
|
||||
});
|
||||
return ClassType.cloneForSpecialization(type, typeParams, /* isTypeArgumentExplicit */ true);
|
||||
return ClassType.cloneForSpecialization(type, typeParams, /* isTypeArgExplicit */ true);
|
||||
}
|
||||
|
||||
// Determines whether the type derives from tuple. If so, it returns
|
||||
@ -1418,10 +1408,10 @@ export function isTupleGradualForm(type: Type) {
|
||||
return (
|
||||
isClassInstance(type) &&
|
||||
isTupleClass(type) &&
|
||||
type.priv.tupleTypeArguments &&
|
||||
type.priv.tupleTypeArguments.length === 1 &&
|
||||
isAnyOrUnknown(type.priv.tupleTypeArguments[0].type) &&
|
||||
type.priv.tupleTypeArguments[0].isUnbounded
|
||||
type.priv.tupleTypeArgs &&
|
||||
type.priv.tupleTypeArgs.length === 1 &&
|
||||
isAnyOrUnknown(type.priv.tupleTypeArgs[0].type) &&
|
||||
type.priv.tupleTypeArgs[0].isUnbounded
|
||||
);
|
||||
}
|
||||
|
||||
@ -1434,29 +1424,27 @@ export function isTupleClass(type: ClassType) {
|
||||
// in the tuple is unknown.
|
||||
export function isUnboundedTupleClass(type: ClassType) {
|
||||
return (
|
||||
type.priv.tupleTypeArguments &&
|
||||
type.priv.tupleTypeArguments.some((t) => t.isUnbounded || isUnpackedVariadicTypeVar(t.type))
|
||||
type.priv.tupleTypeArgs &&
|
||||
type.priv.tupleTypeArgs.some((t) => t.isUnbounded || isUnpackedVariadicTypeVar(t.type))
|
||||
);
|
||||
}
|
||||
|
||||
// Indicates whether the specified index is within range and its type is unambiguous
|
||||
// in that it doesn't involve any element ranges that are of indeterminate length.
|
||||
export function isTupleIndexUnambiguous(type: ClassType, index: number) {
|
||||
if (!type.priv.tupleTypeArguments) {
|
||||
if (!type.priv.tupleTypeArgs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const unboundedIndex = type.priv.tupleTypeArguments.findIndex(
|
||||
(t) => t.isUnbounded || isUnpackedVariadicTypeVar(t.type)
|
||||
);
|
||||
const unboundedIndex = type.priv.tupleTypeArgs.findIndex((t) => t.isUnbounded || isUnpackedVariadicTypeVar(t.type));
|
||||
|
||||
if (index < 0) {
|
||||
const lowerIndexLimit = unboundedIndex < 0 ? 0 : unboundedIndex;
|
||||
index += type.priv.tupleTypeArguments.length;
|
||||
index += type.priv.tupleTypeArgs.length;
|
||||
return index >= lowerIndexLimit;
|
||||
}
|
||||
|
||||
const upperIndexLimit = unboundedIndex < 0 ? type.priv.tupleTypeArguments.length : unboundedIndex;
|
||||
const upperIndexLimit = unboundedIndex < 0 ? type.priv.tupleTypeArgs.length : unboundedIndex;
|
||||
return index < upperIndexLimit;
|
||||
}
|
||||
|
||||
@ -1737,15 +1725,15 @@ export function getContainerDepth(type: Type, recursionCount = 0) {
|
||||
|
||||
let maxChildDepth = 0;
|
||||
|
||||
if (type.priv.tupleTypeArguments) {
|
||||
type.priv.tupleTypeArguments.forEach((typeArgInfo) => {
|
||||
if (type.priv.tupleTypeArgs) {
|
||||
type.priv.tupleTypeArgs.forEach((typeArgInfo) => {
|
||||
doForEachSubtype(typeArgInfo.type, (subtype) => {
|
||||
const childDepth = getContainerDepth(subtype, recursionCount);
|
||||
maxChildDepth = Math.max(childDepth, maxChildDepth);
|
||||
});
|
||||
});
|
||||
} else if (type.priv.typeArguments) {
|
||||
type.priv.typeArguments.forEach((typeArg) => {
|
||||
} else if (type.priv.typeArgs) {
|
||||
type.priv.typeArgs.forEach((typeArg) => {
|
||||
doForEachSubtype(typeArg, (subtype) => {
|
||||
const childDepth = getContainerDepth(subtype, recursionCount);
|
||||
maxChildDepth = Math.max(childDepth, maxChildDepth);
|
||||
@ -2053,18 +2041,18 @@ export function addTypeVarsToListIfUnique(list1: TypeVarType[], list2: TypeVarTy
|
||||
// of unique type variables. For example, if the type is
|
||||
// Union[List[Dict[_T1, _T2]], _T1, _T3], the result would be
|
||||
// [_T1, _T2, _T3].
|
||||
export function getTypeVarArgumentsRecursive(type: Type, recursionCount = 0): TypeVarType[] {
|
||||
export function getTypeVarArgsRecursive(type: Type, recursionCount = 0): TypeVarType[] {
|
||||
if (recursionCount > maxTypeRecursionCount) {
|
||||
return [];
|
||||
}
|
||||
recursionCount++;
|
||||
|
||||
const aliasInfo = type.props?.typeAliasInfo;
|
||||
if (aliasInfo?.typeArguments) {
|
||||
if (aliasInfo?.typeArgs) {
|
||||
const combinedList: TypeVarType[] = [];
|
||||
|
||||
aliasInfo?.typeArguments.forEach((typeArg) => {
|
||||
addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(typeArg, recursionCount));
|
||||
aliasInfo?.typeArgs.forEach((typeArg) => {
|
||||
addTypeVarsToListIfUnique(combinedList, getTypeVarArgsRecursive(typeArg, recursionCount));
|
||||
});
|
||||
|
||||
return combinedList;
|
||||
@ -2086,12 +2074,10 @@ export function getTypeVarArgumentsRecursive(type: Type, recursionCount = 0): Ty
|
||||
|
||||
if (isClass(type)) {
|
||||
const combinedList: TypeVarType[] = [];
|
||||
const typeArgs = type.priv.tupleTypeArguments
|
||||
? type.priv.tupleTypeArguments.map((e) => e.type)
|
||||
: type.priv.typeArguments;
|
||||
const typeArgs = type.priv.tupleTypeArgs ? type.priv.tupleTypeArgs.map((e) => e.type) : type.priv.typeArgs;
|
||||
if (typeArgs) {
|
||||
typeArgs.forEach((typeArg) => {
|
||||
addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(typeArg, recursionCount));
|
||||
addTypeVarsToListIfUnique(combinedList, getTypeVarArgsRecursive(typeArg, recursionCount));
|
||||
});
|
||||
}
|
||||
|
||||
@ -2101,7 +2087,7 @@ export function getTypeVarArgumentsRecursive(type: Type, recursionCount = 0): Ty
|
||||
if (isUnion(type)) {
|
||||
const combinedList: TypeVarType[] = [];
|
||||
doForEachSubtype(type, (subtype) => {
|
||||
addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(subtype, recursionCount));
|
||||
addTypeVarsToListIfUnique(combinedList, getTypeVarArgsRecursive(subtype, recursionCount));
|
||||
});
|
||||
return combinedList;
|
||||
}
|
||||
@ -2112,13 +2098,13 @@ export function getTypeVarArgumentsRecursive(type: Type, recursionCount = 0): Ty
|
||||
for (let i = 0; i < type.shared.parameters.length; i++) {
|
||||
addTypeVarsToListIfUnique(
|
||||
combinedList,
|
||||
getTypeVarArgumentsRecursive(FunctionType.getEffectiveParameterType(type, i), recursionCount)
|
||||
getTypeVarArgsRecursive(FunctionType.getEffectiveParameterType(type, i), recursionCount)
|
||||
);
|
||||
}
|
||||
|
||||
const returnType = FunctionType.getEffectiveReturnType(type);
|
||||
if (returnType) {
|
||||
addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(returnType, recursionCount));
|
||||
addTypeVarsToListIfUnique(combinedList, getTypeVarArgsRecursive(returnType, recursionCount));
|
||||
}
|
||||
|
||||
return combinedList;
|
||||
@ -2142,7 +2128,7 @@ export function specializeClassType(type: ClassType): ClassType {
|
||||
|
||||
// Recursively finds all of the type arguments and sets them
|
||||
// to the specified srcType.
|
||||
export function setTypeArgumentsRecursive(
|
||||
export function setTypeArgsRecursive(
|
||||
destType: Type,
|
||||
srcType: UnknownType | AnyType,
|
||||
typeVarContext: TypeVarContext,
|
||||
@ -2160,19 +2146,19 @@ export function setTypeArgumentsRecursive(
|
||||
switch (destType.category) {
|
||||
case TypeCategory.Union:
|
||||
doForEachSubtype(destType, (subtype) => {
|
||||
setTypeArgumentsRecursive(subtype, srcType, typeVarContext, recursionCount);
|
||||
setTypeArgsRecursive(subtype, srcType, typeVarContext, recursionCount);
|
||||
});
|
||||
break;
|
||||
|
||||
case TypeCategory.Class:
|
||||
if (destType.priv.typeArguments) {
|
||||
destType.priv.typeArguments.forEach((typeArg) => {
|
||||
setTypeArgumentsRecursive(typeArg, srcType, typeVarContext, recursionCount);
|
||||
if (destType.priv.typeArgs) {
|
||||
destType.priv.typeArgs.forEach((typeArg) => {
|
||||
setTypeArgsRecursive(typeArg, srcType, typeVarContext, recursionCount);
|
||||
});
|
||||
}
|
||||
if (destType.priv.tupleTypeArguments) {
|
||||
destType.priv.tupleTypeArguments.forEach((typeArg) => {
|
||||
setTypeArgumentsRecursive(typeArg.type, srcType, typeVarContext, recursionCount);
|
||||
if (destType.priv.tupleTypeArgs) {
|
||||
destType.priv.tupleTypeArgs.forEach((typeArg) => {
|
||||
setTypeArgsRecursive(typeArg.type, srcType, typeVarContext, recursionCount);
|
||||
});
|
||||
}
|
||||
break;
|
||||
@ -2180,10 +2166,10 @@ export function setTypeArgumentsRecursive(
|
||||
case TypeCategory.Function:
|
||||
if (destType.priv.specializedTypes) {
|
||||
destType.priv.specializedTypes.parameterTypes.forEach((paramType) => {
|
||||
setTypeArgumentsRecursive(paramType, srcType, typeVarContext, recursionCount);
|
||||
setTypeArgsRecursive(paramType, srcType, typeVarContext, recursionCount);
|
||||
});
|
||||
if (destType.priv.specializedTypes.returnType) {
|
||||
setTypeArgumentsRecursive(
|
||||
setTypeArgsRecursive(
|
||||
destType.priv.specializedTypes.returnType,
|
||||
srcType,
|
||||
typeVarContext,
|
||||
@ -2192,22 +2178,17 @@ export function setTypeArgumentsRecursive(
|
||||
}
|
||||
} else {
|
||||
destType.shared.parameters.forEach((param) => {
|
||||
setTypeArgumentsRecursive(param.type, srcType, typeVarContext, recursionCount);
|
||||
setTypeArgsRecursive(param.type, srcType, typeVarContext, recursionCount);
|
||||
});
|
||||
if (destType.shared.declaredReturnType) {
|
||||
setTypeArgumentsRecursive(
|
||||
destType.shared.declaredReturnType,
|
||||
srcType,
|
||||
typeVarContext,
|
||||
recursionCount
|
||||
);
|
||||
setTypeArgsRecursive(destType.shared.declaredReturnType, srcType, typeVarContext, recursionCount);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case TypeCategory.OverloadedFunction:
|
||||
destType.priv.overloads.forEach((subtype) => {
|
||||
setTypeArgumentsRecursive(subtype, srcType, typeVarContext, recursionCount);
|
||||
setTypeArgsRecursive(subtype, srcType, typeVarContext, recursionCount);
|
||||
});
|
||||
break;
|
||||
|
||||
@ -2227,19 +2208,19 @@ export function buildTypeVarContextFromSpecializedClass(classType: ClassType): T
|
||||
const typeParameters = ClassType.getTypeParameters(classType);
|
||||
let typeArgs: Type[] | undefined;
|
||||
|
||||
if (classType.priv.tupleTypeArguments) {
|
||||
if (classType.priv.tupleTypeArgs) {
|
||||
typeArgs = [
|
||||
convertToInstance(
|
||||
specializeTupleClass(
|
||||
classType,
|
||||
classType.priv.tupleTypeArguments,
|
||||
classType.priv.isTypeArgumentExplicit,
|
||||
classType.priv.tupleTypeArgs,
|
||||
classType.priv.isTypeArgExplicit,
|
||||
/* isUnpackedTuple */ true
|
||||
)
|
||||
),
|
||||
];
|
||||
} else {
|
||||
typeArgs = classType.priv.typeArguments;
|
||||
typeArgs = classType.priv.typeArgs;
|
||||
}
|
||||
|
||||
return buildTypeVarContext(typeParameters, typeArgs, getTypeVarScopeId(classType));
|
||||
@ -2350,8 +2331,8 @@ export function synthesizeTypeVarForSelfCls(classType: ClassType, isClsParam: bo
|
||||
|
||||
const boundType = ClassType.cloneForSpecialization(
|
||||
classType,
|
||||
/* typeArguments */ undefined,
|
||||
/* isTypeArgumentExplicit */ false,
|
||||
/* typeArgs */ undefined,
|
||||
/* isTypeArgExplicit */ false,
|
||||
/* includeSubclasses */ !!classType.priv.includeSubclasses
|
||||
);
|
||||
|
||||
@ -2396,8 +2377,8 @@ export function getGeneratorYieldType(declaredReturnType: Type, isAsync: boolean
|
||||
];
|
||||
|
||||
if (expectedClasses.some((classes) => ClassType.isBuiltIn(subtype, isAsync ? classes[0] : classes[1]))) {
|
||||
return subtype.priv.typeArguments && subtype.priv.typeArguments.length >= 1
|
||||
? subtype.priv.typeArguments[0]
|
||||
return subtype.priv.typeArgs && subtype.priv.typeArgs.length >= 1
|
||||
? subtype.priv.typeArgs[0]
|
||||
: UnknownType.create();
|
||||
}
|
||||
}
|
||||
@ -2470,15 +2451,15 @@ export function convertToInstance(type: Type, includeSubclasses = true): Type {
|
||||
// Handle type[x] as a special case.
|
||||
if (ClassType.isBuiltIn(subtype, 'type')) {
|
||||
if (TypeBase.isInstance(subtype)) {
|
||||
if (!subtype.priv.typeArguments || subtype.priv.typeArguments.length < 1) {
|
||||
if (!subtype.priv.typeArgs || subtype.priv.typeArgs.length < 1) {
|
||||
return UnknownType.create();
|
||||
} else {
|
||||
return subtype.priv.typeArguments[0];
|
||||
return subtype.priv.typeArgs[0];
|
||||
}
|
||||
} else {
|
||||
if (subtype.priv.typeArguments && subtype.priv.typeArguments.length > 0) {
|
||||
if (!isAnyOrUnknown(subtype.priv.typeArguments[0])) {
|
||||
return convertToInstantiable(subtype.priv.typeArguments[0]);
|
||||
if (subtype.priv.typeArgs && subtype.priv.typeArgs.length > 0) {
|
||||
if (!isAnyOrUnknown(subtype.priv.typeArgs[0])) {
|
||||
return convertToInstantiable(subtype.priv.typeArgs[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2537,7 +2518,7 @@ export function convertToInstance(type: Type, includeSubclasses = true): Type {
|
||||
aliasInfo.typeVarScopeId,
|
||||
aliasInfo.isPep695Syntax,
|
||||
aliasInfo.typeParameters,
|
||||
aliasInfo.typeArguments
|
||||
aliasInfo.typeArgs
|
||||
);
|
||||
}
|
||||
|
||||
@ -2745,8 +2726,8 @@ export function isPartlyUnknown(type: Type, recursionCount = 0): boolean {
|
||||
// If this is a generic type alias, see if any of its type arguments
|
||||
// are either unspecified or are partially known.
|
||||
const aliasInfo = type.props?.typeAliasInfo;
|
||||
if (aliasInfo?.typeArguments) {
|
||||
if (aliasInfo.typeArguments.some((typeArg) => isPartlyUnknown(typeArg, recursionCount))) {
|
||||
if (aliasInfo?.typeArgs) {
|
||||
if (aliasInfo.typeArgs.some((typeArg) => isPartlyUnknown(typeArg, recursionCount))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -2766,7 +2747,7 @@ export function isPartlyUnknown(type: Type, recursionCount = 0): boolean {
|
||||
}
|
||||
|
||||
if (!ClassType.isPseudoGenericClass(type)) {
|
||||
const typeArgs = type.priv.tupleTypeArguments?.map((t) => t.type) || type.priv.typeArguments;
|
||||
const typeArgs = type.priv.tupleTypeArgs?.map((t) => t.type) || type.priv.typeArgs;
|
||||
if (typeArgs) {
|
||||
for (const argType of typeArgs) {
|
||||
if (isPartlyUnknown(argType, recursionCount)) {
|
||||
@ -2815,17 +2796,13 @@ export function isPartlyUnknown(type: Type, recursionCount = 0): boolean {
|
||||
// that is a union, it "explodes" the class into a union of classes with
|
||||
// each element of the union - e.g. Foo[A | B] becomes Foo[A] | Foo[B].
|
||||
export function explodeGenericClass(classType: ClassType) {
|
||||
if (
|
||||
!classType.priv.typeArguments ||
|
||||
classType.priv.typeArguments.length !== 1 ||
|
||||
!isUnion(classType.priv.typeArguments[0])
|
||||
) {
|
||||
if (!classType.priv.typeArgs || classType.priv.typeArgs.length !== 1 || !isUnion(classType.priv.typeArgs[0])) {
|
||||
return classType;
|
||||
}
|
||||
|
||||
return combineTypes(
|
||||
classType.priv.typeArguments[0].priv.subtypes.map((subtype) => {
|
||||
return ClassType.cloneForSpecialization(classType, [subtype], /* isTypeArgumentExplicit */ true);
|
||||
classType.priv.typeArgs[0].priv.subtypes.map((subtype) => {
|
||||
return ClassType.cloneForSpecialization(classType, [subtype], /* isTypeArgExplicit */ true);
|
||||
})
|
||||
);
|
||||
}
|
||||
@ -2855,17 +2832,17 @@ export function combineSameSizedTuples(type: Type, tupleType: Type | undefined):
|
||||
) as ClassType | undefined;
|
||||
}
|
||||
|
||||
if (tupleClass && isClass(tupleClass) && tupleClass.priv.tupleTypeArguments) {
|
||||
if (tupleClass && isClass(tupleClass) && tupleClass.priv.tupleTypeArgs) {
|
||||
if (tupleEntries) {
|
||||
if (tupleEntries.length === tupleClass.priv.tupleTypeArguments.length) {
|
||||
tupleClass.priv.tupleTypeArguments.forEach((entry, index) => {
|
||||
if (tupleEntries.length === tupleClass.priv.tupleTypeArgs.length) {
|
||||
tupleClass.priv.tupleTypeArgs.forEach((entry, index) => {
|
||||
tupleEntries![index].push(entry.type);
|
||||
});
|
||||
} else {
|
||||
isValid = false;
|
||||
}
|
||||
} else {
|
||||
tupleEntries = tupleClass.priv.tupleTypeArguments.map((entry) => [entry.type]);
|
||||
tupleEntries = tupleClass.priv.tupleTypeArgs.map((entry) => [entry.type]);
|
||||
}
|
||||
} else {
|
||||
isValid = false;
|
||||
@ -2889,7 +2866,7 @@ export function combineSameSizedTuples(type: Type, tupleType: Type | undefined):
|
||||
);
|
||||
}
|
||||
|
||||
export function combineTupleTypeArgs(typeArgs: TupleTypeArgument[]): Type {
|
||||
export function combineTupleTypeArgs(typeArgs: TupleTypeArg[]): Type {
|
||||
return combineTypes(
|
||||
typeArgs.map((t) => {
|
||||
if (isTypeVar(t.type) && isUnpackedVariadicTypeVar(t.type)) {
|
||||
@ -2907,14 +2884,14 @@ export function combineTupleTypeArgs(typeArgs: TupleTypeArgument[]): Type {
|
||||
// arguments.
|
||||
export function specializeTupleClass(
|
||||
classType: ClassType,
|
||||
typeArgs: TupleTypeArgument[],
|
||||
isTypeArgumentExplicit = true,
|
||||
typeArgs: TupleTypeArg[],
|
||||
isTypeArgExplicit = true,
|
||||
isUnpackedTuple = false
|
||||
): ClassType {
|
||||
const clonedClassType = ClassType.cloneForSpecialization(
|
||||
classType,
|
||||
[combineTupleTypeArgs(typeArgs)],
|
||||
isTypeArgumentExplicit,
|
||||
isTypeArgExplicit,
|
||||
/* includeSubclasses */ undefined,
|
||||
typeArgs
|
||||
);
|
||||
@ -2927,8 +2904,8 @@ export function specializeTupleClass(
|
||||
}
|
||||
|
||||
function _expandVariadicUnpackedUnion(type: Type) {
|
||||
if (isClassInstance(type) && isTupleClass(type) && type.priv.tupleTypeArguments && type.priv.isUnpacked) {
|
||||
return combineTypes(type.priv.tupleTypeArguments.map((t) => t.type));
|
||||
if (isClassInstance(type) && isTupleClass(type) && type.priv.tupleTypeArgs && type.priv.isUnpacked) {
|
||||
return combineTypes(type.priv.tupleTypeArgs.map((t) => t.type));
|
||||
}
|
||||
|
||||
return type;
|
||||
@ -2939,18 +2916,18 @@ function _expandVariadicUnpackedUnion(type: Type) {
|
||||
export function getGeneratorTypeArgs(returnType: Type): Type[] | undefined {
|
||||
if (isClassInstance(returnType)) {
|
||||
if (ClassType.isBuiltIn(returnType, ['Generator', 'AsyncGenerator'])) {
|
||||
return returnType.priv.typeArguments;
|
||||
return returnType.priv.typeArgs;
|
||||
} else if (ClassType.isBuiltIn(returnType, 'AwaitableGenerator')) {
|
||||
// AwaitableGenerator has four type arguments, and the first 3
|
||||
// correspond to the generator.
|
||||
return returnType.priv.typeArguments?.slice(0, 3);
|
||||
return returnType.priv.typeArgs?.slice(0, 3);
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function requiresTypeArguments(classType: ClassType) {
|
||||
export function requiresTypeArgs(classType: ClassType) {
|
||||
if (classType.shared.typeParameters.length > 0) {
|
||||
const firstTypeParam = classType.shared.typeParameters[0];
|
||||
|
||||
@ -3034,14 +3011,12 @@ function _requiresSpecialization(type: Type, options?: RequiresSpecializationOpt
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!type.priv.isTypeArgumentExplicit && options?.ignoreImplicitTypeArgs) {
|
||||
if (!type.priv.isTypeArgExplicit && options?.ignoreImplicitTypeArgs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type.priv.typeArguments) {
|
||||
return type.priv.typeArguments.some((typeArg) =>
|
||||
requiresSpecialization(typeArg, options, recursionCount)
|
||||
);
|
||||
if (type.priv.typeArgs) {
|
||||
return type.priv.typeArgs.some((typeArg) => requiresSpecialization(typeArg, options, recursionCount));
|
||||
}
|
||||
|
||||
return ClassType.getTypeParameters(type).length > 0;
|
||||
@ -3092,10 +3067,8 @@ function _requiresSpecialization(type: Type, options?: RequiresSpecializationOpt
|
||||
// If this is a recursive type alias, it may need to be specialized
|
||||
// if it has generic type arguments.
|
||||
const aliasInfo = type.props?.typeAliasInfo;
|
||||
if (aliasInfo?.typeArguments) {
|
||||
return aliasInfo.typeArguments.some((typeArg) =>
|
||||
requiresSpecialization(typeArg, options, recursionCount)
|
||||
);
|
||||
if (aliasInfo?.typeArgs) {
|
||||
return aliasInfo.typeArgs.some((typeArg) => requiresSpecialization(typeArg, options, recursionCount));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3122,7 +3095,7 @@ export function combineVariances(variance1: Variance, variance2: Variance) {
|
||||
|
||||
// Determines if the variance of the type argument for a generic class is compatible
|
||||
// With the declared variance of the corresponding type parameter.
|
||||
export function isVarianceOfTypeArgumentCompatible(type: Type, typeParamVariance: Variance): boolean {
|
||||
export function isVarianceOfTypeArgCompatible(type: Type, typeParamVariance: Variance): boolean {
|
||||
if (typeParamVariance === Variance.Unknown || typeParamVariance === Variance.Auto) {
|
||||
return true;
|
||||
}
|
||||
@ -3142,8 +3115,8 @@ export function isVarianceOfTypeArgumentCompatible(type: Type, typeParamVariance
|
||||
return true;
|
||||
}
|
||||
|
||||
if (type.priv.typeArguments && index < type.priv.typeArguments.length) {
|
||||
typeArgType = type.priv.typeArguments[index];
|
||||
if (type.priv.typeArgs && index < type.priv.typeArgs.length) {
|
||||
typeArgType = type.priv.typeArgs[index];
|
||||
}
|
||||
|
||||
const declaredVariance = typeParam.shared.declaredVariance;
|
||||
@ -3166,7 +3139,7 @@ export function isVarianceOfTypeArgumentCompatible(type: Type, typeParamVariance
|
||||
}
|
||||
}
|
||||
|
||||
return isVarianceOfTypeArgumentCompatible(typeArgType ?? UnknownType.create(), effectiveVariance);
|
||||
return isVarianceOfTypeArgCompatible(typeArgType ?? UnknownType.create(), effectiveVariance);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -3203,8 +3176,8 @@ export function computeMroLinearization(classType: ClassType): boolean {
|
||||
return (
|
||||
innerIndex > index &&
|
||||
isInstantiableClass(innerBaseClass) &&
|
||||
innerBaseClass.priv.typeArguments &&
|
||||
innerBaseClass.priv.isTypeArgumentExplicit
|
||||
innerBaseClass.priv.typeArgs &&
|
||||
innerBaseClass.priv.isTypeArgExplicit
|
||||
);
|
||||
})
|
||||
) {
|
||||
@ -3343,9 +3316,9 @@ export function getDeclaringModulesForType(type: Type): string[] {
|
||||
return moduleList;
|
||||
}
|
||||
|
||||
export function convertArgumentNodeToFunctionArgument(node: ArgumentNode): FunctionArgumentWithExpression {
|
||||
export function convertNodeToArg(node: ArgumentNode): ArgWithExpression {
|
||||
return {
|
||||
argumentCategory: node.d.argCategory,
|
||||
argCategory: node.d.argCategory,
|
||||
name: node.d.name,
|
||||
valueExpression: node.d.valueExpr,
|
||||
};
|
||||
@ -3541,12 +3514,12 @@ class TypeVarTransformer {
|
||||
// type aliases.
|
||||
const aliasInfo = type.props?.typeAliasInfo;
|
||||
if (type.shared.recursiveAlias) {
|
||||
if (!aliasInfo?.typeArguments) {
|
||||
if (!aliasInfo?.typeArgs) {
|
||||
return type;
|
||||
}
|
||||
|
||||
let requiresUpdate = false;
|
||||
const typeArgs = aliasInfo.typeArguments.map((typeArg) => {
|
||||
const typeArgs = aliasInfo.typeArgs.map((typeArg) => {
|
||||
const replacementType = this.apply(typeArg, recursionCount);
|
||||
if (replacementType !== typeArg) {
|
||||
requiresUpdate = true;
|
||||
@ -3710,7 +3683,7 @@ class TypeVarTransformer {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
transformTupleTypeVar(paramSpec: TypeVarType, recursionCount: number): TupleTypeArgument[] | undefined {
|
||||
transformTupleTypeVar(paramSpec: TypeVarType, recursionCount: number): TupleTypeArg[] | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@ -3730,12 +3703,12 @@ class TypeVarTransformer {
|
||||
|
||||
transformGenericTypeAlias(type: Type, recursionCount: number) {
|
||||
const aliasInfo = type.props?.typeAliasInfo;
|
||||
if (!aliasInfo || !aliasInfo.typeParameters || !aliasInfo.typeArguments) {
|
||||
if (!aliasInfo || !aliasInfo.typeParameters || !aliasInfo.typeArgs) {
|
||||
return type;
|
||||
}
|
||||
|
||||
let requiresUpdate = false;
|
||||
const newTypeArgs = aliasInfo.typeArguments.map((typeArg) => {
|
||||
const newTypeArgs = aliasInfo.typeArgs.map((typeArg) => {
|
||||
const updatedType = this.apply(typeArg, recursionCount);
|
||||
if (type !== updatedType) {
|
||||
requiresUpdate = true;
|
||||
@ -3776,7 +3749,7 @@ class TypeVarTransformer {
|
||||
}
|
||||
|
||||
let newTypeArgs: Type[] | undefined;
|
||||
let newTupleTypeArgs: TupleTypeArgument[] | undefined;
|
||||
let newTupleTypeArgs: TupleTypeArg[] | undefined;
|
||||
let specializationNeeded = false;
|
||||
|
||||
const transformParamSpec = (paramSpec: TypeVarType) => {
|
||||
@ -3796,9 +3769,9 @@ class TypeVarTransformer {
|
||||
|
||||
// Handle tuples specially.
|
||||
if (ClassType.isTupleClass(classType)) {
|
||||
if (classType.priv.tupleTypeArguments) {
|
||||
if (classType.priv.tupleTypeArgs) {
|
||||
newTupleTypeArgs = [];
|
||||
classType.priv.tupleTypeArguments.forEach((oldTypeArgType) => {
|
||||
classType.priv.tupleTypeArgs.forEach((oldTypeArgType) => {
|
||||
const newTypeArgType = this.apply(oldTypeArgType.type, recursionCount);
|
||||
|
||||
if (newTypeArgType !== oldTypeArgType.type) {
|
||||
@ -3809,9 +3782,9 @@ class TypeVarTransformer {
|
||||
isUnpackedVariadicTypeVar(oldTypeArgType.type) &&
|
||||
isClassInstance(newTypeArgType) &&
|
||||
isTupleClass(newTypeArgType) &&
|
||||
newTypeArgType.priv.tupleTypeArguments
|
||||
newTypeArgType.priv.tupleTypeArgs
|
||||
) {
|
||||
appendArray(newTupleTypeArgs!, newTypeArgType.priv.tupleTypeArguments);
|
||||
appendArray(newTupleTypeArgs!, newTypeArgType.priv.tupleTypeArgs);
|
||||
} else {
|
||||
// Handle the special case where tuple[T, ...] is being specialized
|
||||
// to tuple[Never, ...]. This is equivalent to tuple[()].
|
||||
@ -3819,7 +3792,7 @@ class TypeVarTransformer {
|
||||
oldTypeArgType.isUnbounded &&
|
||||
isTypeVar(oldTypeArgType.type) &&
|
||||
isNever(newTypeArgType) &&
|
||||
classType.priv.tupleTypeArguments!.length === 1;
|
||||
classType.priv.tupleTypeArgs!.length === 1;
|
||||
|
||||
if (!isEmptyTuple) {
|
||||
newTupleTypeArgs!.push({
|
||||
@ -3849,8 +3822,8 @@ class TypeVarTransformer {
|
||||
}
|
||||
|
||||
if (!newTypeArgs) {
|
||||
if (classType.priv.typeArguments) {
|
||||
newTypeArgs = classType.priv.typeArguments.map((oldTypeArgType) => {
|
||||
if (classType.priv.typeArgs) {
|
||||
newTypeArgs = classType.priv.typeArgs.map((oldTypeArgType) => {
|
||||
if (isTypeVar(oldTypeArgType) && oldTypeArgType.shared.isParamSpec) {
|
||||
return transformParamSpec(oldTypeArgType);
|
||||
}
|
||||
@ -3889,7 +3862,7 @@ class TypeVarTransformer {
|
||||
|
||||
if (replacementType !== typeParam) {
|
||||
specializationNeeded = true;
|
||||
} else if (transformedType !== undefined && !classType.priv.typeArguments) {
|
||||
} else if (transformedType !== undefined && !classType.priv.typeArgs) {
|
||||
specializationNeeded = true;
|
||||
}
|
||||
}
|
||||
@ -3910,7 +3883,7 @@ class TypeVarTransformer {
|
||||
return ClassType.cloneForSpecialization(
|
||||
classType,
|
||||
newTypeArgs,
|
||||
/* isTypeArgumentExplicit */ true,
|
||||
/* isTypeArgExplicit */ true,
|
||||
/* includeSubclasses */ undefined,
|
||||
newTupleTypeArgs
|
||||
);
|
||||
@ -3953,7 +3926,7 @@ class TypeVarTransformer {
|
||||
}
|
||||
|
||||
let variadicParamIndex: number | undefined;
|
||||
let variadicTypesToUnpack: TupleTypeArgument[] | undefined;
|
||||
let variadicTypesToUnpack: TupleTypeArg[] | undefined;
|
||||
const specializedDefaultArgs: (Type | undefined)[] = [];
|
||||
|
||||
const wasTransformingTypeArg = this._isTransformingTypeArg;
|
||||
@ -3987,7 +3960,7 @@ class TypeVarTransformer {
|
||||
isTupleClass(specializedType) &&
|
||||
specializedType.priv.isUnpacked
|
||||
) {
|
||||
variadicTypesToUnpack = specializedType.priv.tupleTypeArguments;
|
||||
variadicTypesToUnpack = specializedType.priv.tupleTypeArgs;
|
||||
}
|
||||
}
|
||||
|
||||
@ -4325,7 +4298,7 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
||||
replacement = ClassType.cloneForSpecialization(
|
||||
ClassType.cloneAsInstance(this._options.typeClassType),
|
||||
[replacement],
|
||||
/* isTypeArgumentExplicit */ true
|
||||
/* isTypeArgExplicit */ true
|
||||
);
|
||||
} else {
|
||||
replacement = convertToInstantiable(replacement, /* includeSubclasses */ false);
|
||||
@ -4343,7 +4316,7 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
||||
subtype = ClassType.cloneAsInstance(ClassType.cloneAsInstantiable(subtype));
|
||||
}
|
||||
|
||||
if (subtype.shared.typeParameters && !subtype.priv.typeArguments) {
|
||||
if (subtype.shared.typeParameters && !subtype.priv.typeArgs) {
|
||||
if (this._options.unknownIfNotFound) {
|
||||
return this._options.useUnknownOverDefault
|
||||
? specializeWithUnknownTypeArgs(subtype, this._options.tupleClassType)
|
||||
@ -4365,10 +4338,10 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
||||
if (
|
||||
!isVariadicTypeVar(typeVar) &&
|
||||
isClassInstance(replacement) &&
|
||||
replacement.priv.tupleTypeArguments &&
|
||||
replacement.priv.tupleTypeArgs &&
|
||||
replacement.priv.isUnpacked
|
||||
) {
|
||||
replacement = combineTupleTypeArgs(replacement.priv.tupleTypeArguments);
|
||||
replacement = combineTupleTypeArgs(replacement.priv.tupleTypeArgs);
|
||||
}
|
||||
|
||||
if (
|
||||
@ -4462,16 +4435,12 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
||||
return postTransform;
|
||||
}
|
||||
|
||||
override transformTupleTypeVar(typeVar: TypeVarType): TupleTypeArgument[] | undefined {
|
||||
override transformTupleTypeVar(typeVar: TypeVarType): TupleTypeArg[] | undefined {
|
||||
if (!typeVar.priv.scopeId || !this._typeVarContext.hasSolveForScope(typeVar.priv.scopeId)) {
|
||||
const defaultType = typeVar.shared.defaultType;
|
||||
|
||||
if (
|
||||
typeVar.shared.isDefaultExplicit &&
|
||||
isClassInstance(defaultType) &&
|
||||
defaultType.priv.tupleTypeArguments
|
||||
) {
|
||||
return defaultType.priv.tupleTypeArguments;
|
||||
if (typeVar.shared.isDefaultExplicit && isClassInstance(defaultType) && defaultType.priv.tupleTypeArgs) {
|
||||
return defaultType.priv.tupleTypeArgs;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
@ -4481,8 +4450,8 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
||||
this._activeTypeVarSignatureContextIndex ?? 0
|
||||
);
|
||||
const value = signatureContext.getTypeVarType(typeVar);
|
||||
if (value && isClassInstance(value) && value.priv.tupleTypeArguments && isUnpackedClass(value)) {
|
||||
return value.priv.tupleTypeArguments;
|
||||
if (value && isClassInstance(value) && value.priv.tupleTypeArgs && isUnpackedClass(value)) {
|
||||
return value.priv.tupleTypeArgs;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
@ -110,8 +110,8 @@ export class TypeWalker {
|
||||
const aliasInfo = type.props?.typeAliasInfo;
|
||||
assert(aliasInfo !== undefined);
|
||||
|
||||
if (aliasInfo.typeArguments) {
|
||||
for (const typeArg of aliasInfo.typeArguments) {
|
||||
if (aliasInfo.typeArgs) {
|
||||
for (const typeArg of aliasInfo.typeArgs) {
|
||||
this.walk(typeArg);
|
||||
if (this._isWalkCanceled) {
|
||||
break;
|
||||
@ -167,7 +167,7 @@ export class TypeWalker {
|
||||
|
||||
visitClass(type: ClassType): void {
|
||||
if (!ClassType.isPseudoGenericClass(type)) {
|
||||
const typeArgs = type.priv.tupleTypeArguments?.map((t) => t.type) || type.priv.typeArguments;
|
||||
const typeArgs = type.priv.tupleTypeArgs?.map((t) => t.type) || type.priv.typeArgs;
|
||||
if (typeArgs) {
|
||||
for (const argType of typeArgs) {
|
||||
this.walk(argType);
|
||||
|
@ -16,7 +16,7 @@ import { convertOffsetsToRange } from '../common/positionUtils';
|
||||
import { TextRange } from '../common/textRange';
|
||||
import { LocAddendum, LocMessage } from '../localization/localize';
|
||||
import {
|
||||
ArgumentCategory,
|
||||
ArgCategory,
|
||||
ClassNode,
|
||||
DictionaryNode,
|
||||
ExpressionNode,
|
||||
@ -30,7 +30,7 @@ import { DeclarationType, VariableDeclaration } from './declaration';
|
||||
import * as ParseTreeUtils from './parseTreeUtils';
|
||||
import { Symbol, SymbolFlags, SymbolTable } from './symbol';
|
||||
import { getLastTypedDeclarationForSymbol } from './symbolUtils';
|
||||
import { EvaluatorUsage, FunctionArgument, TypeEvaluator, TypeResult, TypeResultWithNode } from './typeEvaluatorTypes';
|
||||
import { Arg, EvaluatorUsage, TypeEvaluator, TypeResult, TypeResultWithNode } from './typeEvaluatorTypes';
|
||||
import {
|
||||
AnyType,
|
||||
ClassType,
|
||||
@ -73,7 +73,7 @@ export function createTypedDictType(
|
||||
evaluator: TypeEvaluator,
|
||||
errorNode: ExpressionNode,
|
||||
typedDictClass: ClassType,
|
||||
argList: FunctionArgument[]
|
||||
argList: Arg[]
|
||||
): ClassType {
|
||||
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
||||
|
||||
@ -86,7 +86,7 @@ export function createTypedDictType(
|
||||
} else {
|
||||
const nameArg = argList[0];
|
||||
if (
|
||||
nameArg.argumentCategory !== ArgumentCategory.Simple ||
|
||||
nameArg.argCategory !== ArgCategory.Simple ||
|
||||
!nameArg.valueExpression ||
|
||||
nameArg.valueExpression.nodeType !== ParseNodeType.StringList
|
||||
) {
|
||||
@ -127,7 +127,7 @@ export function createTypedDictType(
|
||||
const entriesArg = argList[1];
|
||||
|
||||
if (
|
||||
entriesArg.argumentCategory === ArgumentCategory.Simple &&
|
||||
entriesArg.argCategory === ArgCategory.Simple &&
|
||||
entriesArg.valueExpression &&
|
||||
entriesArg.valueExpression.nodeType === ParseNodeType.Dictionary
|
||||
) {
|
||||
@ -583,7 +583,7 @@ export function synthesizeTypedDictClassMethods(
|
||||
ClassType.cloneForSpecialization(
|
||||
iterableType,
|
||||
[combineTypes(tuplesToCombine)],
|
||||
/* isTypeArgumentExplicit */ true
|
||||
/* isTypeArgExplicit */ true
|
||||
),
|
||||
FunctionParamFlags.TypeDeclared,
|
||||
'__m'
|
||||
@ -701,7 +701,7 @@ export function synthesizeTypedDictClassMethods(
|
||||
{ type: strType, isUnbounded: false },
|
||||
{ type: dictValueType, isUnbounded: false },
|
||||
],
|
||||
/* isTypeArgumentExplicit */ true
|
||||
/* isTypeArgExplicit */ true
|
||||
);
|
||||
} else {
|
||||
tupleType = UnknownType.create();
|
||||
@ -729,7 +729,7 @@ export function synthesizeTypedDictClassMethods(
|
||||
method.shared.declaredReturnType = ClassType.cloneForSpecialization(
|
||||
ClassType.cloneAsInstance(returnTypeClass),
|
||||
[strType, mappingValueType],
|
||||
/* isTypeArgumentExplicit */ true
|
||||
/* isTypeArgExplicit */ true
|
||||
);
|
||||
|
||||
symbolTable.set(methodName, Symbol.createWithType(SymbolFlags.ClassMember, method));
|
||||
@ -1279,11 +1279,11 @@ export function assignToTypedDict(
|
||||
typeVarContext = new TypeVarContext(getTypeVarScopeId(classType));
|
||||
|
||||
// Create a generic (nonspecialized version) of the class.
|
||||
if (classType.priv.typeArguments) {
|
||||
if (classType.priv.typeArgs) {
|
||||
genericClassType = ClassType.cloneForSpecialization(
|
||||
classType,
|
||||
/* typeArguments */ undefined,
|
||||
/* isTypeArgumentExplicit */ false
|
||||
/* typeArgs */ undefined,
|
||||
/* isTypeArgExplicit */ false
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1426,7 +1426,7 @@ export function getTypeOfIndexedTypedDict(
|
||||
}
|
||||
|
||||
// Look for subscript types that are not supported by TypedDict.
|
||||
if (node.d.trailingComma || node.d.items[0].d.name || node.d.items[0].d.argCategory !== ArgumentCategory.Simple) {
|
||||
if (node.d.trailingComma || node.d.items[0].d.name || node.d.items[0].d.argCategory !== ArgCategory.Simple) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ export interface TypeAliasInfo {
|
||||
usageVariance: Variance[] | undefined;
|
||||
|
||||
// Type argument, if type alias is specialized
|
||||
typeArguments: Type[] | undefined;
|
||||
typeArgs: Type[] | undefined;
|
||||
}
|
||||
|
||||
interface CachedTypeInfo {
|
||||
@ -333,7 +333,7 @@ export namespace TypeBase {
|
||||
isPep695Syntax,
|
||||
typeParameters: typeParams,
|
||||
usageVariance: undefined,
|
||||
typeArguments: typeArgs,
|
||||
typeArgs: typeArgs,
|
||||
});
|
||||
|
||||
return typeClone;
|
||||
@ -713,7 +713,7 @@ interface ClassDetailsShared {
|
||||
inheritedSlotsNamesCached?: string[];
|
||||
}
|
||||
|
||||
export interface TupleTypeArgument {
|
||||
export interface TupleTypeArg {
|
||||
type: Type;
|
||||
|
||||
// Does the type argument represent a single value or
|
||||
@ -738,7 +738,7 @@ export interface ClassDetailsPriv {
|
||||
// A generic class that has been completely or partially
|
||||
// specialized will have type arguments that correspond to
|
||||
// some or all of the type parameters.
|
||||
typeArguments?: Type[] | undefined;
|
||||
typeArgs?: Type[] | undefined;
|
||||
|
||||
// If a generic container class (like a list or dict) is known
|
||||
// to contain no elements, its type arguments may be "Unknown".
|
||||
@ -749,9 +749,9 @@ export interface ClassDetailsPriv {
|
||||
// For tuples, the class definition calls for a single type parameter but
|
||||
// the spec allows the programmer to provide an arbitrary number of
|
||||
// type arguments. This field holds the individual type arguments
|
||||
// while the "typeArguments" field holds the derived non-variadic
|
||||
// while the "typeArgs" field holds the derived non-variadic
|
||||
// type argument, which is the union of the tuple type arguments.
|
||||
tupleTypeArguments?: TupleTypeArgument[] | undefined;
|
||||
tupleTypeArgs?: TupleTypeArg[] | undefined;
|
||||
|
||||
// We sometimes package multiple types into a tuple internally
|
||||
// for matching against a variadic type variable or another unpacked
|
||||
@ -760,7 +760,7 @@ export interface ClassDetailsPriv {
|
||||
|
||||
// If type arguments are present, were they explicit (i.e.
|
||||
// provided explicitly in the code)?
|
||||
isTypeArgumentExplicit?: boolean | undefined;
|
||||
isTypeArgExplicit?: boolean | undefined;
|
||||
|
||||
// This class type represents the class and any classes that
|
||||
// derive from it, as opposed to the original class only. This
|
||||
@ -892,22 +892,22 @@ export namespace ClassType {
|
||||
|
||||
export function cloneForSpecialization(
|
||||
classType: ClassType,
|
||||
typeArguments: Type[] | undefined,
|
||||
isTypeArgumentExplicit: boolean,
|
||||
typeArgs: Type[] | undefined,
|
||||
isTypeArgExplicit: boolean,
|
||||
includeSubclasses = false,
|
||||
tupleTypeArguments?: TupleTypeArgument[],
|
||||
tupleTypeArgs?: TupleTypeArg[],
|
||||
isEmptyContainer?: boolean
|
||||
): ClassType {
|
||||
const newClassType = TypeBase.cloneType(classType);
|
||||
|
||||
newClassType.priv.typeArguments = typeArguments?.length === 0 ? undefined : typeArguments;
|
||||
newClassType.priv.isTypeArgumentExplicit = isTypeArgumentExplicit;
|
||||
newClassType.priv.typeArgs = typeArgs?.length === 0 ? undefined : typeArgs;
|
||||
newClassType.priv.isTypeArgExplicit = isTypeArgExplicit;
|
||||
|
||||
if (includeSubclasses) {
|
||||
newClassType.priv.includeSubclasses = true;
|
||||
}
|
||||
|
||||
newClassType.priv.tupleTypeArguments = tupleTypeArguments ? [...tupleTypeArguments] : undefined;
|
||||
newClassType.priv.tupleTypeArgs = tupleTypeArgs ? [...tupleTypeArgs] : undefined;
|
||||
|
||||
if (isEmptyContainer !== undefined) {
|
||||
newClassType.priv.isEmptyContainer = isEmptyContainer;
|
||||
@ -1078,7 +1078,7 @@ export namespace ClassType {
|
||||
|
||||
// Is the class generic but not specialized?
|
||||
export function isUnspecialized(classType: ClassType) {
|
||||
return classType.shared.typeParameters.length > 0 && classType.priv.typeArguments === undefined;
|
||||
return classType.shared.typeParameters.length > 0 && classType.priv.typeArgs === undefined;
|
||||
}
|
||||
|
||||
export function isSpecialBuiltIn(classType: ClassType, className?: string) {
|
||||
@ -3195,9 +3195,9 @@ export function isTypeSame(type1: Type, type2: Type, options: TypeSameOptions =
|
||||
|
||||
if (!options.ignorePseudoGeneric || !ClassType.isPseudoGenericClass(type1)) {
|
||||
// Make sure the type args match.
|
||||
if (type1.priv.tupleTypeArguments && classType2.priv.tupleTypeArguments) {
|
||||
const type1TupleTypeArgs = type1.priv.tupleTypeArguments || [];
|
||||
const type2TupleTypeArgs = classType2.priv.tupleTypeArguments || [];
|
||||
if (type1.priv.tupleTypeArgs && classType2.priv.tupleTypeArgs) {
|
||||
const type1TupleTypeArgs = type1.priv.tupleTypeArgs || [];
|
||||
const type2TupleTypeArgs = classType2.priv.tupleTypeArgs || [];
|
||||
if (type1TupleTypeArgs.length !== type2TupleTypeArgs.length) {
|
||||
return false;
|
||||
}
|
||||
@ -3219,8 +3219,8 @@ export function isTypeSame(type1: Type, type2: Type, options: TypeSameOptions =
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const type1TypeArgs = type1.priv.typeArguments || [];
|
||||
const type2TypeArgs = classType2.priv.typeArguments || [];
|
||||
const type1TypeArgs = type1.priv.typeArgs || [];
|
||||
const type2TypeArgs = classType2.priv.typeArgs || [];
|
||||
const typeArgCount = Math.max(type1TypeArgs.length, type2TypeArgs.length);
|
||||
|
||||
for (let i = 0; i < typeArgCount; i++) {
|
||||
@ -3379,8 +3379,8 @@ export function isTypeSame(type1: Type, type2: Type, options: TypeSameOptions =
|
||||
// Handle the case where this is a generic recursive type alias. Make
|
||||
// sure that the type argument types match.
|
||||
if (type1.shared.recursiveAlias && type2TypeVar.shared.recursiveAlias) {
|
||||
const type1TypeArgs = type1?.props?.typeAliasInfo?.typeArguments || [];
|
||||
const type2TypeArgs = type2?.props?.typeAliasInfo?.typeArguments || [];
|
||||
const type1TypeArgs = type1?.props?.typeAliasInfo?.typeArgs || [];
|
||||
const type2TypeArgs = type2?.props?.typeAliasInfo?.typeArgs || [];
|
||||
const typeArgCount = Math.max(type1TypeArgs.length, type2TypeArgs.length);
|
||||
|
||||
for (let i = 0; i < typeArgCount; i++) {
|
||||
@ -3738,7 +3738,7 @@ function _addTypeIfUnique(unionType: UnionType, typeToAdd: UnionableType, elideR
|
||||
unionType.priv.subtypes[i] = ClassType.cloneForSpecialization(
|
||||
typeToAdd,
|
||||
typeToAdd.shared.typeParameters.map(() => UnknownType.create()),
|
||||
/* isTypeArgumentExplicit */ true
|
||||
/* isTypeArgExplicit */ true
|
||||
);
|
||||
return;
|
||||
}
|
||||
@ -3774,7 +3774,7 @@ function _addTypeIfUnique(unionType: UnionType, typeToAdd: UnionableType, elideR
|
||||
// existing type, see if one of them is a proper subset of the other.
|
||||
if (ClassType.isTypedDictClass(type) && ClassType.isSameGenericClass(type, typeToAdd)) {
|
||||
// Do not proceed if the TypedDicts are generic and have different type arguments.
|
||||
if (!type.priv.typeArguments && !typeToAdd.priv.typeArguments) {
|
||||
if (!type.priv.typeArgs && !typeToAdd.priv.typeArgs) {
|
||||
if (ClassType.isTypedDictNarrower(typeToAdd, type)) {
|
||||
return;
|
||||
} else if (ClassType.isTypedDictNarrower(type, typeToAdd)) {
|
||||
|
@ -32,7 +32,7 @@ import { TextRange } from '../common/textRange';
|
||||
import { TextRangeCollection } from '../common/textRangeCollection';
|
||||
import { Uri } from '../common/uri/uri';
|
||||
import {
|
||||
ArgumentCategory,
|
||||
ArgCategory,
|
||||
ArgumentNode,
|
||||
AssertNode,
|
||||
AssignmentExpressionNode,
|
||||
@ -578,7 +578,7 @@ class TreeDumper extends ParseTreeWalker {
|
||||
}
|
||||
|
||||
override visitArgument(node: ArgumentNode) {
|
||||
this._log(`${this._getPrefix(node)} ${getArgumentCategoryString(node.d.argCategory)}`);
|
||||
this._log(`${this._getPrefix(node)} ${getArgCategoryString(node.d.argCategory)}`);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1024,13 +1024,13 @@ function getParameterCategoryString(type: ParameterCategory) {
|
||||
}
|
||||
}
|
||||
|
||||
function getArgumentCategoryString(type: ArgumentCategory) {
|
||||
function getArgCategoryString(type: ArgCategory) {
|
||||
switch (type) {
|
||||
case ArgumentCategory.Simple:
|
||||
case ArgCategory.Simple:
|
||||
return 'Simple';
|
||||
case ArgumentCategory.UnpackedList:
|
||||
case ArgCategory.UnpackedList:
|
||||
return 'UnpackedList';
|
||||
case ArgumentCategory.UnpackedDictionary:
|
||||
case ArgCategory.UnpackedDictionary:
|
||||
return 'UnpackedDictionary';
|
||||
default:
|
||||
return `Unknown Value!! (${type})`;
|
||||
|
@ -89,7 +89,7 @@ import { Uri } from '../common/uri/uri';
|
||||
import { convertToTextEdits } from '../common/workspaceEditUtils';
|
||||
import { Localizer } from '../localization/localize';
|
||||
import {
|
||||
ArgumentCategory,
|
||||
ArgCategory,
|
||||
DecoratorNode,
|
||||
DictionaryKeyEntryNode,
|
||||
DictionaryNode,
|
||||
@ -1986,7 +1986,7 @@ export class CompletionProvider {
|
||||
return (
|
||||
currentNode &&
|
||||
currentNode.nodeType === ParseNodeType.Argument &&
|
||||
currentNode.d.argCategory === ArgumentCategory.Simple &&
|
||||
currentNode.d.argCategory === ArgCategory.Simple &&
|
||||
currentNode.parent &&
|
||||
currentNode.parent.nodeType === ParseNodeType.Index &&
|
||||
currentNode.parent.d.leftExpr &&
|
||||
|
@ -361,9 +361,9 @@ export function combineExpressionTypes(typeNodes: ExpressionNode[], evaluator: T
|
||||
typeList.length === 1 &&
|
||||
result.category === TypeCategory.Class &&
|
||||
ClassType.isBuiltIn(result, 'list') &&
|
||||
result.priv.typeArguments
|
||||
result.priv.typeArgs
|
||||
) {
|
||||
result = result.priv.typeArguments[0];
|
||||
result = result.priv.typeArgs[0];
|
||||
} else if (
|
||||
typeList.length === 1 &&
|
||||
result.category === TypeCategory.Class &&
|
||||
|
@ -1964,7 +1964,7 @@ export namespace ListNode {
|
||||
}
|
||||
}
|
||||
|
||||
export const enum ArgumentCategory {
|
||||
export const enum ArgCategory {
|
||||
Simple,
|
||||
UnpackedList,
|
||||
UnpackedDictionary,
|
||||
@ -1972,7 +1972,7 @@ export const enum ArgumentCategory {
|
||||
|
||||
export interface ArgumentNode extends ParseNodeBase<ParseNodeType.Argument> {
|
||||
d: {
|
||||
argCategory: ArgumentCategory;
|
||||
argCategory: ArgCategory;
|
||||
name: NameNode | undefined;
|
||||
valueExpr: ExpressionNode;
|
||||
|
||||
@ -1982,7 +1982,7 @@ export interface ArgumentNode extends ParseNodeBase<ParseNodeType.Argument> {
|
||||
}
|
||||
|
||||
export namespace ArgumentNode {
|
||||
export function create(startToken: Token | undefined, valueExpr: ExpressionNode, argCategory: ArgumentCategory) {
|
||||
export function create(startToken: Token | undefined, valueExpr: ExpressionNode, argCategory: ArgCategory) {
|
||||
const node: ArgumentNode = {
|
||||
start: startToken ? startToken.start : valueExpr.start,
|
||||
length: startToken ? startToken.length : valueExpr.length,
|
||||
|
@ -36,7 +36,7 @@ import { TextRangeCollection } from '../common/textRangeCollection';
|
||||
import { timingStats } from '../common/timing';
|
||||
import { LocAddendum, LocMessage } from '../localization/localize';
|
||||
import {
|
||||
ArgumentCategory,
|
||||
ArgCategory,
|
||||
ArgumentNode,
|
||||
AssertNode,
|
||||
AssignmentExpressionNode,
|
||||
@ -3641,11 +3641,11 @@ export class Parser {
|
||||
break;
|
||||
}
|
||||
|
||||
let argType = ArgumentCategory.Simple;
|
||||
let argType = ArgCategory.Simple;
|
||||
if (this._consumeTokenIfOperator(OperatorType.Multiply)) {
|
||||
argType = ArgumentCategory.UnpackedList;
|
||||
argType = ArgCategory.UnpackedList;
|
||||
} else if (this._consumeTokenIfOperator(OperatorType.Power)) {
|
||||
argType = ArgumentCategory.UnpackedDictionary;
|
||||
argType = ArgCategory.UnpackedDictionary;
|
||||
}
|
||||
|
||||
const startOfSubscriptIndex = this._tokenIndex;
|
||||
@ -3653,7 +3653,7 @@ export class Parser {
|
||||
let nameIdentifier: IdentifierToken | undefined;
|
||||
|
||||
// Is this a keyword argument?
|
||||
if (argType === ArgumentCategory.Simple) {
|
||||
if (argType === ArgCategory.Simple) {
|
||||
if (this._consumeTokenIfOperator(OperatorType.Assign)) {
|
||||
const nameExpr = valueExpr;
|
||||
valueExpr = this._parsePossibleSlice();
|
||||
@ -3685,7 +3685,7 @@ export class Parser {
|
||||
|
||||
if (argNode.d.name) {
|
||||
sawKeywordArg = true;
|
||||
} else if (sawKeywordArg && argNode.d.argCategory === ArgumentCategory.Simple) {
|
||||
} else if (sawKeywordArg && argNode.d.argCategory === ArgCategory.Simple) {
|
||||
this._addSyntaxError(LocMessage.positionArgAfterNamedArg(), argNode);
|
||||
}
|
||||
argList.push(argNode);
|
||||
@ -3694,17 +3694,17 @@ export class Parser {
|
||||
this._addSyntaxError(LocMessage.keywordSubscriptIllegal(), argNode.d.name);
|
||||
}
|
||||
|
||||
if (argType !== ArgumentCategory.Simple) {
|
||||
if (argType !== ArgCategory.Simple) {
|
||||
const unpackListAllowed =
|
||||
this._parseOptions.isStubFile ||
|
||||
this._isParsingQuotedText ||
|
||||
this._getLanguageVersion().isGreaterOrEqualTo(pythonVersion3_11);
|
||||
|
||||
if (argType === ArgumentCategory.UnpackedList && !unpackListAllowed) {
|
||||
if (argType === ArgCategory.UnpackedList && !unpackListAllowed) {
|
||||
this._addSyntaxError(LocMessage.unpackedSubscriptIllegal(), argNode);
|
||||
}
|
||||
|
||||
if (argType === ArgumentCategory.UnpackedDictionary) {
|
||||
if (argType === ArgCategory.UnpackedDictionary) {
|
||||
this._addSyntaxError(LocMessage.unpackedDictSubscriptIllegal(), argNode);
|
||||
}
|
||||
}
|
||||
@ -3726,7 +3726,7 @@ export class Parser {
|
||||
/* childNode */ undefined,
|
||||
[TokenType.CloseBracket]
|
||||
);
|
||||
argList.push(ArgumentNode.create(this._peekToken(), errorNode, ArgumentCategory.Simple));
|
||||
argList.push(ArgumentNode.create(this._peekToken(), errorNode, ArgCategory.Simple));
|
||||
}
|
||||
|
||||
return {
|
||||
@ -3813,7 +3813,7 @@ export class Parser {
|
||||
const arg = this._parseArgument();
|
||||
if (arg.d.name) {
|
||||
sawKeywordArg = true;
|
||||
} else if (sawKeywordArg && arg.d.argCategory === ArgumentCategory.Simple) {
|
||||
} else if (sawKeywordArg && arg.d.argCategory === ArgCategory.Simple) {
|
||||
this._addSyntaxError(LocMessage.positionArgAfterNamedArg(), arg);
|
||||
}
|
||||
argList.push(arg);
|
||||
@ -3836,11 +3836,11 @@ export class Parser {
|
||||
private _parseArgument(): ArgumentNode {
|
||||
const firstToken = this._peekToken();
|
||||
|
||||
let argType = ArgumentCategory.Simple;
|
||||
let argType = ArgCategory.Simple;
|
||||
if (this._consumeTokenIfOperator(OperatorType.Multiply)) {
|
||||
argType = ArgumentCategory.UnpackedList;
|
||||
argType = ArgCategory.UnpackedList;
|
||||
} else if (this._consumeTokenIfOperator(OperatorType.Power)) {
|
||||
argType = ArgumentCategory.UnpackedDictionary;
|
||||
argType = ArgCategory.UnpackedDictionary;
|
||||
}
|
||||
|
||||
let valueExpr = this._parseTestExpression(/* allowAssignmentExpression */ true);
|
||||
@ -3848,7 +3848,7 @@ export class Parser {
|
||||
let isNameSameAsValue = false;
|
||||
let assignmentToken: Token | undefined;
|
||||
|
||||
if (argType === ArgumentCategory.Simple) {
|
||||
if (argType === ArgCategory.Simple) {
|
||||
const nextToken = this._peekToken();
|
||||
|
||||
if (this._consumeTokenIfOperator(OperatorType.Assign)) {
|
||||
|
Loading…
Reference in New Issue
Block a user