mirror of
https://github.com/microsoft/pyright.git
synced 2024-10-03 19:37:39 +03:00
Renamed internal function for clarity. No functional change.
This commit is contained in:
parent
d55be983e5
commit
3e70e7a8f9
@ -1020,7 +1020,7 @@ function assignTypeToParamSpec(
|
||||
// performs this reverse mapping of type arguments and populates the type var
|
||||
// map for the target type. If the type is not assignable to the expected type,
|
||||
// it returns false.
|
||||
export function populateTypeVarContextBasedOnExpectedType(
|
||||
export function addConstraintsForExpectedType(
|
||||
evaluator: TypeEvaluator,
|
||||
type: ClassType,
|
||||
expectedType: Type,
|
||||
|
@ -17,7 +17,7 @@ import { DiagnosticAddendum } from '../common/diagnostic';
|
||||
import { DiagnosticRule } from '../common/diagnosticRules';
|
||||
import { LocMessage } from '../localization/localize';
|
||||
import { ArgumentCategory, ExpressionNode, ParameterCategory } from '../parser/parseNodes';
|
||||
import { populateTypeVarContextBasedOnExpectedType } from './constraintSolver';
|
||||
import { addConstraintsForExpectedType } from './constraintSolver';
|
||||
import { applyConstructorTransform, hasConstructorTransform } from './constructorTransform';
|
||||
import { getTypeVarScopesForNode } from './parseTreeUtils';
|
||||
import { CallResult, FunctionArgument, TypeEvaluator, TypeResult } from './typeEvaluatorTypes';
|
||||
@ -543,7 +543,7 @@ function validateInitMethod(
|
||||
typeVarContext.addSolveForScope(getTypeVarScopeId(initMethodType));
|
||||
|
||||
if (
|
||||
populateTypeVarContextBasedOnExpectedType(
|
||||
!addConstraintsForExpectedType(
|
||||
evaluator,
|
||||
ClassType.cloneAsInstance(type),
|
||||
expectedSubType,
|
||||
@ -552,54 +552,56 @@ function validateInitMethod(
|
||||
errorNode.start
|
||||
)
|
||||
) {
|
||||
const specializedConstructor = applySolvedTypeVars(initMethodType, typeVarContext);
|
||||
|
||||
let callResult: CallResult | undefined;
|
||||
callResult = evaluator.useSpeculativeMode(errorNode, () => {
|
||||
return evaluator.validateCallArguments(
|
||||
errorNode,
|
||||
argList,
|
||||
{ type: specializedConstructor },
|
||||
typeVarContext.clone(),
|
||||
skipUnknownArgCheck,
|
||||
/* inferenceContext */ undefined,
|
||||
signatureTracker
|
||||
);
|
||||
});
|
||||
|
||||
if (!callResult.argumentErrors) {
|
||||
// Call validateCallArguments again, this time without speculative
|
||||
// mode, so any errors are reported.
|
||||
callResult = evaluator.validateCallArguments(
|
||||
errorNode,
|
||||
argList,
|
||||
{ type: specializedConstructor },
|
||||
typeVarContext,
|
||||
skipUnknownArgCheck,
|
||||
/* inferenceContext */ undefined,
|
||||
signatureTracker
|
||||
);
|
||||
|
||||
if (callResult.isTypeIncomplete) {
|
||||
isTypeIncomplete = true;
|
||||
}
|
||||
|
||||
if (callResult.argumentErrors) {
|
||||
argumentErrors = true;
|
||||
}
|
||||
|
||||
if (callResult.overloadsUsedForCall) {
|
||||
appendArray(overloadsUsedForCall, callResult.overloadsUsedForCall);
|
||||
}
|
||||
|
||||
// Note that we've found an expected type that works.
|
||||
foundWorkingExpectedType = true;
|
||||
|
||||
return applyExpectedSubtypeForConstructor(evaluator, type, expectedSubType, typeVarContext);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
const specializedConstructor = applySolvedTypeVars(initMethodType, typeVarContext);
|
||||
|
||||
let callResult: CallResult | undefined;
|
||||
callResult = evaluator.useSpeculativeMode(errorNode, () => {
|
||||
return evaluator.validateCallArguments(
|
||||
errorNode,
|
||||
argList,
|
||||
{ type: specializedConstructor },
|
||||
typeVarContext.clone(),
|
||||
skipUnknownArgCheck,
|
||||
/* inferenceContext */ undefined,
|
||||
signatureTracker
|
||||
);
|
||||
});
|
||||
|
||||
if (callResult.argumentErrors) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Call validateCallArguments again, this time without speculative
|
||||
// mode, so any errors are reported.
|
||||
callResult = evaluator.validateCallArguments(
|
||||
errorNode,
|
||||
argList,
|
||||
{ type: specializedConstructor },
|
||||
typeVarContext,
|
||||
skipUnknownArgCheck,
|
||||
/* inferenceContext */ undefined,
|
||||
signatureTracker
|
||||
);
|
||||
|
||||
if (callResult.isTypeIncomplete) {
|
||||
isTypeIncomplete = true;
|
||||
}
|
||||
|
||||
if (callResult.argumentErrors) {
|
||||
argumentErrors = true;
|
||||
}
|
||||
|
||||
if (callResult.overloadsUsedForCall) {
|
||||
appendArray(overloadsUsedForCall, callResult.overloadsUsedForCall);
|
||||
}
|
||||
|
||||
// Note that we've found an expected type that works.
|
||||
foundWorkingExpectedType = true;
|
||||
|
||||
return applyExpectedSubtypeForConstructor(evaluator, type, expectedSubType, typeVarContext);
|
||||
},
|
||||
/* sortSubtypes */ true
|
||||
);
|
||||
@ -708,7 +710,7 @@ function validateFallbackConstructorCall(
|
||||
}
|
||||
|
||||
if (expectedType) {
|
||||
populateTypeVarContextBasedOnExpectedType(
|
||||
addConstraintsForExpectedType(
|
||||
evaluator,
|
||||
ClassType.cloneAsInstance(type),
|
||||
expectedType,
|
||||
|
@ -29,7 +29,7 @@ import {
|
||||
PatternValueNode,
|
||||
} from '../parser/parseNodes';
|
||||
import { CodeFlowReferenceExpressionNode } from './codeFlowTypes';
|
||||
import { populateTypeVarContextBasedOnExpectedType } from './constraintSolver';
|
||||
import { addConstraintsForExpectedType } from './constraintSolver';
|
||||
import { getTypeVarScopesForNode, isMatchingExpression } from './parseTreeUtils';
|
||||
import { EvaluatorFlags, TypeEvaluator, TypeResult } from './typeEvaluatorTypes';
|
||||
import {
|
||||
@ -921,7 +921,7 @@ function narrowTypeBasedOnClassPattern(
|
||||
|
||||
const matchTypeInstance = ClassType.cloneAsInstance(unspecializedMatchType);
|
||||
if (
|
||||
populateTypeVarContextBasedOnExpectedType(
|
||||
addConstraintsForExpectedType(
|
||||
evaluator,
|
||||
matchTypeInstance,
|
||||
subjectSubtypeExpanded,
|
||||
@ -1454,7 +1454,7 @@ function getSequencePatternInfo(
|
||||
if (sequenceType && isInstantiableClass(sequenceType)) {
|
||||
const sequenceTypeVarContext = new TypeVarContext(getTypeVarScopeId(sequenceType));
|
||||
if (
|
||||
populateTypeVarContextBasedOnExpectedType(
|
||||
addConstraintsForExpectedType(
|
||||
evaluator,
|
||||
ClassType.cloneAsInstance(sequenceType),
|
||||
subtype,
|
||||
|
@ -97,7 +97,7 @@ import {
|
||||
isCodeFlowSupportedForReference,
|
||||
wildcardImportReferenceKey,
|
||||
} from './codeFlowTypes';
|
||||
import { assignTypeToTypeVar, populateTypeVarContextBasedOnExpectedType, updateTypeVarType } from './constraintSolver';
|
||||
import { addConstraintsForExpectedType, assignTypeToTypeVar, updateTypeVarType } from './constraintSolver';
|
||||
import {
|
||||
createFunctionFromConstructor,
|
||||
getBoundInitMethod,
|
||||
@ -7872,7 +7872,7 @@ export function createTypeEvaluator(
|
||||
} else {
|
||||
const tupleTypeVarContext = new TypeVarContext(getTypeVarScopeId(tupleClass));
|
||||
if (
|
||||
!populateTypeVarContextBasedOnExpectedType(
|
||||
!addConstraintsForExpectedType(
|
||||
evaluatorInterface,
|
||||
ClassType.cloneAsInstance(tupleClass),
|
||||
inferenceContext.expectedType,
|
||||
@ -11316,7 +11316,7 @@ export function createTypeEvaluator(
|
||||
if (isClassInstance(effectiveExpectedType) && !isTypeSame(effectiveReturnType, effectiveExpectedType)) {
|
||||
const tempTypeVarContext = new TypeVarContext(getTypeVarScopeId(effectiveReturnType));
|
||||
if (
|
||||
populateTypeVarContextBasedOnExpectedType(
|
||||
addConstraintsForExpectedType(
|
||||
evaluatorInterface,
|
||||
effectiveReturnType,
|
||||
effectiveExpectedType,
|
||||
@ -13397,7 +13397,7 @@ export function createTypeEvaluator(
|
||||
|
||||
const dictTypeVarContext = new TypeVarContext(getTypeVarScopeId(builtInDict));
|
||||
if (
|
||||
!populateTypeVarContextBasedOnExpectedType(
|
||||
!addConstraintsForExpectedType(
|
||||
evaluatorInterface,
|
||||
builtInDict,
|
||||
inferenceContext.expectedType,
|
||||
@ -14016,7 +14016,7 @@ export function createTypeEvaluator(
|
||||
|
||||
const typeVarContext = new TypeVarContext(getTypeVarScopeId(expectedClassType));
|
||||
if (
|
||||
!populateTypeVarContextBasedOnExpectedType(
|
||||
!addConstraintsForExpectedType(
|
||||
evaluatorInterface,
|
||||
ClassType.cloneAsInstance(expectedClassType),
|
||||
inferenceContext.expectedType,
|
||||
@ -25959,7 +25959,7 @@ export function createTypeEvaluator(
|
||||
!assignedType.tupleTypeArguments
|
||||
) {
|
||||
const typeVarContext = new TypeVarContext(getTypeVarScopeId(assignedType));
|
||||
populateTypeVarContextBasedOnExpectedType(
|
||||
addConstraintsForExpectedType(
|
||||
evaluatorInterface,
|
||||
ClassType.cloneForSpecialization(
|
||||
assignedType,
|
||||
|
@ -22,7 +22,7 @@ import {
|
||||
} from '../parser/parseNodes';
|
||||
import { KeywordType, OperatorType } from '../parser/tokenizerTypes';
|
||||
import { getFileInfo } from './analyzerNodeInfo';
|
||||
import { populateTypeVarContextBasedOnExpectedType } from './constraintSolver';
|
||||
import { addConstraintsForExpectedType } from './constraintSolver';
|
||||
import { Declaration, DeclarationType } from './declaration';
|
||||
import { transformTypeForEnumMember } from './enums';
|
||||
import * as ParseTreeUtils from './parseTreeUtils';
|
||||
@ -1451,7 +1451,7 @@ function narrowTypeForIsInstanceInternal(
|
||||
);
|
||||
|
||||
if (
|
||||
populateTypeVarContextBasedOnExpectedType(
|
||||
addConstraintsForExpectedType(
|
||||
evaluator,
|
||||
unspecializedFilterType,
|
||||
concreteVarType,
|
||||
|
Loading…
Reference in New Issue
Block a user