mirror of
https://github.com/microsoft/pyright.git
synced 2024-08-15 19:00:33 +03:00
Renamed evaluation flag for clarify and consistency. No functional change.
This commit is contained in:
parent
2947be68bf
commit
f6c9ca9feb
@ -703,7 +703,7 @@ export function getTypeOfBinaryOperation(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & EvaluatorFlags.ExpectingTypeAnnotation) !== 0) {
|
if ((flags & EvaluatorFlags.ExpectingTypeExpression) !== 0) {
|
||||||
// Exempt "|" because it might be a union operation involving unknowns.
|
// Exempt "|" because it might be a union operation involving unknowns.
|
||||||
if (node.operator !== OperatorType.BitwiseOr) {
|
if (node.operator !== OperatorType.BitwiseOr) {
|
||||||
evaluator.addDiagnostic(DiagnosticRule.reportInvalidTypeForm, LocMessage.binaryOperationNotAllowed(), node);
|
evaluator.addDiagnostic(DiagnosticRule.reportInvalidTypeForm, LocMessage.binaryOperationNotAllowed(), node);
|
||||||
@ -950,7 +950,7 @@ export function getTypeOfUnaryOperation(
|
|||||||
flags: EvaluatorFlags,
|
flags: EvaluatorFlags,
|
||||||
inferenceContext: InferenceContext | undefined
|
inferenceContext: InferenceContext | undefined
|
||||||
): TypeResult {
|
): TypeResult {
|
||||||
if ((flags & EvaluatorFlags.ExpectingTypeAnnotation) !== 0) {
|
if ((flags & EvaluatorFlags.ExpectingTypeExpression) !== 0) {
|
||||||
evaluator.addDiagnostic(DiagnosticRule.reportInvalidTypeForm, LocMessage.unaryOperationNotAllowed(), node);
|
evaluator.addDiagnostic(DiagnosticRule.reportInvalidTypeForm, LocMessage.unaryOperationNotAllowed(), node);
|
||||||
return { type: UnknownType.create() };
|
return { type: UnknownType.create() };
|
||||||
}
|
}
|
||||||
@ -1087,7 +1087,7 @@ export function getTypeOfTernaryOperation(
|
|||||||
): TypeResult {
|
): TypeResult {
|
||||||
const fileInfo = getFileInfo(node);
|
const fileInfo = getFileInfo(node);
|
||||||
|
|
||||||
if ((flags & EvaluatorFlags.ExpectingTypeAnnotation) !== 0) {
|
if ((flags & EvaluatorFlags.ExpectingTypeExpression) !== 0) {
|
||||||
evaluator.addDiagnostic(DiagnosticRule.reportInvalidTypeForm, LocMessage.ternaryNotAllowed(), node);
|
evaluator.addDiagnostic(DiagnosticRule.reportInvalidTypeForm, LocMessage.ternaryNotAllowed(), node);
|
||||||
return { type: UnknownType.create() };
|
return { type: UnknownType.create() };
|
||||||
}
|
}
|
||||||
|
@ -1266,7 +1266,7 @@ export function createTypeEvaluator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
case ParseNodeType.AssignmentExpression: {
|
case ParseNodeType.AssignmentExpression: {
|
||||||
if ((flags & EvaluatorFlags.ExpectingTypeAnnotation) !== 0) {
|
if ((flags & EvaluatorFlags.ExpectingTypeExpression) !== 0) {
|
||||||
addError(LocMessage.walrusNotAllowed(), node);
|
addError(LocMessage.walrusNotAllowed(), node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1294,7 +1294,7 @@ export function createTypeEvaluator(
|
|||||||
typeResult = getTypeOfExpression(
|
typeResult = getTypeOfExpression(
|
||||||
node.typeAnnotation,
|
node.typeAnnotation,
|
||||||
EvaluatorFlags.ExpectingInstantiableType |
|
EvaluatorFlags.ExpectingInstantiableType |
|
||||||
EvaluatorFlags.ExpectingTypeAnnotation |
|
EvaluatorFlags.ExpectingTypeExpression |
|
||||||
EvaluatorFlags.EvaluateStringLiteralAsType |
|
EvaluatorFlags.EvaluateStringLiteralAsType |
|
||||||
EvaluatorFlags.DisallowParamSpec |
|
EvaluatorFlags.DisallowParamSpec |
|
||||||
EvaluatorFlags.DisallowTypeVarTuple |
|
EvaluatorFlags.DisallowTypeVarTuple |
|
||||||
@ -1337,7 +1337,7 @@ export function createTypeEvaluator(
|
|||||||
|
|
||||||
// If this is a PEP 695 type alias, remove the special form so the type
|
// If this is a PEP 695 type alias, remove the special form so the type
|
||||||
// printer prints it as its aliased type rather than TypeAliasType.
|
// printer prints it as its aliased type rather than TypeAliasType.
|
||||||
if ((flags & EvaluatorFlags.ExpectingTypeAnnotation) !== 0) {
|
if ((flags & EvaluatorFlags.ExpectingTypeExpression) !== 0) {
|
||||||
if (typeResult.type.specialForm && ClassType.isBuiltIn(typeResult.type.specialForm, 'TypeAliasType')) {
|
if (typeResult.type.specialForm && ClassType.isBuiltIn(typeResult.type.specialForm, 'TypeAliasType')) {
|
||||||
typeResult.type = TypeBase.cloneAsSpecialForm(typeResult.type, undefined);
|
typeResult.type = TypeBase.cloneAsSpecialForm(typeResult.type, undefined);
|
||||||
}
|
}
|
||||||
@ -1404,7 +1404,7 @@ export function createTypeEvaluator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getTypeOfAwaitOperator(node: AwaitNode, flags: EvaluatorFlags, inferenceContext?: InferenceContext) {
|
function getTypeOfAwaitOperator(node: AwaitNode, flags: EvaluatorFlags, inferenceContext?: InferenceContext) {
|
||||||
if ((flags & EvaluatorFlags.ExpectingTypeAnnotation) !== 0) {
|
if ((flags & EvaluatorFlags.ExpectingTypeExpression) !== 0) {
|
||||||
addError(LocMessage.awaitNotAllowed(), node);
|
addError(LocMessage.awaitNotAllowed(), node);
|
||||||
return { type: UnknownType.create() };
|
return { type: UnknownType.create() };
|
||||||
}
|
}
|
||||||
@ -1484,7 +1484,7 @@ export function createTypeEvaluator(
|
|||||||
ClassType.isBuiltIn(iterType, 'tuple')
|
ClassType.isBuiltIn(iterType, 'tuple')
|
||||||
) {
|
) {
|
||||||
typeResult = { type: ClassType.cloneForUnpacked(iterType) };
|
typeResult = { type: ClassType.cloneForUnpacked(iterType) };
|
||||||
} else if ((flags & EvaluatorFlags.ExpectingTypeAnnotation) !== 0) {
|
} else if ((flags & EvaluatorFlags.ExpectingTypeExpression) !== 0) {
|
||||||
addError(LocMessage.unpackInAnnotation(), node, node.starToken);
|
addError(LocMessage.unpackInAnnotation(), node, node.starToken);
|
||||||
typeResult = { type: UnknownType.create() };
|
typeResult = { type: UnknownType.create() };
|
||||||
} else {
|
} else {
|
||||||
@ -1726,7 +1726,7 @@ export function createTypeEvaluator(
|
|||||||
|
|
||||||
let evaluatorFlags =
|
let evaluatorFlags =
|
||||||
EvaluatorFlags.ExpectingInstantiableType |
|
EvaluatorFlags.ExpectingInstantiableType |
|
||||||
EvaluatorFlags.ExpectingTypeAnnotation |
|
EvaluatorFlags.ExpectingTypeExpression |
|
||||||
EvaluatorFlags.ConvertEllipsisToAny |
|
EvaluatorFlags.ConvertEllipsisToAny |
|
||||||
EvaluatorFlags.EvaluateStringLiteralAsType;
|
EvaluatorFlags.EvaluateStringLiteralAsType;
|
||||||
|
|
||||||
@ -4411,7 +4411,7 @@ export function createTypeEvaluator(
|
|||||||
node,
|
node,
|
||||||
name,
|
name,
|
||||||
!allowForwardReferences,
|
!allowForwardReferences,
|
||||||
allowForwardReferences && (flags & EvaluatorFlags.ExpectingTypeAnnotation) !== 0
|
allowForwardReferences && (flags & EvaluatorFlags.ExpectingTypeExpression) !== 0
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!symbolWithScope) {
|
if (!symbolWithScope) {
|
||||||
@ -4424,7 +4424,7 @@ export function createTypeEvaluator(
|
|||||||
alias,
|
alias,
|
||||||
alias.value,
|
alias.value,
|
||||||
!allowForwardReferences,
|
!allowForwardReferences,
|
||||||
allowForwardReferences && (flags & EvaluatorFlags.ExpectingTypeAnnotation) !== 0
|
allowForwardReferences && (flags & EvaluatorFlags.ExpectingTypeExpression) !== 0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4517,7 +4517,7 @@ export function createTypeEvaluator(
|
|||||||
const codeFlowTypeResult = getFlowTypeOfReference(node, /* startNode */ undefined, {
|
const codeFlowTypeResult = getFlowTypeOfReference(node, /* startNode */ undefined, {
|
||||||
targetSymbolId: symbol.id,
|
targetSymbolId: symbol.id,
|
||||||
typeAtStart: { type: typeAtStart, isIncomplete: isTypeAtStartIncomplete },
|
typeAtStart: { type: typeAtStart, isIncomplete: isTypeAtStartIncomplete },
|
||||||
skipConditionalNarrowing: (flags & EvaluatorFlags.ExpectingTypeAnnotation) !== 0,
|
skipConditionalNarrowing: (flags & EvaluatorFlags.ExpectingTypeExpression) !== 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (codeFlowTypeResult.type) {
|
if (codeFlowTypeResult.type) {
|
||||||
@ -4532,7 +4532,7 @@ export function createTypeEvaluator(
|
|||||||
// Detect, report, and fill in missing type arguments if appropriate.
|
// Detect, report, and fill in missing type arguments if appropriate.
|
||||||
type = reportMissingTypeArguments(node, type, flags);
|
type = reportMissingTypeArguments(node, type, flags);
|
||||||
|
|
||||||
if ((flags & EvaluatorFlags.ExpectingTypeAnnotation) !== 0) {
|
if ((flags & EvaluatorFlags.ExpectingTypeExpression) !== 0) {
|
||||||
// Verify that the name does not refer to a (non type alias) variable.
|
// Verify that the name does not refer to a (non type alias) variable.
|
||||||
if (effectiveTypeInfo.includesVariableDecl && !type.typeAliasInfo) {
|
if (effectiveTypeInfo.includesVariableDecl && !type.typeAliasInfo) {
|
||||||
let isAllowedTypeForVariable = isTypeVar(type) || isTypeAliasPlaceholder(type);
|
let isAllowedTypeForVariable = isTypeVar(type) || isTypeAliasPlaceholder(type);
|
||||||
@ -4593,7 +4593,7 @@ export function createTypeEvaluator(
|
|||||||
|
|
||||||
type = convertTypeVarToRuntimeInstance(node, type, flags);
|
type = convertTypeVarToRuntimeInstance(node, type, flags);
|
||||||
|
|
||||||
if ((flags & EvaluatorFlags.ExpectingTypeAnnotation) === 0) {
|
if ((flags & EvaluatorFlags.ExpectingTypeExpression) === 0) {
|
||||||
reportUseOfTypeCheckOnly(type, node);
|
reportUseOfTypeCheckOnly(type, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5094,7 +5094,7 @@ export function createTypeEvaluator(
|
|||||||
let leftExprFlags = EvaluatorFlags.MemberAccessBaseDefaults;
|
let leftExprFlags = EvaluatorFlags.MemberAccessBaseDefaults;
|
||||||
leftExprFlags |=
|
leftExprFlags |=
|
||||||
flags &
|
flags &
|
||||||
(EvaluatorFlags.ExpectingTypeAnnotation |
|
(EvaluatorFlags.ExpectingTypeExpression |
|
||||||
EvaluatorFlags.VariableTypeAnnotation |
|
EvaluatorFlags.VariableTypeAnnotation |
|
||||||
EvaluatorFlags.AllowForwardReferences |
|
EvaluatorFlags.AllowForwardReferences |
|
||||||
EvaluatorFlags.NotParsedByInterpreter |
|
EvaluatorFlags.NotParsedByInterpreter |
|
||||||
@ -5161,7 +5161,7 @@ export function createTypeEvaluator(
|
|||||||
const codeFlowTypeResult = getFlowTypeOfReference(node, /* startNode */ undefined, {
|
const codeFlowTypeResult = getFlowTypeOfReference(node, /* startNode */ undefined, {
|
||||||
targetSymbolId: indeterminateSymbolId,
|
targetSymbolId: indeterminateSymbolId,
|
||||||
typeAtStart: { type: typeAtStart, isIncomplete: isTypeAtStartIncomplete },
|
typeAtStart: { type: typeAtStart, isIncomplete: isTypeAtStartIncomplete },
|
||||||
skipConditionalNarrowing: (flags & EvaluatorFlags.ExpectingTypeAnnotation) !== 0,
|
skipConditionalNarrowing: (flags & EvaluatorFlags.ExpectingTypeExpression) !== 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (codeFlowTypeResult.type) {
|
if (codeFlowTypeResult.type) {
|
||||||
@ -5294,7 +5294,7 @@ export function createTypeEvaluator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// It's illegal to reference a member from a type variable.
|
// It's illegal to reference a member from a type variable.
|
||||||
if ((flags & EvaluatorFlags.ExpectingTypeAnnotation) !== 0) {
|
if ((flags & EvaluatorFlags.ExpectingTypeExpression) !== 0) {
|
||||||
if (!isIncomplete) {
|
if (!isIncomplete) {
|
||||||
addDiagnostic(
|
addDiagnostic(
|
||||||
DiagnosticRule.reportGeneralTypeIssues,
|
DiagnosticRule.reportGeneralTypeIssues,
|
||||||
@ -5638,7 +5638,7 @@ export function createTypeEvaluator(
|
|||||||
type = isFunctionRule ? AnyType.create() : UnknownType.create();
|
type = isFunctionRule ? AnyType.create() : UnknownType.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & EvaluatorFlags.ExpectingTypeAnnotation) === 0) {
|
if ((flags & EvaluatorFlags.ExpectingTypeExpression) === 0) {
|
||||||
reportUseOfTypeCheckOnly(type, node.memberName);
|
reportUseOfTypeCheckOnly(type, node.memberName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6521,7 +6521,7 @@ export function createTypeEvaluator(
|
|||||||
type: indexTypeResult.type,
|
type: indexTypeResult.type,
|
||||||
isIncomplete: !!baseTypeResult.isIncomplete || !!indexTypeResult.isIncomplete,
|
isIncomplete: !!baseTypeResult.isIncomplete || !!indexTypeResult.isIncomplete,
|
||||||
},
|
},
|
||||||
skipConditionalNarrowing: (flags & EvaluatorFlags.ExpectingTypeAnnotation) !== 0,
|
skipConditionalNarrowing: (flags & EvaluatorFlags.ExpectingTypeExpression) !== 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (codeFlowTypeResult.type) {
|
if (codeFlowTypeResult.type) {
|
||||||
@ -7027,7 +7027,7 @@ export function createTypeEvaluator(
|
|||||||
getIndexAccessMagicMethodName(usage)
|
getIndexAccessMagicMethodName(usage)
|
||||||
);
|
);
|
||||||
|
|
||||||
if ((flags & EvaluatorFlags.ExpectingTypeAnnotation) !== 0) {
|
if ((flags & EvaluatorFlags.ExpectingTypeExpression) !== 0) {
|
||||||
// If the class doesn't derive from Generic, a type argument should not be allowed.
|
// If the class doesn't derive from Generic, a type argument should not be allowed.
|
||||||
addDiagnostic(
|
addDiagnostic(
|
||||||
DiagnosticRule.reportInvalidTypeArguments,
|
DiagnosticRule.reportInvalidTypeArguments,
|
||||||
@ -7068,7 +7068,7 @@ export function createTypeEvaluator(
|
|||||||
// Special-case InitVar, used in dataclasses.
|
// Special-case InitVar, used in dataclasses.
|
||||||
const typeArgs = getTypeArgs(node, flags);
|
const typeArgs = getTypeArgs(node, flags);
|
||||||
|
|
||||||
if ((flags & EvaluatorFlags.ExpectingTypeAnnotation) !== 0) {
|
if ((flags & EvaluatorFlags.ExpectingTypeExpression) !== 0) {
|
||||||
if ((flags & EvaluatorFlags.VariableTypeAnnotation) === 0) {
|
if ((flags & EvaluatorFlags.VariableTypeAnnotation) === 0) {
|
||||||
addError(LocMessage.initVarNotAllowed(), node.baseExpression);
|
addError(LocMessage.initVarNotAllowed(), node.baseExpression);
|
||||||
}
|
}
|
||||||
@ -7752,7 +7752,7 @@ export function createTypeEvaluator(
|
|||||||
signatureTracker: UniqueSignatureTracker | undefined
|
signatureTracker: UniqueSignatureTracker | undefined
|
||||||
): TypeResult {
|
): TypeResult {
|
||||||
if (
|
if (
|
||||||
(flags & EvaluatorFlags.ExpectingTypeAnnotation) !== 0 &&
|
(flags & EvaluatorFlags.ExpectingTypeExpression) !== 0 &&
|
||||||
node.parent?.nodeType !== ParseNodeType.Argument
|
node.parent?.nodeType !== ParseNodeType.Argument
|
||||||
) {
|
) {
|
||||||
// This is allowed inside of an index trailer, specifically
|
// This is allowed inside of an index trailer, specifically
|
||||||
@ -7778,7 +7778,7 @@ export function createTypeEvaluator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
flags &= ~(
|
flags &= ~(
|
||||||
EvaluatorFlags.ExpectingTypeAnnotation |
|
EvaluatorFlags.ExpectingTypeExpression |
|
||||||
EvaluatorFlags.EvaluateStringLiteralAsType |
|
EvaluatorFlags.EvaluateStringLiteralAsType |
|
||||||
EvaluatorFlags.ExpectingInstantiableType
|
EvaluatorFlags.ExpectingInstantiableType
|
||||||
);
|
);
|
||||||
@ -8010,7 +8010,7 @@ export function createTypeEvaluator(
|
|||||||
// allowed, and it's a common mistake, so we want to emit a diagnostic
|
// allowed, and it's a common mistake, so we want to emit a diagnostic
|
||||||
// that guides the user to the right solution.
|
// that guides the user to the right solution.
|
||||||
if (
|
if (
|
||||||
(flags & EvaluatorFlags.ExpectingTypeAnnotation) !== 0 &&
|
(flags & EvaluatorFlags.ExpectingTypeExpression) !== 0 &&
|
||||||
node.leftExpression.nodeType === ParseNodeType.Name &&
|
node.leftExpression.nodeType === ParseNodeType.Name &&
|
||||||
node.leftExpression.value === 'type'
|
node.leftExpression.value === 'type'
|
||||||
) {
|
) {
|
||||||
@ -8138,7 +8138,7 @@ export function createTypeEvaluator(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & EvaluatorFlags.ExpectingTypeAnnotation) !== 0) {
|
if ((flags & EvaluatorFlags.ExpectingTypeExpression) !== 0) {
|
||||||
addDiagnostic(DiagnosticRule.reportInvalidTypeForm, LocMessage.typeAnnotationCall(), node);
|
addDiagnostic(DiagnosticRule.reportInvalidTypeForm, LocMessage.typeAnnotationCall(), node);
|
||||||
|
|
||||||
typeResult = { type: UnknownType.create() };
|
typeResult = { type: UnknownType.create() };
|
||||||
@ -12078,7 +12078,7 @@ export function createTypeEvaluator(
|
|||||||
EvaluatorFlags.DisallowTypeVarTuple |
|
EvaluatorFlags.DisallowTypeVarTuple |
|
||||||
EvaluatorFlags.DisallowFinal |
|
EvaluatorFlags.DisallowFinal |
|
||||||
EvaluatorFlags.DoNotSpecialize
|
EvaluatorFlags.DoNotSpecialize
|
||||||
: EvaluatorFlags.DoNotSpecialize | EvaluatorFlags.DisallowFinal;
|
: EvaluatorFlags.DisallowFinal | EvaluatorFlags.DoNotSpecialize;
|
||||||
const exprTypeResult = getTypeOfExpression(
|
const exprTypeResult = getTypeOfExpression(
|
||||||
argParam.argument.valueExpression,
|
argParam.argument.valueExpression,
|
||||||
flags,
|
flags,
|
||||||
@ -13265,7 +13265,7 @@ export function createTypeEvaluator(
|
|||||||
inferenceContext: InferenceContext | undefined
|
inferenceContext: InferenceContext | undefined
|
||||||
): TypeResult {
|
): TypeResult {
|
||||||
if (
|
if (
|
||||||
(flags & EvaluatorFlags.ExpectingTypeAnnotation) !== 0 &&
|
(flags & EvaluatorFlags.ExpectingTypeExpression) !== 0 &&
|
||||||
node.parent?.nodeType !== ParseNodeType.Argument
|
node.parent?.nodeType !== ParseNodeType.Argument
|
||||||
) {
|
) {
|
||||||
const diag = new DiagnosticAddendum();
|
const diag = new DiagnosticAddendum();
|
||||||
@ -13585,7 +13585,7 @@ export function createTypeEvaluator(
|
|||||||
const keyFlags =
|
const keyFlags =
|
||||||
flags &
|
flags &
|
||||||
~(
|
~(
|
||||||
EvaluatorFlags.ExpectingTypeAnnotation |
|
EvaluatorFlags.ExpectingTypeExpression |
|
||||||
EvaluatorFlags.EvaluateStringLiteralAsType |
|
EvaluatorFlags.EvaluateStringLiteralAsType |
|
||||||
EvaluatorFlags.ExpectingInstantiableType
|
EvaluatorFlags.ExpectingInstantiableType
|
||||||
);
|
);
|
||||||
@ -13847,7 +13847,7 @@ export function createTypeEvaluator(
|
|||||||
inferenceContext: InferenceContext | undefined
|
inferenceContext: InferenceContext | undefined
|
||||||
): TypeResult {
|
): TypeResult {
|
||||||
if (
|
if (
|
||||||
(flags & EvaluatorFlags.ExpectingTypeAnnotation) !== 0 &&
|
(flags & EvaluatorFlags.ExpectingTypeExpression) !== 0 &&
|
||||||
node.nodeType === ParseNodeType.List &&
|
node.nodeType === ParseNodeType.List &&
|
||||||
node.parent?.nodeType !== ParseNodeType.Argument
|
node.parent?.nodeType !== ParseNodeType.Argument
|
||||||
) {
|
) {
|
||||||
@ -13857,7 +13857,7 @@ export function createTypeEvaluator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
flags &= ~(
|
flags &= ~(
|
||||||
EvaluatorFlags.ExpectingTypeAnnotation |
|
EvaluatorFlags.ExpectingTypeExpression |
|
||||||
EvaluatorFlags.EvaluateStringLiteralAsType |
|
EvaluatorFlags.EvaluateStringLiteralAsType |
|
||||||
EvaluatorFlags.ExpectingInstantiableType
|
EvaluatorFlags.ExpectingInstantiableType
|
||||||
);
|
);
|
||||||
@ -14931,7 +14931,7 @@ export function createTypeEvaluator(
|
|||||||
// If no type arguments are provided, the resulting type
|
// If no type arguments are provided, the resulting type
|
||||||
// depends on whether we're evaluating a type annotation or
|
// depends on whether we're evaluating a type annotation or
|
||||||
// we're in some other context.
|
// we're in some other context.
|
||||||
if ((flags & EvaluatorFlags.ExpectingTypeAnnotation) !== 0) {
|
if ((flags & EvaluatorFlags.ExpectingTypeExpression) !== 0) {
|
||||||
addError(LocMessage.optionalExtraArgs(), errorNode);
|
addError(LocMessage.optionalExtraArgs(), errorNode);
|
||||||
return UnknownType.create();
|
return UnknownType.create();
|
||||||
}
|
}
|
||||||
@ -15149,7 +15149,7 @@ export function createTypeEvaluator(
|
|||||||
// depends on whether we're evaluating a type annotation or
|
// depends on whether we're evaluating a type annotation or
|
||||||
// we're in some other context.
|
// we're in some other context.
|
||||||
if (!typeArgs) {
|
if (!typeArgs) {
|
||||||
if ((flags & EvaluatorFlags.ExpectingTypeAnnotation) !== 0) {
|
if ((flags & EvaluatorFlags.ExpectingTypeExpression) !== 0) {
|
||||||
addError(LocMessage.typeGuardArgCount(), errorNode);
|
addError(LocMessage.typeGuardArgCount(), errorNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15194,7 +15194,7 @@ export function createTypeEvaluator(
|
|||||||
|
|
||||||
const enclosingClassTypeResult = enclosingClass ? getTypeOfClass(enclosingClass) : undefined;
|
const enclosingClassTypeResult = enclosingClass ? getTypeOfClass(enclosingClass) : undefined;
|
||||||
if (!enclosingClassTypeResult) {
|
if (!enclosingClassTypeResult) {
|
||||||
if ((flags & (EvaluatorFlags.ExpectingTypeAnnotation | EvaluatorFlags.ExpectingInstantiableType)) !== 0) {
|
if ((flags & (EvaluatorFlags.ExpectingTypeExpression | EvaluatorFlags.ExpectingInstantiableType)) !== 0) {
|
||||||
addDiagnostic(DiagnosticRule.reportGeneralTypeIssues, LocMessage.selfTypeContext(), errorNode);
|
addDiagnostic(DiagnosticRule.reportGeneralTypeIssues, LocMessage.selfTypeContext(), errorNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15256,7 +15256,7 @@ export function createTypeEvaluator(
|
|||||||
// If no type arguments are provided, the resulting type
|
// If no type arguments are provided, the resulting type
|
||||||
// depends on whether we're evaluating a type annotation or
|
// depends on whether we're evaluating a type annotation or
|
||||||
// we're in some other context.
|
// we're in some other context.
|
||||||
if (!typeArgs && (flags & EvaluatorFlags.ExpectingTypeAnnotation) === 0) {
|
if (!typeArgs && (flags & EvaluatorFlags.ExpectingTypeExpression) === 0) {
|
||||||
return { type: classType };
|
return { type: classType };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15340,7 +15340,7 @@ export function createTypeEvaluator(
|
|||||||
// If no type arguments are provided, the resulting type
|
// If no type arguments are provided, the resulting type
|
||||||
// depends on whether we're evaluating a type annotation or
|
// depends on whether we're evaluating a type annotation or
|
||||||
// we're in some other context.
|
// we're in some other context.
|
||||||
if (!typeArgs && (flags & EvaluatorFlags.ExpectingTypeAnnotation) === 0) {
|
if (!typeArgs && (flags & EvaluatorFlags.ExpectingTypeExpression) === 0) {
|
||||||
return classType;
|
return classType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15664,7 +15664,7 @@ export function createTypeEvaluator(
|
|||||||
// If no type arguments are provided, the resulting type
|
// If no type arguments are provided, the resulting type
|
||||||
// depends on whether we're evaluating a type annotation or
|
// depends on whether we're evaluating a type annotation or
|
||||||
// we're in some other context.
|
// we're in some other context.
|
||||||
if ((flags & EvaluatorFlags.ExpectingTypeAnnotation) !== 0) {
|
if ((flags & EvaluatorFlags.ExpectingTypeExpression) !== 0) {
|
||||||
addError(LocMessage.unionTypeArgCount(), errorNode);
|
addError(LocMessage.unionTypeArgCount(), errorNode);
|
||||||
return NeverType.createNever();
|
return NeverType.createNever();
|
||||||
}
|
}
|
||||||
@ -15751,7 +15751,7 @@ export function createTypeEvaluator(
|
|||||||
// If no type arguments are provided, the resulting type
|
// If no type arguments are provided, the resulting type
|
||||||
// depends on whether we're evaluating a type annotation or
|
// depends on whether we're evaluating a type annotation or
|
||||||
// we're in some other context.
|
// we're in some other context.
|
||||||
if ((flags & (EvaluatorFlags.ExpectingTypeAnnotation | EvaluatorFlags.DisallowNakedGeneric)) !== 0) {
|
if ((flags & (EvaluatorFlags.ExpectingTypeExpression | EvaluatorFlags.DisallowNakedGeneric)) !== 0) {
|
||||||
addError(LocMessage.genericTypeArgMissing(), errorNode);
|
addError(LocMessage.genericTypeArgMissing(), errorNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16145,11 +16145,12 @@ export function createTypeEvaluator(
|
|||||||
|
|
||||||
let typeAliasNameNode: NameNode | undefined;
|
let typeAliasNameNode: NameNode | undefined;
|
||||||
let isSpeculativeTypeAlias = false;
|
let isSpeculativeTypeAlias = false;
|
||||||
|
let typeAliasPlaceholder: TypeVarType | undefined;
|
||||||
|
|
||||||
if (isDeclaredTypeAlias(node.leftExpression)) {
|
if (isDeclaredTypeAlias(node.leftExpression)) {
|
||||||
flags =
|
flags =
|
||||||
EvaluatorFlags.ExpectingInstantiableType |
|
EvaluatorFlags.ExpectingInstantiableType |
|
||||||
EvaluatorFlags.ExpectingTypeAnnotation |
|
EvaluatorFlags.ExpectingTypeExpression |
|
||||||
EvaluatorFlags.EvaluateStringLiteralAsType |
|
EvaluatorFlags.EvaluateStringLiteralAsType |
|
||||||
EvaluatorFlags.DisallowParamSpec |
|
EvaluatorFlags.DisallowParamSpec |
|
||||||
EvaluatorFlags.DisallowTypeVarTuple |
|
EvaluatorFlags.DisallowTypeVarTuple |
|
||||||
@ -16187,13 +16188,9 @@ export function createTypeEvaluator(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synthesize a type variable that represents the type alias while we're
|
|
||||||
// evaluating it. This allows us to handle recursive definitions.
|
|
||||||
let typeAliasPlaceholder: TypeVarType | undefined;
|
|
||||||
if (typeAliasNameNode) {
|
if (typeAliasNameNode) {
|
||||||
typeAliasPlaceholder = synthesizeTypeAliasPlaceholder(typeAliasNameNode);
|
typeAliasPlaceholder = synthesizeTypeAliasPlaceholder(typeAliasNameNode);
|
||||||
|
|
||||||
// Write the type to the type cache to support recursive type alias definitions.
|
|
||||||
writeTypeCache(node, { type: typeAliasPlaceholder }, /* flags */ undefined);
|
writeTypeCache(node, { type: typeAliasPlaceholder }, /* flags */ undefined);
|
||||||
writeTypeCache(node.leftExpression, { type: typeAliasPlaceholder }, /* flags */ undefined);
|
writeTypeCache(node.leftExpression, { type: typeAliasPlaceholder }, /* flags */ undefined);
|
||||||
|
|
||||||
@ -20022,7 +20019,7 @@ export function createTypeEvaluator(
|
|||||||
case 'Protocol': {
|
case 'Protocol': {
|
||||||
if (
|
if (
|
||||||
(flags &
|
(flags &
|
||||||
(EvaluatorFlags.DisallowNonTypeSpecialForms | EvaluatorFlags.ExpectingTypeAnnotation)) !==
|
(EvaluatorFlags.DisallowNonTypeSpecialForms | EvaluatorFlags.ExpectingTypeExpression)) !==
|
||||||
0
|
0
|
||||||
) {
|
) {
|
||||||
addError(LocMessage.protocolNotAllowed(), errorNode);
|
addError(LocMessage.protocolNotAllowed(), errorNode);
|
||||||
@ -20047,7 +20044,7 @@ export function createTypeEvaluator(
|
|||||||
case 'TypedDict': {
|
case 'TypedDict': {
|
||||||
if (
|
if (
|
||||||
(flags &
|
(flags &
|
||||||
(EvaluatorFlags.DisallowNonTypeSpecialForms | EvaluatorFlags.ExpectingTypeAnnotation)) !==
|
(EvaluatorFlags.DisallowNonTypeSpecialForms | EvaluatorFlags.ExpectingTypeExpression)) !==
|
||||||
0
|
0
|
||||||
) {
|
) {
|
||||||
addError(LocMessage.typedDictNotAllowed(), errorNode);
|
addError(LocMessage.typedDictNotAllowed(), errorNode);
|
||||||
@ -20058,7 +20055,7 @@ export function createTypeEvaluator(
|
|||||||
case 'Literal': {
|
case 'Literal': {
|
||||||
if (
|
if (
|
||||||
(flags &
|
(flags &
|
||||||
(EvaluatorFlags.DisallowNonTypeSpecialForms | EvaluatorFlags.ExpectingTypeAnnotation)) !==
|
(EvaluatorFlags.DisallowNonTypeSpecialForms | EvaluatorFlags.ExpectingTypeExpression)) !==
|
||||||
0
|
0
|
||||||
) {
|
) {
|
||||||
addError(LocMessage.literalNotAllowed(), errorNode);
|
addError(LocMessage.literalNotAllowed(), errorNode);
|
||||||
@ -20511,7 +20508,7 @@ export function createTypeEvaluator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (options?.allowRequired) {
|
if (options?.allowRequired) {
|
||||||
flags |= EvaluatorFlags.AllowRequired | EvaluatorFlags.ExpectingTypeAnnotation;
|
flags |= EvaluatorFlags.AllowRequired | EvaluatorFlags.ExpectingTypeExpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options?.allowUnpackedTuple) {
|
if (options?.allowUnpackedTuple) {
|
||||||
@ -20525,7 +20522,7 @@ export function createTypeEvaluator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (options?.enforceTypeAnnotationRules) {
|
if (options?.enforceTypeAnnotationRules) {
|
||||||
flags |= EvaluatorFlags.ExpectingTypeAnnotation;
|
flags |= EvaluatorFlags.ExpectingTypeExpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options?.disallowProtocolAndTypedDict) {
|
if (options?.disallowProtocolAndTypedDict) {
|
||||||
|
@ -86,10 +86,9 @@ export const enum EvaluatorFlags {
|
|||||||
// than an instance (object)
|
// than an instance (object)
|
||||||
ExpectingInstantiableType = 1 << 7,
|
ExpectingInstantiableType = 1 << 7,
|
||||||
|
|
||||||
// A type annotation restricts the types of expressions that are
|
// A type expression imposes grammatical and semantic limits on an
|
||||||
// allowed. If this flag is set, illegal type expressions are
|
// expression. If this flag is set, illegal type expressions are
|
||||||
// flagged as errors.
|
ExpectingTypeExpression = 1 << 8,
|
||||||
ExpectingTypeAnnotation = 1 << 8,
|
|
||||||
|
|
||||||
// Suppress the reportMissingTypeArgument diagnostic in this context.
|
// Suppress the reportMissingTypeArgument diagnostic in this context.
|
||||||
AllowMissingTypeArgs = 1 << 9,
|
AllowMissingTypeArgs = 1 << 9,
|
||||||
|
Loading…
Reference in New Issue
Block a user