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
|
// 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,
|
// map for the target type. If the type is not assignable to the expected type,
|
||||||
// it returns false.
|
// it returns false.
|
||||||
export function populateTypeVarContextBasedOnExpectedType(
|
export function addConstraintsForExpectedType(
|
||||||
evaluator: TypeEvaluator,
|
evaluator: TypeEvaluator,
|
||||||
type: ClassType,
|
type: ClassType,
|
||||||
expectedType: Type,
|
expectedType: Type,
|
||||||
|
@ -17,7 +17,7 @@ import { DiagnosticAddendum } from '../common/diagnostic';
|
|||||||
import { DiagnosticRule } from '../common/diagnosticRules';
|
import { DiagnosticRule } from '../common/diagnosticRules';
|
||||||
import { LocMessage } from '../localization/localize';
|
import { LocMessage } from '../localization/localize';
|
||||||
import { ArgumentCategory, ExpressionNode, ParameterCategory } from '../parser/parseNodes';
|
import { ArgumentCategory, ExpressionNode, ParameterCategory } from '../parser/parseNodes';
|
||||||
import { populateTypeVarContextBasedOnExpectedType } from './constraintSolver';
|
import { addConstraintsForExpectedType } from './constraintSolver';
|
||||||
import { applyConstructorTransform, hasConstructorTransform } from './constructorTransform';
|
import { applyConstructorTransform, hasConstructorTransform } from './constructorTransform';
|
||||||
import { getTypeVarScopesForNode } from './parseTreeUtils';
|
import { getTypeVarScopesForNode } from './parseTreeUtils';
|
||||||
import { CallResult, FunctionArgument, TypeEvaluator, TypeResult } from './typeEvaluatorTypes';
|
import { CallResult, FunctionArgument, TypeEvaluator, TypeResult } from './typeEvaluatorTypes';
|
||||||
@ -543,7 +543,7 @@ function validateInitMethod(
|
|||||||
typeVarContext.addSolveForScope(getTypeVarScopeId(initMethodType));
|
typeVarContext.addSolveForScope(getTypeVarScopeId(initMethodType));
|
||||||
|
|
||||||
if (
|
if (
|
||||||
populateTypeVarContextBasedOnExpectedType(
|
!addConstraintsForExpectedType(
|
||||||
evaluator,
|
evaluator,
|
||||||
ClassType.cloneAsInstance(type),
|
ClassType.cloneAsInstance(type),
|
||||||
expectedSubType,
|
expectedSubType,
|
||||||
@ -552,54 +552,56 @@ function validateInitMethod(
|
|||||||
errorNode.start
|
errorNode.start
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
const specializedConstructor = applySolvedTypeVars(initMethodType, typeVarContext);
|
return undefined;
|
||||||
|
|
||||||
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;
|
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
|
/* sortSubtypes */ true
|
||||||
);
|
);
|
||||||
@ -708,7 +710,7 @@ function validateFallbackConstructorCall(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (expectedType) {
|
if (expectedType) {
|
||||||
populateTypeVarContextBasedOnExpectedType(
|
addConstraintsForExpectedType(
|
||||||
evaluator,
|
evaluator,
|
||||||
ClassType.cloneAsInstance(type),
|
ClassType.cloneAsInstance(type),
|
||||||
expectedType,
|
expectedType,
|
||||||
|
@ -29,7 +29,7 @@ import {
|
|||||||
PatternValueNode,
|
PatternValueNode,
|
||||||
} from '../parser/parseNodes';
|
} from '../parser/parseNodes';
|
||||||
import { CodeFlowReferenceExpressionNode } from './codeFlowTypes';
|
import { CodeFlowReferenceExpressionNode } from './codeFlowTypes';
|
||||||
import { populateTypeVarContextBasedOnExpectedType } from './constraintSolver';
|
import { addConstraintsForExpectedType } from './constraintSolver';
|
||||||
import { getTypeVarScopesForNode, isMatchingExpression } from './parseTreeUtils';
|
import { getTypeVarScopesForNode, isMatchingExpression } from './parseTreeUtils';
|
||||||
import { EvaluatorFlags, TypeEvaluator, TypeResult } from './typeEvaluatorTypes';
|
import { EvaluatorFlags, TypeEvaluator, TypeResult } from './typeEvaluatorTypes';
|
||||||
import {
|
import {
|
||||||
@ -921,7 +921,7 @@ function narrowTypeBasedOnClassPattern(
|
|||||||
|
|
||||||
const matchTypeInstance = ClassType.cloneAsInstance(unspecializedMatchType);
|
const matchTypeInstance = ClassType.cloneAsInstance(unspecializedMatchType);
|
||||||
if (
|
if (
|
||||||
populateTypeVarContextBasedOnExpectedType(
|
addConstraintsForExpectedType(
|
||||||
evaluator,
|
evaluator,
|
||||||
matchTypeInstance,
|
matchTypeInstance,
|
||||||
subjectSubtypeExpanded,
|
subjectSubtypeExpanded,
|
||||||
@ -1454,7 +1454,7 @@ function getSequencePatternInfo(
|
|||||||
if (sequenceType && isInstantiableClass(sequenceType)) {
|
if (sequenceType && isInstantiableClass(sequenceType)) {
|
||||||
const sequenceTypeVarContext = new TypeVarContext(getTypeVarScopeId(sequenceType));
|
const sequenceTypeVarContext = new TypeVarContext(getTypeVarScopeId(sequenceType));
|
||||||
if (
|
if (
|
||||||
populateTypeVarContextBasedOnExpectedType(
|
addConstraintsForExpectedType(
|
||||||
evaluator,
|
evaluator,
|
||||||
ClassType.cloneAsInstance(sequenceType),
|
ClassType.cloneAsInstance(sequenceType),
|
||||||
subtype,
|
subtype,
|
||||||
|
@ -97,7 +97,7 @@ import {
|
|||||||
isCodeFlowSupportedForReference,
|
isCodeFlowSupportedForReference,
|
||||||
wildcardImportReferenceKey,
|
wildcardImportReferenceKey,
|
||||||
} from './codeFlowTypes';
|
} from './codeFlowTypes';
|
||||||
import { assignTypeToTypeVar, populateTypeVarContextBasedOnExpectedType, updateTypeVarType } from './constraintSolver';
|
import { addConstraintsForExpectedType, assignTypeToTypeVar, updateTypeVarType } from './constraintSolver';
|
||||||
import {
|
import {
|
||||||
createFunctionFromConstructor,
|
createFunctionFromConstructor,
|
||||||
getBoundInitMethod,
|
getBoundInitMethod,
|
||||||
@ -7872,7 +7872,7 @@ export function createTypeEvaluator(
|
|||||||
} else {
|
} else {
|
||||||
const tupleTypeVarContext = new TypeVarContext(getTypeVarScopeId(tupleClass));
|
const tupleTypeVarContext = new TypeVarContext(getTypeVarScopeId(tupleClass));
|
||||||
if (
|
if (
|
||||||
!populateTypeVarContextBasedOnExpectedType(
|
!addConstraintsForExpectedType(
|
||||||
evaluatorInterface,
|
evaluatorInterface,
|
||||||
ClassType.cloneAsInstance(tupleClass),
|
ClassType.cloneAsInstance(tupleClass),
|
||||||
inferenceContext.expectedType,
|
inferenceContext.expectedType,
|
||||||
@ -11316,7 +11316,7 @@ export function createTypeEvaluator(
|
|||||||
if (isClassInstance(effectiveExpectedType) && !isTypeSame(effectiveReturnType, effectiveExpectedType)) {
|
if (isClassInstance(effectiveExpectedType) && !isTypeSame(effectiveReturnType, effectiveExpectedType)) {
|
||||||
const tempTypeVarContext = new TypeVarContext(getTypeVarScopeId(effectiveReturnType));
|
const tempTypeVarContext = new TypeVarContext(getTypeVarScopeId(effectiveReturnType));
|
||||||
if (
|
if (
|
||||||
populateTypeVarContextBasedOnExpectedType(
|
addConstraintsForExpectedType(
|
||||||
evaluatorInterface,
|
evaluatorInterface,
|
||||||
effectiveReturnType,
|
effectiveReturnType,
|
||||||
effectiveExpectedType,
|
effectiveExpectedType,
|
||||||
@ -13397,7 +13397,7 @@ export function createTypeEvaluator(
|
|||||||
|
|
||||||
const dictTypeVarContext = new TypeVarContext(getTypeVarScopeId(builtInDict));
|
const dictTypeVarContext = new TypeVarContext(getTypeVarScopeId(builtInDict));
|
||||||
if (
|
if (
|
||||||
!populateTypeVarContextBasedOnExpectedType(
|
!addConstraintsForExpectedType(
|
||||||
evaluatorInterface,
|
evaluatorInterface,
|
||||||
builtInDict,
|
builtInDict,
|
||||||
inferenceContext.expectedType,
|
inferenceContext.expectedType,
|
||||||
@ -14016,7 +14016,7 @@ export function createTypeEvaluator(
|
|||||||
|
|
||||||
const typeVarContext = new TypeVarContext(getTypeVarScopeId(expectedClassType));
|
const typeVarContext = new TypeVarContext(getTypeVarScopeId(expectedClassType));
|
||||||
if (
|
if (
|
||||||
!populateTypeVarContextBasedOnExpectedType(
|
!addConstraintsForExpectedType(
|
||||||
evaluatorInterface,
|
evaluatorInterface,
|
||||||
ClassType.cloneAsInstance(expectedClassType),
|
ClassType.cloneAsInstance(expectedClassType),
|
||||||
inferenceContext.expectedType,
|
inferenceContext.expectedType,
|
||||||
@ -25959,7 +25959,7 @@ export function createTypeEvaluator(
|
|||||||
!assignedType.tupleTypeArguments
|
!assignedType.tupleTypeArguments
|
||||||
) {
|
) {
|
||||||
const typeVarContext = new TypeVarContext(getTypeVarScopeId(assignedType));
|
const typeVarContext = new TypeVarContext(getTypeVarScopeId(assignedType));
|
||||||
populateTypeVarContextBasedOnExpectedType(
|
addConstraintsForExpectedType(
|
||||||
evaluatorInterface,
|
evaluatorInterface,
|
||||||
ClassType.cloneForSpecialization(
|
ClassType.cloneForSpecialization(
|
||||||
assignedType,
|
assignedType,
|
||||||
|
@ -22,7 +22,7 @@ import {
|
|||||||
} from '../parser/parseNodes';
|
} from '../parser/parseNodes';
|
||||||
import { KeywordType, OperatorType } from '../parser/tokenizerTypes';
|
import { KeywordType, OperatorType } from '../parser/tokenizerTypes';
|
||||||
import { getFileInfo } from './analyzerNodeInfo';
|
import { getFileInfo } from './analyzerNodeInfo';
|
||||||
import { populateTypeVarContextBasedOnExpectedType } from './constraintSolver';
|
import { addConstraintsForExpectedType } from './constraintSolver';
|
||||||
import { Declaration, DeclarationType } from './declaration';
|
import { Declaration, DeclarationType } from './declaration';
|
||||||
import { transformTypeForEnumMember } from './enums';
|
import { transformTypeForEnumMember } from './enums';
|
||||||
import * as ParseTreeUtils from './parseTreeUtils';
|
import * as ParseTreeUtils from './parseTreeUtils';
|
||||||
@ -1451,7 +1451,7 @@ function narrowTypeForIsInstanceInternal(
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
populateTypeVarContextBasedOnExpectedType(
|
addConstraintsForExpectedType(
|
||||||
evaluator,
|
evaluator,
|
||||||
unspecializedFilterType,
|
unspecializedFilterType,
|
||||||
concreteVarType,
|
concreteVarType,
|
||||||
|
Loading…
Reference in New Issue
Block a user