@zzzen/pyright-internal 1.2.0-dev.20230723 → 1.2.0-dev.20230730
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/backgroundAnalysisProgram.d.ts +2 -2
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/binder.js +0 -1
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +2 -24
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +5 -9
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +11 -10
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructors.js +25 -5
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/patternMatching.js +24 -0
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +4 -2
- package/dist/analyzer/program.js +31 -25
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +5 -0
- package/dist/analyzer/sourceFile.js +11 -5
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +206 -141
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeGuards.js +1 -1
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +4 -2
- package/dist/analyzer/typeUtils.js +55 -13
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +2 -2
- package/dist/analyzer/types.js +11 -5
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +4 -4
- package/dist/backgroundAnalysisBase.js +6 -6
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/common/configOptions.d.ts +1 -0
- package/dist/common/configOptions.js +5 -1
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/diagnosticRules.d.ts +1 -0
- package/dist/common/diagnosticRules.js +1 -0
- package/dist/common/diagnosticRules.js.map +1 -1
- package/dist/languageService/completionProvider.js +3 -3
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +0 -4
- package/dist/localization/localize.js +0 -1
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +5 -6
- package/dist/localization/package.nls.de.json +5 -6
- package/dist/localization/package.nls.en-us.json +0 -1
- package/dist/localization/package.nls.es.json +5 -6
- package/dist/localization/package.nls.fr.json +5 -6
- package/dist/localization/package.nls.it.json +5 -6
- package/dist/localization/package.nls.ja.json +5 -6
- package/dist/localization/package.nls.ko.json +5 -6
- package/dist/localization/package.nls.pl.json +5 -6
- package/dist/localization/package.nls.pt-br.json +5 -6
- package/dist/localization/package.nls.qps-ploc.json +5 -6
- package/dist/localization/package.nls.ru.json +5 -6
- package/dist/localization/package.nls.tr.json +5 -6
- package/dist/localization/package.nls.zh-cn.json +5 -6
- package/dist/localization/package.nls.zh-tw.json +5 -6
- package/dist/tests/typeEvaluator2.test.js +11 -1
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +13 -3
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +4 -0
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +8 -4
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/package.json +2 -2
@@ -3818,7 +3818,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3818
3818
|
// a descriptor protocol, only 'get' operations are allowed. If it's accessed
|
3819
3819
|
// through the object, all access methods are supported.
|
3820
3820
|
if (isAccessedThroughObject || usage.method === 'get') {
|
3821
|
-
lookupClass =
|
3821
|
+
lookupClass = types_1.ClassType.cloneAsInstance(concreteSubtype.details.effectiveMetaclass);
|
3822
3822
|
isAccessedThroughMetaclass = true;
|
3823
3823
|
}
|
3824
3824
|
else {
|
@@ -4641,7 +4641,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4641
4641
|
const isFinalAnnotation = (0, types_1.isInstantiableClass)(concreteSubtype) && types_1.ClassType.isBuiltIn(concreteSubtype, 'Final');
|
4642
4642
|
const isClassVarAnnotation = (0, types_1.isInstantiableClass)(concreteSubtype) && types_1.ClassType.isBuiltIn(concreteSubtype, 'ClassVar');
|
4643
4643
|
// Inlined TypedDicts are supported only for 'dict' (and not for 'Dict').
|
4644
|
-
|
4644
|
+
// This feature is currently experimental.
|
4645
|
+
const supportsTypedDictTypeArg = AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures &&
|
4646
|
+
(0, types_1.isInstantiableClass)(concreteSubtype) &&
|
4645
4647
|
types_1.ClassType.isBuiltIn(concreteSubtype, 'dict') &&
|
4646
4648
|
!concreteSubtype.aliasName;
|
4647
4649
|
let typeArgs = getTypeArgs(node, flags, {
|
@@ -7654,12 +7656,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7654
7656
|
}
|
7655
7657
|
}
|
7656
7658
|
});
|
7659
|
+
let paramSpecTypeVarContext = [];
|
7657
7660
|
// Handle the assignment of additional arguments that map to a param spec.
|
7658
7661
|
if (matchResults.paramSpecArgList && matchResults.paramSpecTarget) {
|
7659
|
-
|
7662
|
+
const paramSpecArgResult = validateFunctionArgumentsForParamSpec(errorNode, matchResults.paramSpecArgList, matchResults.paramSpecTarget, typeVarContext, typeCondition);
|
7663
|
+
if (paramSpecArgResult.argumentErrors) {
|
7660
7664
|
argumentErrors = true;
|
7661
7665
|
argumentMatchScore += 1;
|
7662
7666
|
}
|
7667
|
+
paramSpecTypeVarContext = paramSpecArgResult.typeVarContexts;
|
7663
7668
|
}
|
7664
7669
|
else if (type.details.paramSpec) {
|
7665
7670
|
if (!sawParamSpecArgs || !sawParamSpecKwargs) {
|
@@ -7713,17 +7718,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7713
7718
|
applyInScopePlaceholders: true,
|
7714
7719
|
});
|
7715
7720
|
specializedReturnType = (0, typeUtils_1.addConditionToType)(specializedReturnType, typeCondition);
|
7721
|
+
// If the function includes a ParamSpec and the captured signature(s) includes
|
7722
|
+
// generic types, we may need to apply those solved TypeVars.
|
7723
|
+
if (paramSpecTypeVarContext.length > 0) {
|
7724
|
+
paramSpecTypeVarContext.forEach((paramSpecTypeVarContext) => {
|
7725
|
+
if (paramSpecTypeVarContext) {
|
7726
|
+
specializedReturnType = (0, typeUtils_1.applySolvedTypeVars)(specializedReturnType, paramSpecTypeVarContext);
|
7727
|
+
}
|
7728
|
+
});
|
7729
|
+
}
|
7716
7730
|
// If the final return type is an unpacked tuple, turn it into a normal (unpacked) tuple.
|
7717
7731
|
if ((0, types_1.isUnpackedClass)(specializedReturnType)) {
|
7718
7732
|
specializedReturnType = types_1.ClassType.cloneForUnpacked(specializedReturnType, /* isUnpackedTuple */ false);
|
7719
7733
|
}
|
7720
|
-
// Handle 'TypeGuard'
|
7721
|
-
//
|
7722
|
-
// narrowed type.
|
7734
|
+
// Handle 'TypeGuard' specially. We'll transform the return type into a 'bool'
|
7735
|
+
// object with a type argument that reflects the narrowed type.
|
7723
7736
|
if ((0, types_1.isClassInstance)(specializedReturnType) &&
|
7724
|
-
types_1.ClassType.isBuiltIn(specializedReturnType,
|
7737
|
+
types_1.ClassType.isBuiltIn(specializedReturnType, 'TypeGuard') &&
|
7725
7738
|
specializedReturnType.typeArguments &&
|
7726
|
-
specializedReturnType.typeArguments.length > 0
|
7739
|
+
specializedReturnType.typeArguments.length > 0 &&
|
7740
|
+
(0, types_1.isClassInstance)(returnType) &&
|
7741
|
+
returnType.typeArguments &&
|
7742
|
+
returnType.typeArguments.length > 0) {
|
7727
7743
|
if (boolClassType && (0, types_1.isInstantiableClass)(boolClassType)) {
|
7728
7744
|
let typeGuardType = specializedReturnType.typeArguments[0];
|
7729
7745
|
// If the first argument is a simple (non-constrained) TypeVar,
|
@@ -7742,7 +7758,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7742
7758
|
]);
|
7743
7759
|
}
|
7744
7760
|
}
|
7745
|
-
|
7761
|
+
let useStrictTypeGuardSemantics = false;
|
7762
|
+
if (AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.enableExperimentalFeatures) {
|
7763
|
+
// Determine the type of the first parameter.
|
7764
|
+
const paramIndex = type.boundToType ? 1 : 0;
|
7765
|
+
if (paramIndex < type.details.parameters.length) {
|
7766
|
+
const paramType = types_1.FunctionType.getEffectiveParameterType(type, paramIndex);
|
7767
|
+
// If the type guard meets the requirements that the first parameter
|
7768
|
+
// type is a proper subtype of the return type, we can use strict
|
7769
|
+
// type guard semantics.
|
7770
|
+
if (assignType(paramType, returnType.typeArguments[0])) {
|
7771
|
+
useStrictTypeGuardSemantics = true;
|
7772
|
+
}
|
7773
|
+
}
|
7774
|
+
}
|
7775
|
+
specializedReturnType = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForTypeGuard(boolClassType, typeGuardType, useStrictTypeGuardSemantics));
|
7746
7776
|
}
|
7747
7777
|
}
|
7748
7778
|
specializedReturnType = adjustCallableReturnType(specializedReturnType);
|
@@ -7837,12 +7867,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7837
7867
|
return validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, signatureContexts[0], conditionFilter);
|
7838
7868
|
}
|
7839
7869
|
const filteredSignatureContexts = [];
|
7870
|
+
const typeVarContexts = [];
|
7840
7871
|
signatureContexts.forEach((context) => {
|
7841
7872
|
// Use speculative mode to avoid emitting errors or caching types.
|
7842
7873
|
useSpeculativeMode(errorNode, () => {
|
7843
|
-
|
7874
|
+
const paramSpecArgResult = validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, context, conditionFilter);
|
7875
|
+
if (!paramSpecArgResult.argumentErrors) {
|
7844
7876
|
filteredSignatureContexts.push(context);
|
7845
7877
|
}
|
7878
|
+
(0, collectionUtils_1.appendArray)(typeVarContexts, paramSpecArgResult.typeVarContexts);
|
7846
7879
|
});
|
7847
7880
|
});
|
7848
7881
|
// Copy back any compatible signature contexts if any were compatible.
|
@@ -7850,109 +7883,121 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7850
7883
|
destTypeVarContext.copySignatureContexts(filteredSignatureContexts);
|
7851
7884
|
}
|
7852
7885
|
// Evaluate non-speculatively to produce a final result and cache types.
|
7853
|
-
|
7886
|
+
const paramSpecArgResult = validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, filteredSignatureContexts.length > 0 ? filteredSignatureContexts[0] : signatureContexts[0], conditionFilter);
|
7887
|
+
return { argumentErrors: paramSpecArgResult.argumentErrors, typeVarContexts };
|
7854
7888
|
}
|
7855
7889
|
function validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, typeVarContext, conditionFilter) {
|
7856
7890
|
var _a;
|
7857
7891
|
const paramSpecType = typeVarContext.getParamSpecType(paramSpec);
|
7858
7892
|
if (!paramSpecType) {
|
7859
7893
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramSpecNotBound().format({ type: printType(paramSpec) }), ((_a = argList[0]) === null || _a === void 0 ? void 0 : _a.valueExpression) || errorNode);
|
7860
|
-
return
|
7894
|
+
return { argumentErrors: true, typeVarContexts: [undefined] };
|
7861
7895
|
}
|
7862
7896
|
const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(errorNode);
|
7863
7897
|
const srcTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeIds)(paramSpecType));
|
7864
7898
|
let reportedArgError = false;
|
7865
|
-
// Build a map of all named parameters.
|
7866
|
-
const paramMap = new Map();
|
7867
|
-
const paramSpecParams = paramSpecType.details.parameters;
|
7868
|
-
paramSpecParams.forEach((param) => {
|
7869
|
-
if (param.name) {
|
7870
|
-
paramMap.set(param.name, param);
|
7871
|
-
}
|
7872
|
-
});
|
7873
|
-
let positionalIndex = 0;
|
7874
|
-
let positionalIndexLimit = paramSpecParams.findIndex((paramInfo) => paramInfo.category !== 0 /* Simple */);
|
7875
|
-
if (positionalIndexLimit < 0) {
|
7876
|
-
positionalIndexLimit = paramSpecParams.length;
|
7877
|
-
}
|
7878
|
-
const argsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 1 /* ArgsList */);
|
7879
|
-
const kwargsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 2 /* KwargsDict */);
|
7880
|
-
const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
|
7881
7899
|
let sawUnpackedListArgument = false;
|
7882
7900
|
let sawUnpackedDictArgument = false;
|
7883
|
-
|
7884
|
-
|
7885
|
-
|
7886
|
-
|
7887
|
-
|
7888
|
-
|
7889
|
-
|
7890
|
-
|
7891
|
-
|
7892
|
-
|
7893
|
-
|
7894
|
-
|
7895
|
-
|
7896
|
-
|
7897
|
-
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramNameMissing().format({ name: arg.name.value }), arg.name || errorNode);
|
7898
|
-
reportedArgError = true;
|
7901
|
+
let paramMap = new Map();
|
7902
|
+
// We'll use two passes in case there are type variables that depend
|
7903
|
+
// on later arguments.
|
7904
|
+
const passCount = 2;
|
7905
|
+
for (let i = 0; i < passCount; i++) {
|
7906
|
+
// Unless we're on the last pass, use speculative mode to suppress
|
7907
|
+
// any diagnostics.
|
7908
|
+
useSpeculativeMode(i < passCount - 1 ? errorNode : undefined, () => {
|
7909
|
+
// Build a map of all named parameters.
|
7910
|
+
paramMap = new Map();
|
7911
|
+
const paramSpecParams = paramSpecType.details.parameters;
|
7912
|
+
paramSpecParams.forEach((param) => {
|
7913
|
+
if (param.name) {
|
7914
|
+
paramMap.set(param.name, param);
|
7899
7915
|
}
|
7900
|
-
}
|
7901
|
-
|
7902
|
-
|
7903
|
-
|
7904
|
-
|
7905
|
-
|
7906
|
-
|
7916
|
+
});
|
7917
|
+
let positionalIndex = 0;
|
7918
|
+
let positionalIndexLimit = paramSpecParams.findIndex((paramInfo) => paramInfo.category !== 0 /* Simple */);
|
7919
|
+
if (positionalIndexLimit < 0) {
|
7920
|
+
positionalIndexLimit = paramSpecParams.length;
|
7921
|
+
}
|
7922
|
+
const argsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 1 /* ArgsList */);
|
7923
|
+
const kwargsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 2 /* KwargsDict */);
|
7924
|
+
const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
|
7925
|
+
argList.forEach((arg) => {
|
7926
|
+
var _a;
|
7927
|
+
if (arg.argumentCategory === 0 /* Simple */) {
|
7928
|
+
let paramType;
|
7929
|
+
if (arg.name) {
|
7930
|
+
const paramInfo = paramMap.get(arg.name.value);
|
7931
|
+
if (paramInfo) {
|
7932
|
+
paramType = paramInfo.type;
|
7933
|
+
paramMap.delete(arg.name.value);
|
7934
|
+
}
|
7935
|
+
else if (kwargsParam) {
|
7936
|
+
paramType = kwargsParam.type;
|
7937
|
+
}
|
7938
|
+
else {
|
7939
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramNameMissing().format({ name: arg.name.value }), arg.name || errorNode);
|
7940
|
+
reportedArgError = true;
|
7941
|
+
}
|
7942
|
+
}
|
7943
|
+
else {
|
7944
|
+
if (positionalIndex < positionalIndexLimit) {
|
7945
|
+
const paramInfo = paramSpecParams[positionalIndex];
|
7946
|
+
paramType = paramInfo.type;
|
7947
|
+
if (paramInfo.name) {
|
7948
|
+
paramMap.delete(paramInfo.name);
|
7949
|
+
}
|
7950
|
+
}
|
7951
|
+
else if (argsParam) {
|
7952
|
+
paramType = argsParam.type;
|
7953
|
+
}
|
7954
|
+
else {
|
7955
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, paramSpecParams.length === 1
|
7956
|
+
? localize_1.Localizer.Diagnostic.argPositionalExpectedOne()
|
7957
|
+
: localize_1.Localizer.Diagnostic.argPositionalExpectedCount().format({
|
7958
|
+
expected: paramSpecParams.length,
|
7959
|
+
}), (_a = arg.valueExpression) !== null && _a !== void 0 ? _a : errorNode);
|
7960
|
+
reportedArgError = true;
|
7961
|
+
}
|
7962
|
+
positionalIndex++;
|
7963
|
+
}
|
7964
|
+
if (paramType) {
|
7965
|
+
const argResult = validateArgType({
|
7966
|
+
paramCategory: 0 /* Simple */,
|
7967
|
+
paramType: (0, typeUtils_1.transformExpectedType)(paramType, liveTypeVarScopes,
|
7968
|
+
/* usageOffset */ undefined),
|
7969
|
+
requiresTypeVarMatching: false,
|
7970
|
+
argument: arg,
|
7971
|
+
errorNode: arg.valueExpression || errorNode,
|
7972
|
+
}, srcTypeVarContext, signatureTracker,
|
7973
|
+
/* functionType */ undefined, { conditionFilter });
|
7974
|
+
if (!argResult.isCompatible) {
|
7975
|
+
reportedArgError = true;
|
7976
|
+
}
|
7907
7977
|
}
|
7908
7978
|
}
|
7909
|
-
else if (
|
7910
|
-
|
7979
|
+
else if (arg.argumentCategory === 1 /* UnpackedList */) {
|
7980
|
+
sawUnpackedListArgument = true;
|
7981
|
+
// See if there is an *args parameter.
|
7982
|
+
const argsParam = paramSpecParams.find((param) => param.category === 1 /* ArgsList */ && param.name);
|
7983
|
+
if (argsParam && paramMap.has(argsParam.name)) {
|
7984
|
+
// TODO - validate args type
|
7985
|
+
paramMap.delete(argsParam.name);
|
7986
|
+
}
|
7911
7987
|
}
|
7912
7988
|
else {
|
7913
|
-
|
7914
|
-
|
7915
|
-
|
7916
|
-
|
7917
|
-
|
7918
|
-
|
7919
|
-
|
7920
|
-
|
7921
|
-
}
|
7922
|
-
if (paramType) {
|
7923
|
-
const argResult = validateArgType({
|
7924
|
-
paramCategory: 0 /* Simple */,
|
7925
|
-
paramType: (0, typeUtils_1.transformExpectedType)(paramType, liveTypeVarScopes, /* usageOffset */ undefined),
|
7926
|
-
requiresTypeVarMatching: false,
|
7927
|
-
argument: arg,
|
7928
|
-
errorNode: arg.valueExpression || errorNode,
|
7929
|
-
}, srcTypeVarContext, signatureTracker,
|
7930
|
-
/* functionType */ undefined, { conditionFilter });
|
7931
|
-
if (!argResult.isCompatible) {
|
7932
|
-
reportedArgError = true;
|
7989
|
+
sawUnpackedDictArgument = true;
|
7990
|
+
(0, debug_1.assert)(arg.argumentCategory === 2 /* UnpackedDictionary */);
|
7991
|
+
// See if there is an *kwargs parameter.
|
7992
|
+
const kwargsParam = paramSpecParams.find((param) => param.category === 2 /* KwargsDict */);
|
7993
|
+
if (kwargsParam && paramMap.has(kwargsParam.name)) {
|
7994
|
+
// TODO - validate kwargs type
|
7995
|
+
paramMap.delete(kwargsParam.name);
|
7996
|
+
}
|
7933
7997
|
}
|
7934
|
-
}
|
7935
|
-
}
|
7936
|
-
|
7937
|
-
sawUnpackedListArgument = true;
|
7938
|
-
// See if there is an *args parameter.
|
7939
|
-
const argsParam = paramSpecParams.find((param) => param.category === 1 /* ArgsList */ && param.name);
|
7940
|
-
if (argsParam && paramMap.has(argsParam.name)) {
|
7941
|
-
// TODO - validate args type
|
7942
|
-
paramMap.delete(argsParam.name);
|
7943
|
-
}
|
7944
|
-
}
|
7945
|
-
else {
|
7946
|
-
sawUnpackedDictArgument = true;
|
7947
|
-
(0, debug_1.assert)(arg.argumentCategory === 2 /* UnpackedDictionary */);
|
7948
|
-
// See if there is an *kwargs parameter.
|
7949
|
-
const kwargsParam = paramSpecParams.find((param) => param.category === 2 /* KwargsDict */);
|
7950
|
-
if (kwargsParam && paramMap.has(kwargsParam.name)) {
|
7951
|
-
// TODO - validate kwargs type
|
7952
|
-
paramMap.delete(kwargsParam.name);
|
7953
|
-
}
|
7954
|
-
}
|
7955
|
-
});
|
7998
|
+
});
|
7999
|
+
});
|
8000
|
+
}
|
7956
8001
|
// Report any missing parameters.
|
7957
8002
|
if (!reportedArgError) {
|
7958
8003
|
let unassignedParams = Array.from(paramMap.keys());
|
@@ -7975,7 +8020,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7975
8020
|
if (!reportedArgError) {
|
7976
8021
|
(0, typeUtils_1.applySourceContextTypeVarsToSignature)(typeVarContext, srcTypeVarContext);
|
7977
8022
|
}
|
7978
|
-
return
|
8023
|
+
return {
|
8024
|
+
argumentErrors: reportedArgError,
|
8025
|
+
typeVarContexts: [reportedArgError ? srcTypeVarContext : undefined],
|
8026
|
+
};
|
7979
8027
|
}
|
7980
8028
|
function validateArgType(argParam, typeVarContext, signatureTracker, typeResult, options) {
|
7981
8029
|
var _a;
|
@@ -10563,7 +10611,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10563
10611
|
['TypeAlias', { alias: '', module: 'builtins' }],
|
10564
10612
|
['Concatenate', { alias: '', module: 'builtins' }],
|
10565
10613
|
['TypeGuard', { alias: '', module: 'builtins' }],
|
10566
|
-
['StrictTypeGuard', { alias: '', module: 'builtins' }],
|
10567
10614
|
['Unpack', { alias: '', module: 'builtins' }],
|
10568
10615
|
['Required', { alias: '', module: 'builtins' }],
|
10569
10616
|
['NotRequired', { alias: '', module: 'builtins' }],
|
@@ -10573,7 +10620,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10573
10620
|
['LiteralString', { alias: '', module: 'builtins' }],
|
10574
10621
|
['ReadOnly', { alias: '', module: 'builtins' }],
|
10575
10622
|
]);
|
10576
|
-
|
10623
|
+
let aliasMapEntry = specialTypes.get(assignedName);
|
10624
|
+
// Support ReadOnly only as an experimental feature.
|
10625
|
+
if (assignedName === 'ReadOnly' &&
|
10626
|
+
!AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures) {
|
10627
|
+
aliasMapEntry = undefined;
|
10628
|
+
}
|
10577
10629
|
if (aliasMapEntry) {
|
10578
10630
|
const cachedType = readTypeCache(node, 0 /* None */);
|
10579
10631
|
if (cachedType) {
|
@@ -12454,9 +12506,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12454
12506
|
}
|
12455
12507
|
return inferredReturnType ? { type: inferredReturnType, isIncomplete } : undefined;
|
12456
12508
|
}
|
12457
|
-
// Determines whether the
|
12458
|
-
// and the exception type raised is a NotImplementedError
|
12459
|
-
// used for abstract methods
|
12509
|
+
// Determines whether the method consists only of a "raise" statement
|
12510
|
+
// and the exception type raised is a NotImplementedError or a subclass
|
12511
|
+
// thereof. This is commonly used for abstract methods.
|
12460
12512
|
function methodAlwaysRaisesNotImplemented(functionDecl) {
|
12461
12513
|
if (!functionDecl ||
|
12462
12514
|
!functionDecl.isMethod ||
|
@@ -12475,7 +12527,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12475
12527
|
: (0, types_1.isClassInstance)(raiseType)
|
12476
12528
|
? raiseType
|
12477
12529
|
: undefined;
|
12478
|
-
if (!classType || !
|
12530
|
+
if (!classType || !(0, typeUtils_1.derivesFromStdlibClass)(classType, 'NotImplementedError')) {
|
12479
12531
|
return false;
|
12480
12532
|
}
|
12481
12533
|
}
|
@@ -13377,18 +13429,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13377
13429
|
case 'Concatenate': {
|
13378
13430
|
return { type: createConcatenateType(errorNode, classType, typeArgs) };
|
13379
13431
|
}
|
13380
|
-
case 'TypeGuard':
|
13381
|
-
case 'StrictTypeGuard': {
|
13432
|
+
case 'TypeGuard': {
|
13382
13433
|
return { type: createTypeGuardType(errorNode, classType, typeArgs, flags) };
|
13383
13434
|
}
|
13384
13435
|
case 'Unpack': {
|
13385
13436
|
return { type: createUnpackType(classType, errorNode, typeArgs, flags) };
|
13386
13437
|
}
|
13387
13438
|
case 'Required':
|
13388
|
-
case 'NotRequired':
|
13389
|
-
case 'ReadOnly': {
|
13439
|
+
case 'NotRequired': {
|
13390
13440
|
return createRequiredOrReadOnlyType(classType, errorNode, typeArgs, flags);
|
13391
13441
|
}
|
13442
|
+
case 'ReadOnly': {
|
13443
|
+
if (AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.enableExperimentalFeatures) {
|
13444
|
+
return createRequiredOrReadOnlyType(classType, errorNode, typeArgs, flags);
|
13445
|
+
}
|
13446
|
+
break;
|
13447
|
+
}
|
13392
13448
|
case 'Self': {
|
13393
13449
|
return { type: createSelfType(classType, errorNode, typeArgs) };
|
13394
13450
|
}
|
@@ -15260,8 +15316,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15260
15316
|
const typeVarContext = new typeVarContext_1.TypeVarContext();
|
15261
15317
|
let isAssignable = true;
|
15262
15318
|
destType.details.fields.forEach((symbol, name) => {
|
15263
|
-
|
15264
|
-
if (!isAssignable || !symbol.isClassMember() || symbol.isIgnoredForProtocolMatch()) {
|
15319
|
+
if (!isAssignable || symbol.isIgnoredForProtocolMatch()) {
|
15265
15320
|
return;
|
15266
15321
|
}
|
15267
15322
|
// Constructor methods are exempt from variance calculations.
|
@@ -15270,32 +15325,37 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15270
15325
|
}
|
15271
15326
|
const memberInfo = (0, typeUtils_1.lookUpClassMember)(srcType, name);
|
15272
15327
|
(0, debug_1.assert)(memberInfo !== undefined);
|
15273
|
-
let destMemberType = (
|
15274
|
-
|
15275
|
-
|
15276
|
-
|
15277
|
-
|
15278
|
-
|
15279
|
-
|
15280
|
-
|
15281
|
-
|
15282
|
-
|
15283
|
-
|
15284
|
-
isAssignable = false;
|
15285
|
-
}
|
15328
|
+
let destMemberType = getEffectiveTypeOfSymbol(symbol);
|
15329
|
+
const srcMemberType = getTypeOfMember(memberInfo);
|
15330
|
+
destMemberType = (0, typeUtils_1.partiallySpecializeType)(destMemberType, destType);
|
15331
|
+
// Properties require special processing.
|
15332
|
+
if ((0, types_1.isClassInstance)(destMemberType) &&
|
15333
|
+
types_1.ClassType.isPropertyClass(destMemberType) &&
|
15334
|
+
(0, types_1.isClassInstance)(srcMemberType) &&
|
15335
|
+
types_1.ClassType.isPropertyClass(srcMemberType)) {
|
15336
|
+
if (!(0, properties_1.assignProperty)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destMemberType), types_1.ClassType.cloneAsInstantiable(srcMemberType), destType, srcType, diag, typeVarContext,
|
15337
|
+
/* selfTypeVarContext */ undefined, recursionCount)) {
|
15338
|
+
isAssignable = false;
|
15286
15339
|
}
|
15287
|
-
|
15288
|
-
|
15340
|
+
}
|
15341
|
+
else {
|
15342
|
+
const primaryDecl = symbol.getDeclarations()[0];
|
15343
|
+
let flags = 0 /* Default */;
|
15344
|
+
if ((primaryDecl === null || primaryDecl === void 0 ? void 0 : primaryDecl.type) === 1 /* Variable */ &&
|
15345
|
+
!isFinalVariableDeclaration(primaryDecl) &&
|
15346
|
+
!types_1.ClassType.isFrozenDataClass(destType)) {
|
15289
15347
|
// Class and instance variables that are mutable need to
|
15290
|
-
// enforce invariance.
|
15291
|
-
|
15292
|
-
|
15293
|
-
|
15294
|
-
|
15295
|
-
/* srcTypeVarContext */ undefined, flags, recursionCount)) {
|
15296
|
-
isAssignable = false;
|
15348
|
+
// enforce invariance. We will exempt variables that are
|
15349
|
+
// private or protected, since these are presumably
|
15350
|
+
// not modifiable outside of the class.
|
15351
|
+
if (!(0, symbolNameUtils_1.isPrivateOrProtectedName)(name)) {
|
15352
|
+
flags |= 1 /* EnforceInvariance */;
|
15297
15353
|
}
|
15298
15354
|
}
|
15355
|
+
if (!assignType(destMemberType, srcMemberType, diag, typeVarContext,
|
15356
|
+
/* srcTypeVarContext */ undefined, flags, recursionCount)) {
|
15357
|
+
isAssignable = false;
|
15358
|
+
}
|
15299
15359
|
}
|
15300
15360
|
});
|
15301
15361
|
if (!isAssignable) {
|
@@ -15927,7 +15987,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15927
15987
|
return !isLiteral;
|
15928
15988
|
}
|
15929
15989
|
}
|
15930
|
-
else if (types_1.ClassType.isBuiltIn(destType,
|
15990
|
+
else if (types_1.ClassType.isBuiltIn(destType, 'TypeGuard')) {
|
15931
15991
|
// All the source to be a "bool".
|
15932
15992
|
if ((originalFlags & 64 /* AllowBoolTypeGuard */) !== 0) {
|
15933
15993
|
if ((0, types_1.isClassInstance)(srcType) && types_1.ClassType.isBuiltIn(srcType, 'bool')) {
|
@@ -17068,7 +17128,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17068
17128
|
// Handle the special case where the return type is a TypeGuard[T].
|
17069
17129
|
// This should also act as a bool, since that's its type at runtime.
|
17070
17130
|
if ((0, types_1.isClassInstance)(srcReturnType) &&
|
17071
|
-
types_1.ClassType.isBuiltIn(srcReturnType,
|
17131
|
+
types_1.ClassType.isBuiltIn(srcReturnType, 'TypeGuard') &&
|
17072
17132
|
boolClassType &&
|
17073
17133
|
(0, types_1.isInstantiableClass)(boolClassType)) {
|
17074
17134
|
if (assignType(destReturnType, types_1.ClassType.cloneAsInstance(boolClassType), returnDiag === null || returnDiag === void 0 ? void 0 : returnDiag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
@@ -17118,7 +17178,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17118
17178
|
const typeParam = assignedType.details.typeParameters[index];
|
17119
17179
|
const expectedTypeArgType = typeVarContext.getPrimarySignature().getTypeVarType(typeParam);
|
17120
17180
|
if (expectedTypeArgType) {
|
17121
|
-
if ((0,
|
17181
|
+
if ((0, typeUtils_1.containsAnyRecursive)(expectedTypeArgType) || (0, types_1.isAnyOrUnknown)(typeArg)) {
|
17122
17182
|
replacedTypeArg = true;
|
17123
17183
|
return expectedTypeArgType;
|
17124
17184
|
}
|
@@ -17145,12 +17205,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17145
17205
|
const narrowedType = (0, typeUtils_1.mapSubtypes)(assignedType, (assignedSubtype) => {
|
17146
17206
|
const narrowedSubtype = (0, typeUtils_1.mapSubtypes)(declaredType, (declaredSubtype) => {
|
17147
17207
|
// We can't narrow "Any".
|
17148
|
-
if ((0, types_1.isAnyOrUnknown)(
|
17149
|
-
return
|
17208
|
+
if ((0, types_1.isAnyOrUnknown)(declaredSubtype)) {
|
17209
|
+
return declaredSubtype;
|
17150
17210
|
}
|
17151
17211
|
if (assignType(declaredSubtype, assignedSubtype)) {
|
17152
17212
|
// If the source is generic and has unspecified type arguments,
|
17153
|
-
// see if we can determine
|
17213
|
+
// see if we can determine them based on the declared type.
|
17154
17214
|
if ((0, types_1.isInstantiableClass)(declaredSubtype) && (0, types_1.isInstantiableClass)(assignedSubtype)) {
|
17155
17215
|
const result = replaceTypeArgsWithAny(node, declaredSubtype, assignedSubtype);
|
17156
17216
|
if (result) {
|
@@ -17168,6 +17228,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17168
17228
|
// use the concrete type.
|
17169
17229
|
return declaredSubtype;
|
17170
17230
|
}
|
17231
|
+
// If the assigned subtype is Any, stick with the declared type.
|
17232
|
+
if ((0, types_1.isAny)(assignedSubtype)) {
|
17233
|
+
return declaredSubtype;
|
17234
|
+
}
|
17235
|
+
// If the declared type doesn't contain any `Any` but the assigned
|
17236
|
+
// type does, stick with the declared type.
|
17237
|
+
if ((0, typeUtils_1.containsAnyRecursive)(assignedSubtype) && !(0, typeUtils_1.containsAnyRecursive)(declaredSubtype)) {
|
17238
|
+
return declaredSubtype;
|
17239
|
+
}
|
17171
17240
|
return assignedSubtype;
|
17172
17241
|
}
|
17173
17242
|
return undefined;
|
@@ -17179,16 +17248,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17179
17248
|
}
|
17180
17249
|
return narrowedSubtype;
|
17181
17250
|
});
|
17182
|
-
// If the result of narrowing is Any, stick with the declared (unnarrowed) type.
|
17183
17251
|
// If the result of narrowing is an Unknown that is incomplete, propagate the
|
17184
17252
|
// incomplete type for the benefit of code flow analysis.
|
17185
17253
|
// If the result of narrowing is a complete Unknown, combine the Unknown type
|
17186
17254
|
// with the declared type. In strict mode, this will retain the "unknown type"
|
17187
17255
|
// diagnostics while still providing reasonable completion suggestions.
|
17188
|
-
if ((0,
|
17189
|
-
return declaredType;
|
17190
|
-
}
|
17191
|
-
else if ((0, typeUtils_1.isIncompleteUnknown)(narrowedType)) {
|
17256
|
+
if ((0, typeUtils_1.isIncompleteUnknown)(narrowedType)) {
|
17192
17257
|
return narrowedType;
|
17193
17258
|
}
|
17194
17259
|
else if ((0, types_1.isUnknown)(narrowedType)) {
|