@zzzen/pyright-internal 1.2.0-dev.20230305 → 1.2.0-dev.20230319
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 +1 -1
- package/dist/analyzer/backgroundAnalysisProgram.js +1 -1
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/binder.js +23 -3
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/cacheManager.d.ts +4 -0
- package/dist/analyzer/cacheManager.js +13 -0
- package/dist/analyzer/cacheManager.js.map +1 -1
- package/dist/analyzer/checker.d.ts +2 -1
- package/dist/analyzer/checker.js +73 -29
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +17 -11
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/commentUtils.js +11 -1
- package/dist/analyzer/commentUtils.js.map +1 -1
- package/dist/analyzer/constructorTransform.d.ts +1 -0
- package/dist/analyzer/constructorTransform.js +19 -2
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +40 -40
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/patternMatching.js +13 -11
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +1 -1
- package/dist/analyzer/program.js +21 -19
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js +0 -1
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/service.d.ts +2 -1
- package/dist/analyzer/service.js +9 -3
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +2 -2
- package/dist/analyzer/sourceFile.js +14 -3
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceFileInfoUtils.d.ts +1 -0
- package/dist/analyzer/sourceFileInfoUtils.js +17 -1
- package/dist/analyzer/sourceFileInfoUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +195 -87
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +1 -2
- package/dist/analyzer/typeEvaluatorTypes.js +0 -3
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typePrinter.js +63 -55
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeStubWriter.js +2 -0
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +1 -0
- package/dist/analyzer/typeUtils.js +29 -3
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.d.ts +2 -1
- package/dist/analyzer/typedDicts.js +84 -40
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +5 -1
- package/dist/analyzer/types.js +11 -1
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +82 -4
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/commands/quickActionCommand.js +2 -2
- package/dist/commands/quickActionCommand.js.map +1 -1
- package/dist/common/configOptions.d.ts +1 -0
- package/dist/common/configOptions.js +4 -0
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/console.d.ts +1 -0
- package/dist/common/console.js +19 -1
- package/dist/common/console.js.map +1 -1
- package/dist/common/diagnosticRules.d.ts +2 -1
- package/dist/common/diagnosticRules.js +1 -0
- package/dist/common/diagnosticRules.js.map +1 -1
- package/dist/common/extensibility.d.ts +2 -2
- package/dist/common/extensibility.js +25 -1
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/extensions.js +3 -1
- package/dist/common/extensions.js.map +1 -1
- package/dist/languageServerBase.d.ts +21 -46
- package/dist/languageServerBase.js +112 -152
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/analyzerServiceExecutor.d.ts +4 -3
- package/dist/languageService/analyzerServiceExecutor.js +9 -7
- package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
- package/dist/languageService/codeActionProvider.d.ts +2 -2
- package/dist/languageService/codeActionProvider.js +4 -4
- package/dist/languageService/codeActionProvider.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +4 -2
- package/dist/languageService/completionProvider.js +209 -156
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.js +1 -1
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.d.ts +2 -1
- package/dist/languageService/documentSymbolCollector.js +23 -2
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +2 -1
- package/dist/languageService/hoverProvider.js +21 -5
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/referencesProvider.d.ts +3 -2
- package/dist/languageService/referencesProvider.js +4 -4
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/renameModuleProvider.d.ts +1 -1
- package/dist/languageService/renameModuleProvider.js +8 -1
- package/dist/languageService/renameModuleProvider.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +2 -1
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/localization/localize.d.ts +17 -6
- package/dist/localization/localize.js +6 -4
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +8 -6
- package/dist/parser/parser.js +24 -7
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/tokenizer.js +1 -1
- package/dist/server.d.ts +3 -2
- package/dist/server.js +1 -4
- package/dist/server.js.map +1 -1
- package/dist/tests/cacheManager.test.d.ts +1 -0
- package/dist/tests/cacheManager.test.js +69 -0
- package/dist/tests/cacheManager.test.js.map +1 -0
- package/dist/tests/checker.test.js +2 -2
- package/dist/tests/completions.test.js +445 -0
- package/dist/tests/completions.test.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.expression.fourslash.js +13 -3
- package/dist/tests/fourslash/completions.dictionary.keys.expression.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.js +7 -2
- package/dist/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.js.map +1 -1
- package/dist/tests/fourslash/missingTypeStub.command.trycatchImport.fourslash.d.ts +7 -0
- package/dist/tests/fourslash/missingTypeStub.command.trycatchImport.fourslash.js +45 -0
- package/dist/tests/fourslash/missingTypeStub.command.trycatchImport.fourslash.js.map +1 -0
- package/dist/tests/harness/fourslash/testLanguageService.d.ts +7 -6
- package/dist/tests/harness/fourslash/testLanguageService.js +14 -13
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.d.ts +5 -4
- package/dist/tests/harness/fourslash/testState.js +14 -13
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/hoverProvider.test.js +1 -1
- package/dist/tests/hoverProvider.test.js.map +1 -1
- package/dist/tests/moveSymbol.misc.test.js +27 -0
- package/dist/tests/moveSymbol.misc.test.js.map +1 -1
- package/dist/tests/service.test.js +4 -4
- package/dist/tests/service.test.js.map +1 -1
- package/dist/tests/signatureHelp.test.js +2 -2
- package/dist/tests/signatureHelp.test.js.map +1 -1
- package/dist/tests/sourceFile.test.js +3 -3
- package/dist/tests/sourceFile.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +4 -0
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +6 -2
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +1 -1
- package/dist/tests/typeEvaluator4.test.js +5 -1
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +12 -0
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/workspaceEditUtils.test.js +2 -2
- package/dist/tests/workspaceEditUtils.test.js.map +1 -1
- package/dist/workspaceFactory.d.ts +72 -0
- package/dist/workspaceFactory.js +421 -0
- package/dist/workspaceFactory.js.map +1 -0
- package/package.json +4 -4
- package/dist/workspaceMap.d.ts +0 -14
- package/dist/workspaceMap.js +0 -172
- package/dist/workspaceMap.js.map +0 -1
@@ -253,6 +253,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
253
253
|
let strClassType;
|
254
254
|
let dictClassType;
|
255
255
|
let typedDictClassType;
|
256
|
+
let typedDictPrivateClassType;
|
256
257
|
let printExpressionSpaceCount = 0;
|
257
258
|
let incompleteGenerationCount = 0;
|
258
259
|
const returnTypeInferenceContextStack = [];
|
@@ -500,7 +501,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
500
501
|
intClassType = getBuiltInType(node, 'int');
|
501
502
|
strClassType = getBuiltInType(node, 'str');
|
502
503
|
dictClassType = getBuiltInType(node, 'dict');
|
503
|
-
typedDictClassType = getTypingType(node, '
|
504
|
+
typedDictClassType = getTypingType(node, 'TypedDict');
|
505
|
+
typedDictPrivateClassType = getTypingType(node, '_TypedDict');
|
504
506
|
}
|
505
507
|
}
|
506
508
|
function getTypeOfExpression(node, flags = 0 /* None */, inferenceContext) {
|
@@ -703,11 +705,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
703
705
|
}
|
704
706
|
}
|
705
707
|
}
|
706
|
-
if (flags & 65536 /* DisallowRecursiveTypeAliasPlaceholder */) {
|
707
|
-
if ((0, types_1.isTypeVar)(typeResult.type) && (0, typeUtils_1.isTypeAliasPlaceholder)(typeResult.type)) {
|
708
|
-
typeResult.type.details.illegalRecursionDetected = true;
|
709
|
-
}
|
710
|
-
}
|
711
708
|
writeTypeCache(node, typeResult, flags, inferenceContext, /* allowSpeculativeCaching */ true);
|
712
709
|
if (inferenceContext &&
|
713
710
|
!(0, types_1.isAnyOrUnknown)(inferenceContext.expectedType) &&
|
@@ -944,7 +941,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
944
941
|
return getTypeOfAnnotation(paramTypeNode, {
|
945
942
|
associateTypeVarsWithScope: true,
|
946
943
|
allowTypeVarTuple: paramCategory === 1 /* VarArgList */,
|
947
|
-
disallowRecursiveTypeAlias: true,
|
948
944
|
allowUnpackedTypedDict: paramCategory === 2 /* VarArgDictionary */,
|
949
945
|
allowUnpackedTuple: paramCategory === 1 /* VarArgList */,
|
950
946
|
});
|
@@ -988,9 +984,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
988
984
|
else {
|
989
985
|
evaluatorFlags |= 4096 /* DisallowTypeVarsWithoutScopeId */;
|
990
986
|
}
|
991
|
-
if (options === null || options === void 0 ? void 0 : options.disallowRecursiveTypeAlias) {
|
992
|
-
evaluatorFlags |= 65536 /* DisallowRecursiveTypeAliasPlaceholder */;
|
993
|
-
}
|
994
987
|
if (options === null || options === void 0 ? void 0 : options.allowUnpackedTypedDict) {
|
995
988
|
evaluatorFlags |= 8388608 /* AllowUnpackedTypedDict */;
|
996
989
|
}
|
@@ -1842,7 +1835,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1842
1835
|
return isTypeHashable;
|
1843
1836
|
}
|
1844
1837
|
function getTypedDictClassType() {
|
1845
|
-
return
|
1838
|
+
return typedDictPrivateClassType;
|
1846
1839
|
}
|
1847
1840
|
function getTupleClassType() {
|
1848
1841
|
return tupleClassType;
|
@@ -4405,7 +4398,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4405
4398
|
if (param.details.isParamSpec && index < typeArgs.length) {
|
4406
4399
|
const typeArgType = typeArgs[index].type;
|
4407
4400
|
if (typeArgs[index].typeList) {
|
4408
|
-
const functionType = types_1.FunctionType.
|
4401
|
+
const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* ParamSpecValue */);
|
4409
4402
|
types_1.TypeBase.setSpecialForm(functionType);
|
4410
4403
|
typeArgs[index].typeList.forEach((paramType, paramIndex) => {
|
4411
4404
|
types_1.FunctionType.addParameter(functionType, {
|
@@ -4451,7 +4444,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4451
4444
|
(0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, functionType, diag, typeVarContext, 128 /* RetainLiteralsForTypeVar */);
|
4452
4445
|
}
|
4453
4446
|
else if ((0, typeUtils_1.isEllipsisType)(typeArgType)) {
|
4454
|
-
const functionType = types_1.FunctionType.
|
4447
|
+
const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* ParamSpecValue */ | 32768 /* SkipArgsKwargsCompatibilityCheck */);
|
4455
4448
|
types_1.TypeBase.setSpecialForm(functionType);
|
4456
4449
|
types_1.FunctionType.addDefaultParameters(functionType);
|
4457
4450
|
(0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, functionType, diag, typeVarContext);
|
@@ -4538,7 +4531,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4538
4531
|
type: printType(unexpandedSubtype),
|
4539
4532
|
}), node.baseExpression);
|
4540
4533
|
// Evaluate the index expressions as though they are type arguments for error-reporting.
|
4541
|
-
getTypeArgs(node, flags
|
4534
|
+
getTypeArgs(node, flags);
|
4542
4535
|
return types_1.UnknownType.create();
|
4543
4536
|
}
|
4544
4537
|
}
|
@@ -4546,10 +4539,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4546
4539
|
// See if the class has a custom metaclass that supports __getitem__, etc.
|
4547
4540
|
if (concreteSubtype.details.effectiveMetaclass &&
|
4548
4541
|
(0, types_1.isInstantiableClass)(concreteSubtype.details.effectiveMetaclass) &&
|
4549
|
-
!types_1.ClassType.isBuiltIn(concreteSubtype.details.effectiveMetaclass, ['type', '_InitVarMeta'])
|
4542
|
+
!types_1.ClassType.isBuiltIn(concreteSubtype.details.effectiveMetaclass, ['type', '_InitVarMeta']) &&
|
4543
|
+
(flags & 128 /* ExpectingType */) === 0) {
|
4550
4544
|
const itemMethodType = getTypeOfClassMember(node, concreteSubtype, getIndexAccessMagicMethodName(usage),
|
4551
4545
|
/* usage */ undefined,
|
4552
4546
|
/* diag */ undefined, 64 /* SkipAttributeAccessOverride */ | 32 /* ConsiderMetaclassOnly */);
|
4547
|
+
if (flags & 256 /* ExpectingTypeAnnotation */) {
|
4548
|
+
// If the class doesn't derive from Generic, a type argument should not be allowed.
|
4549
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeArgsExpectingNone().format({
|
4550
|
+
name: printType(types_1.ClassType.cloneAsInstance(concreteSubtype)),
|
4551
|
+
}), node);
|
4552
|
+
}
|
4553
4553
|
if (itemMethodType) {
|
4554
4554
|
return getTypeOfIndexedObjectOrClass(node, concreteSubtype, usage).type;
|
4555
4555
|
}
|
@@ -4593,7 +4593,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4593
4593
|
types_1.ClassType.isPartiallyEvaluated(concreteSubtype);
|
4594
4594
|
const isFinalAnnotation = (0, types_1.isInstantiableClass)(concreteSubtype) && types_1.ClassType.isBuiltIn(concreteSubtype, 'Final');
|
4595
4595
|
const isClassVarAnnotation = (0, types_1.isInstantiableClass)(concreteSubtype) && types_1.ClassType.isBuiltIn(concreteSubtype, 'ClassVar');
|
4596
|
-
|
4596
|
+
// Inlined TypedDicts are supported only for 'dict' (and not for 'Dict').
|
4597
|
+
const supportsTypedDictTypeArg = (0, types_1.isInstantiableClass)(concreteSubtype) &&
|
4598
|
+
types_1.ClassType.isBuiltIn(concreteSubtype, 'dict') &&
|
4599
|
+
!concreteSubtype.aliasName;
|
4600
|
+
let typeArgs = getTypeArgs(node, flags, {
|
4601
|
+
isAnnotatedClass,
|
4602
|
+
hasCustomClassGetItem: hasCustomClassGetItem || !isGenericClass,
|
4603
|
+
isFinalAnnotation,
|
4604
|
+
isClassVarAnnotation,
|
4605
|
+
supportsTypedDictTypeArg,
|
4606
|
+
});
|
4597
4607
|
if (!isAnnotatedClass) {
|
4598
4608
|
typeArgs = adjustTypeArgumentsForVariadicTypeVar(typeArgs, concreteSubtype.details.typeParameters, node);
|
4599
4609
|
}
|
@@ -4945,18 +4955,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4945
4955
|
isIncomplete: !!callResult.isTypeIncomplete,
|
4946
4956
|
};
|
4947
4957
|
}
|
4948
|
-
function getTypeArgs(node, flags,
|
4958
|
+
function getTypeArgs(node, flags, options) {
|
4949
4959
|
const typeArgs = [];
|
4950
4960
|
let adjFlags = flags;
|
4951
|
-
if (isFinalAnnotation || isClassVarAnnotation) {
|
4961
|
+
if ((options === null || options === void 0 ? void 0 : options.isFinalAnnotation) || (options === null || options === void 0 ? void 0 : options.isClassVarAnnotation)) {
|
4952
4962
|
adjFlags |= 131072 /* DisallowClassVar */ | 16 /* DisallowFinal */;
|
4953
4963
|
}
|
4954
4964
|
else {
|
4955
4965
|
adjFlags &= ~(2 /* DoNotSpecialize */ |
|
4956
4966
|
32 /* DisallowParamSpec */ |
|
4957
4967
|
64 /* DisallowTypeVarTuple */ |
|
4958
|
-
1048576 /* AllowRequired */
|
4959
|
-
|
4968
|
+
1048576 /* AllowRequired */ |
|
4969
|
+
16384 /* EnforceTypeVarVarianceConsistency */);
|
4970
|
+
if (!(options === null || options === void 0 ? void 0 : options.isAnnotatedClass)) {
|
4960
4971
|
adjFlags |= 131072 /* DisallowClassVar */ | 16 /* DisallowFinal */;
|
4961
4972
|
}
|
4962
4973
|
adjFlags |= 2097152 /* AllowUnpackedTupleOrTypeVarTuple */;
|
@@ -4967,7 +4978,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4967
4978
|
// If it's a custom __class_getitem__, none of the arguments should be
|
4968
4979
|
// treated as types. If it's an Annotated[a, b, c], only the first index
|
4969
4980
|
// should be treated as a type. The others can be regular (non-type) objects.
|
4970
|
-
if (hasCustomClassGetItem || (isAnnotatedClass && argIndex > 0)) {
|
4981
|
+
if ((options === null || options === void 0 ? void 0 : options.hasCustomClassGetItem) || ((options === null || options === void 0 ? void 0 : options.isAnnotatedClass) && argIndex > 0)) {
|
4971
4982
|
typeResult = {
|
4972
4983
|
...getTypeOfExpression(expr, 32 /* DisallowParamSpec */ |
|
4973
4984
|
64 /* DisallowTypeVarTuple */ |
|
@@ -4977,7 +4988,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4977
4988
|
};
|
4978
4989
|
}
|
4979
4990
|
else {
|
4980
|
-
typeResult = getTypeArg(expr, adjFlags);
|
4991
|
+
typeResult = getTypeArg(expr, adjFlags, !!(options === null || options === void 0 ? void 0 : options.supportsTypedDictTypeArg) && argIndex === 0);
|
4981
4992
|
}
|
4982
4993
|
return typeResult;
|
4983
4994
|
};
|
@@ -5016,7 +5027,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5016
5027
|
}
|
5017
5028
|
return typeArgs;
|
5018
5029
|
}
|
5019
|
-
function getTypeArg(node, flags) {
|
5030
|
+
function getTypeArg(node, flags, supportsDictExpression) {
|
5020
5031
|
let typeResult;
|
5021
5032
|
let adjustedFlags = flags |
|
5022
5033
|
128 /* ExpectingType */ |
|
@@ -5037,8 +5048,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5037
5048
|
// Set the node's type so it isn't reevaluated later.
|
5038
5049
|
setTypeForNode(node, types_1.UnknownType.create());
|
5039
5050
|
}
|
5051
|
+
else if (node.nodeType === 15 /* Dictionary */ && supportsDictExpression) {
|
5052
|
+
const inlinedTypeDict = typedDictClassType && (0, types_1.isInstantiableClass)(typedDictClassType)
|
5053
|
+
? (0, typedDicts_1.createTypedDictTypeInlined)(evaluatorInterface, node, typedDictClassType)
|
5054
|
+
: undefined;
|
5055
|
+
const keyTypeFallback = strClassType && (0, types_1.isInstantiableClass)(strClassType) ? strClassType : types_1.UnknownType.create();
|
5056
|
+
typeResult = {
|
5057
|
+
type: keyTypeFallback,
|
5058
|
+
inlinedTypeDict,
|
5059
|
+
node,
|
5060
|
+
};
|
5061
|
+
}
|
5040
5062
|
else {
|
5041
5063
|
typeResult = { ...getTypeOfExpression(node, adjustedFlags), node };
|
5064
|
+
if (node.nodeType === 15 /* Dictionary */) {
|
5065
|
+
addError(localize_1.Localizer.Diagnostic.dictInAnnotation(), node);
|
5066
|
+
}
|
5042
5067
|
// "Protocol" is not allowed as a type argument.
|
5043
5068
|
if ((0, types_1.isClass)(typeResult.type) && types_1.ClassType.isBuiltIn(typeResult.type, 'Protocol')) {
|
5044
5069
|
addError(localize_1.Localizer.Diagnostic.protocolNotAllowedInTypeArgument(), node);
|
@@ -6023,7 +6048,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6023
6048
|
}
|
6024
6049
|
typeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(constructorMethodType));
|
6025
6050
|
// Skip the unknown argument check if we've already checked for __init__.
|
6026
|
-
|
6051
|
+
let callResult;
|
6052
|
+
if ((0, constructorTransform_1.hasConstructorTransform)(type)) {
|
6053
|
+
// Use speculative mode if we're going to later apply
|
6054
|
+
// a constructor transform. This allows us to use bidirectional
|
6055
|
+
// type inference for arguments in the transform.
|
6056
|
+
callResult = useSpeculativeMode(errorNode, () => {
|
6057
|
+
return validateCallArguments(errorNode, argList, constructorMethodInfo, typeVarContext, skipUnknownArgCheck);
|
6058
|
+
});
|
6059
|
+
}
|
6060
|
+
else {
|
6061
|
+
callResult = validateCallArguments(errorNode, argList, constructorMethodInfo, typeVarContext, skipUnknownArgCheck);
|
6062
|
+
}
|
6027
6063
|
if (callResult.isTypeIncomplete) {
|
6028
6064
|
isTypeIncomplete = true;
|
6029
6065
|
}
|
@@ -6238,7 +6274,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6238
6274
|
}), exprNode);
|
6239
6275
|
return { returnType: types_1.UnknownType.create(), argumentErrors: true, overloadsUsedForCall };
|
6240
6276
|
}
|
6241
|
-
|
6277
|
+
let returnType = mapSubtypesExpandTypeVars(callTypeResult.type,
|
6242
6278
|
/* conditionFilter */ undefined, (expandedSubtype, unexpandedSubtype) => {
|
6243
6279
|
var _a, _b, _c, _d, _e, _f;
|
6244
6280
|
switch (expandedSubtype.category) {
|
@@ -6257,6 +6293,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6257
6293
|
return expandedSubtype;
|
6258
6294
|
}
|
6259
6295
|
case 5 /* Function */: {
|
6296
|
+
if (types_1.TypeBase.isInstantiable(expandedSubtype)) {
|
6297
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.callableNotInstantiable().format({
|
6298
|
+
type: printType(expandedSubtype),
|
6299
|
+
}), errorNode);
|
6300
|
+
argumentErrors = true;
|
6301
|
+
return undefined;
|
6302
|
+
}
|
6260
6303
|
// The stdlib collections/__init__.pyi stub file defines namedtuple
|
6261
6304
|
// as a function rather than a class, so we need to check for it here.
|
6262
6305
|
if (expandedSubtype.details.builtInName === 'namedtuple') {
|
@@ -6378,6 +6421,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6378
6421
|
(0, types_1.isNoneInstance)(subtype)) {
|
6379
6422
|
return (0, typeUtils_1.convertToInstantiable)(stripLiteralValue(subtype));
|
6380
6423
|
}
|
6424
|
+
else if ((0, types_1.isFunction)(subtype) && types_1.TypeBase.isInstance(subtype)) {
|
6425
|
+
return types_1.FunctionType.cloneAsInstantiable(subtype);
|
6426
|
+
}
|
6381
6427
|
return types_1.AnyType.create();
|
6382
6428
|
});
|
6383
6429
|
}
|
@@ -6501,7 +6547,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6501
6547
|
return returnType;
|
6502
6548
|
}
|
6503
6549
|
else {
|
6504
|
-
const memberType = (_d = getTypeOfObjectMember(errorNode, expandedSubtype, '__call__'
|
6550
|
+
const memberType = (_d = getTypeOfObjectMember(errorNode, expandedSubtype, '__call__',
|
6551
|
+
/* usage */ undefined,
|
6552
|
+
/* diag */ undefined, 64 /* SkipAttributeAccessOverride */)) === null || _d === void 0 ? void 0 : _d.type;
|
6505
6553
|
if (memberType) {
|
6506
6554
|
const functionResult = validateCallArguments(errorNode, argList, { type: memberType }, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
|
6507
6555
|
overloadsUsedForCall.push(...functionResult.overloadsUsedForCall);
|
@@ -6562,9 +6610,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6562
6610
|
}
|
6563
6611
|
return undefined;
|
6564
6612
|
});
|
6613
|
+
// If we ended up with a "Never" type because all code paths returned
|
6614
|
+
// undefined due to argument errors, transform the result into an Unknown
|
6615
|
+
// to avoid subsequent false positives.
|
6616
|
+
if (argumentErrors && (0, types_1.isNever)(returnType) && !returnType.isNoReturn) {
|
6617
|
+
returnType = types_1.UnknownType.create();
|
6618
|
+
}
|
6565
6619
|
return {
|
6566
6620
|
argumentErrors,
|
6567
|
-
returnType
|
6621
|
+
returnType,
|
6568
6622
|
isTypeIncomplete,
|
6569
6623
|
specializedInitSelfType,
|
6570
6624
|
overloadsUsedForCall,
|
@@ -8278,8 +8332,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8278
8332
|
types_1.FunctionType.addDefaultParameters(functionType);
|
8279
8333
|
return functionType;
|
8280
8334
|
}
|
8281
|
-
if (node.nodeType ===
|
8282
|
-
node.
|
8335
|
+
if (node.nodeType === 31 /* List */) {
|
8336
|
+
node.entries.forEach((paramExpr, index) => {
|
8283
8337
|
const typeResult = getTypeOfExpressionExpectingType(paramExpr);
|
8284
8338
|
types_1.FunctionType.addParameter(functionType, {
|
8285
8339
|
category: 0 /* Simple */,
|
@@ -10433,7 +10487,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10433
10487
|
!ParseTreeUtils.isNodeContainedWithin(errorNode, firstParamTypeAnnotation)) {
|
10434
10488
|
const annotationType = getTypeOfAnnotation(firstParamTypeAnnotation, {
|
10435
10489
|
associateTypeVarsWithScope: true,
|
10436
|
-
disallowRecursiveTypeAlias: true,
|
10437
10490
|
});
|
10438
10491
|
if (!(0, types_1.isTypeVar)(annotationType) || !annotationType.details.isSynthesizedSelf) {
|
10439
10492
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.selfTypeWithTypedSelfOrCls(), errorNode);
|
@@ -10548,6 +10601,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10548
10601
|
if ((0, types_1.isParamSpec)(typeArg.type)) {
|
10549
10602
|
addError(localize_1.Localizer.Diagnostic.paramSpecContext(), typeArg.node);
|
10550
10603
|
}
|
10604
|
+
else if ((0, types_1.isUnpackedVariadicTypeVar)(typeArg.type)) {
|
10605
|
+
addError(localize_1.Localizer.Diagnostic.typeVarTupleContext(), typeArg.node);
|
10606
|
+
}
|
10607
|
+
else if ((0, types_1.isUnpackedClass)(typeArg.type)) {
|
10608
|
+
addError(localize_1.Localizer.Diagnostic.unpackedArgInTypeArgument(), typeArg.node);
|
10609
|
+
}
|
10551
10610
|
}
|
10552
10611
|
});
|
10553
10612
|
}
|
@@ -11086,11 +11145,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11086
11145
|
// can be specialized.
|
11087
11146
|
typeAliasTypeVar.details.recursiveTypeParameters = (_a = rightHandType.typeAliasInfo) === null || _a === void 0 ? void 0 : _a.typeParameters;
|
11088
11147
|
}
|
11089
|
-
if (typeAliasTypeVar.details.illegalRecursionDetected) {
|
11090
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasIsRecursiveIndirect().format({
|
11091
|
-
name: typeAliasNameNode.value,
|
11092
|
-
}), node.leftExpression);
|
11093
|
-
}
|
11094
11148
|
}
|
11095
11149
|
}
|
11096
11150
|
}
|
@@ -11176,11 +11230,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11176
11230
|
// Set the resulting type to the boundType of the original type alias
|
11177
11231
|
// to support recursive type aliases.
|
11178
11232
|
typeAliasTypeVar.details.boundType = aliasType;
|
11179
|
-
if (typeAliasTypeVar.details.illegalRecursionDetected) {
|
11180
|
-
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasIsRecursiveIndirect().format({
|
11181
|
-
name: node.name.value,
|
11182
|
-
}), node.name);
|
11183
|
-
}
|
11184
11233
|
writeTypeCache(node.name, { type: aliasType, isIncomplete }, 0 /* None */);
|
11185
11234
|
return aliasType;
|
11186
11235
|
}
|
@@ -11296,7 +11345,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11296
11345
|
argType = (0, types_1.removeUnbound)(argType);
|
11297
11346
|
}
|
11298
11347
|
if (!(0, types_1.isAnyOrUnknown)(argType) && !(0, types_1.isUnbound)(argType)) {
|
11299
|
-
if ((0,
|
11348
|
+
if ((0, typeUtils_1.isMetaclassInstance)(argType)) {
|
11349
|
+
(0, debug_1.assert)((0, types_1.isClassInstance)(argType));
|
11300
11350
|
argType =
|
11301
11351
|
argType.typeArguments && argType.typeArguments.length > 0
|
11302
11352
|
? argType.typeArguments[0]
|
@@ -11883,6 +11933,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11883
11933
|
decoratorCallType.details.builtInName === 'dataclass_transform') {
|
11884
11934
|
originalClassType.details.classDataClassTransform = (0, dataClasses_1.validateDataClassTransformDecorator)(evaluatorInterface, decoratorNode.expression);
|
11885
11935
|
}
|
11936
|
+
else if (decoratorCallType.details.name === 'deprecated') {
|
11937
|
+
originalClassType.details.deprecatedMessage = getCustomDeprecationMessage(decoratorNode);
|
11938
|
+
return inputClassType;
|
11939
|
+
}
|
11886
11940
|
}
|
11887
11941
|
if ((0, types_1.isOverloadedFunction)(decoratorCallType)) {
|
11888
11942
|
if (decoratorCallType.overloads.length > 0 &&
|
@@ -11912,6 +11966,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11912
11966
|
// dependency between builtins, typing and _typeshed stubs.
|
11913
11967
|
return inputClassType;
|
11914
11968
|
}
|
11969
|
+
if (decoratorType.details.builtInName === 'deprecated') {
|
11970
|
+
originalClassType.details.deprecatedMessage = getCustomDeprecationMessage(decoratorNode);
|
11971
|
+
return inputClassType;
|
11972
|
+
}
|
11915
11973
|
if (decoratorType.details.builtInName === 'runtime_checkable') {
|
11916
11974
|
originalClassType.details.flags |= 32768 /* RuntimeCheckable */;
|
11917
11975
|
// Don't call getTypeOfDecorator for runtime_checkable. It appears
|
@@ -12369,7 +12427,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12369
12427
|
functionType.details.declaredReturnType = types_1.UnknownType.create();
|
12370
12428
|
const returnType = getTypeOfAnnotation(returnTypeAnnotationNode, {
|
12371
12429
|
associateTypeVarsWithScope: true,
|
12372
|
-
disallowRecursiveTypeAlias: true,
|
12373
12430
|
});
|
12374
12431
|
functionType.details.declaredReturnType = returnType;
|
12375
12432
|
}
|
@@ -12704,6 +12761,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12704
12761
|
undecoratedType.details.decoratorDataClassBehaviors = (0, dataClasses_1.validateDataClassTransformDecorator)(evaluatorInterface, decoratorNode.expression);
|
12705
12762
|
return inputFunctionType;
|
12706
12763
|
}
|
12764
|
+
if (decoratorCallType.details.name === 'deprecated') {
|
12765
|
+
undecoratedType.details.deprecatedMessage = getCustomDeprecationMessage(decoratorNode);
|
12766
|
+
return inputFunctionType;
|
12767
|
+
}
|
12707
12768
|
}
|
12708
12769
|
if ((0, types_1.isOverloadedFunction)(decoratorCallType)) {
|
12709
12770
|
if (decoratorCallType.overloads.length > 0 &&
|
@@ -12719,6 +12780,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12719
12780
|
if (decoratorType.details.builtInName === 'abstractmethod') {
|
12720
12781
|
return inputFunctionType;
|
12721
12782
|
}
|
12783
|
+
if (decoratorType.details.builtInName === 'deprecated') {
|
12784
|
+
undecoratedType.details.deprecatedMessage = getCustomDeprecationMessage(decoratorNode);
|
12785
|
+
return inputFunctionType;
|
12786
|
+
}
|
12722
12787
|
// Handle property setters and deleters.
|
12723
12788
|
if (decoratorNode.expression.nodeType === 35 /* MemberAccess */) {
|
12724
12789
|
const baseType = getTypeOfExpression(decoratorNode.expression.leftExpression, evaluatorFlags | 2 /* DoNotSpecialize */).type;
|
@@ -12828,7 +12893,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12828
12893
|
getTypeOfFunction(decl.node);
|
12829
12894
|
}
|
12830
12895
|
}
|
12831
|
-
|
12896
|
+
let overloadedTypes = [];
|
12832
12897
|
// Look at the previous declaration's type.
|
12833
12898
|
const prevDecl = decls[declIndex - 1];
|
12834
12899
|
if (prevDecl.type === 5 /* Function */) {
|
@@ -12850,6 +12915,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12850
12915
|
if (overloadedTypes.length === 1) {
|
12851
12916
|
return overloadedTypes[0];
|
12852
12917
|
}
|
12918
|
+
// Apply the implementation's docstring to any overloads that don't
|
12919
|
+
// have their own docstrings.
|
12920
|
+
const implementation = overloadedTypes.find((signature) => !types_1.FunctionType.isOverloaded(signature));
|
12921
|
+
if (implementation === null || implementation === void 0 ? void 0 : implementation.details.docString) {
|
12922
|
+
overloadedTypes = overloadedTypes.map((overload) => {
|
12923
|
+
if (types_1.FunctionType.isOverloaded(overload) && !overload.details.docString) {
|
12924
|
+
return types_1.FunctionType.cloneWithDocString(overload, implementation.details.docString);
|
12925
|
+
}
|
12926
|
+
return overload;
|
12927
|
+
});
|
12928
|
+
}
|
12853
12929
|
// Create a new overloaded type that copies the contents of the previous
|
12854
12930
|
// one and adds a new function.
|
12855
12931
|
const newOverload = types_1.OverloadedFunctionType.create(overloadedTypes);
|
@@ -13522,7 +13598,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13522
13598
|
annotationNode === annotationParent.returnTypeAnnotation) {
|
13523
13599
|
getTypeOfAnnotation(annotationNode, {
|
13524
13600
|
associateTypeVarsWithScope: true,
|
13525
|
-
disallowRecursiveTypeAlias: true,
|
13526
13601
|
});
|
13527
13602
|
return;
|
13528
13603
|
}
|
@@ -14063,7 +14138,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14063
14138
|
if (firstNonDefaultParam >= 0) {
|
14064
14139
|
minTypeArgCount = firstNonDefaultParam;
|
14065
14140
|
}
|
14066
|
-
|
14141
|
+
// Classes that accept inlined type dict type args allow only one.
|
14142
|
+
if (typeArgs[0].inlinedTypeDict) {
|
14143
|
+
if (typeArgs.length > 1) {
|
14144
|
+
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeArgsTooMany().format({
|
14145
|
+
name: classType.aliasName || classType.details.name,
|
14146
|
+
expected: 1,
|
14147
|
+
received: typeArgCount,
|
14148
|
+
}), typeArgs[1].node);
|
14149
|
+
}
|
14150
|
+
return { type: typeArgs[0].inlinedTypeDict };
|
14151
|
+
}
|
14152
|
+
else if (typeArgCount > typeParameters.length) {
|
14067
14153
|
if (!types_1.ClassType.isPartiallyEvaluated(classType) && !types_1.ClassType.isTupleClass(classType)) {
|
14068
14154
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
14069
14155
|
if (typeParameters.length === 0) {
|
@@ -14147,7 +14233,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14147
14233
|
if (typeArgs && index < typeArgs.length) {
|
14148
14234
|
if (typeParam.details.isParamSpec) {
|
14149
14235
|
const typeArg = typeArgs[index];
|
14150
|
-
const functionType = types_1.FunctionType.
|
14236
|
+
const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* ParamSpecValue */);
|
14151
14237
|
types_1.TypeBase.setSpecialForm(functionType);
|
14152
14238
|
if ((0, typeUtils_1.isEllipsisType)(typeArg.type)) {
|
14153
14239
|
types_1.FunctionType.addDefaultParameters(functionType);
|
@@ -14333,7 +14419,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14333
14419
|
const scopeTypeHonorsCodeFlow = scopeType !== 1 /* Function */ && scopeType !== 0 /* ListComprehension */;
|
14334
14420
|
if (symbolWithScope && honorCodeFlow && scopeTypeHonorsCodeFlow) {
|
14335
14421
|
// Filter the declarations based on flow reachability.
|
14336
|
-
const
|
14422
|
+
const reachableDecl = symbolWithScope.symbol.getDeclarations().find((decl) => {
|
14337
14423
|
if (decl.type !== 8 /* Alias */ && decl.type !== 0 /* Intrinsic */) {
|
14338
14424
|
// Is the declaration in the same execution scope as the "usageNode" node?
|
14339
14425
|
const usageScope = ParseTreeUtils.getExecutionScopeNode(node);
|
@@ -14361,7 +14447,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14361
14447
|
});
|
14362
14448
|
// If none of the declarations are reachable from the current node,
|
14363
14449
|
// search for the symbol in outer scopes.
|
14364
|
-
if (
|
14450
|
+
if (!reachableDecl) {
|
14365
14451
|
if (symbolWithScope.scope.type !== 1 /* Function */) {
|
14366
14452
|
let nextScopeToSearch = symbolWithScope.scope.parent;
|
14367
14453
|
const isOutsideCallerModule = symbolWithScope.isOutsideCallerModule || symbolWithScope.scope.type === 3 /* Module */;
|
@@ -14887,7 +14973,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14887
14973
|
return typeVar;
|
14888
14974
|
}
|
14889
14975
|
function getInferredTypeOfDeclaration(symbol, decl) {
|
14890
|
-
var _a, _b;
|
14976
|
+
var _a, _b, _c;
|
14891
14977
|
const resolvedDecl = resolveAliasDeclaration(decl,
|
14892
14978
|
/* resolveLocalNames */ true,
|
14893
14979
|
/* allowExternallyHiddenAccess */ AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile);
|
@@ -14903,7 +14989,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14903
14989
|
moduleType.fields = lookupResults.symbolTable;
|
14904
14990
|
moduleType.docString = lookupResults.docString;
|
14905
14991
|
}
|
14906
|
-
else {
|
14992
|
+
else if (!loaderActions.implicitImports) {
|
14907
14993
|
return evaluatorOptions.evaluateUnknownImportsAsAny ? types_1.AnyType.create() : types_1.UnknownType.create();
|
14908
14994
|
}
|
14909
14995
|
}
|
@@ -14979,17 +15065,38 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14979
15065
|
isUnambiguousType = true;
|
14980
15066
|
}
|
14981
15067
|
}
|
15068
|
+
// Special-case constants, which are treated as unambiguous.
|
14982
15069
|
if (isFinalVariableDeclaration(resolvedDecl) || resolvedDecl.isConstant) {
|
14983
15070
|
isUnambiguousType = true;
|
14984
15071
|
}
|
15072
|
+
// Special-case calls to certain built-in type functions.
|
15073
|
+
if (((_a = resolvedDecl.inferredTypeSource) === null || _a === void 0 ? void 0 : _a.nodeType) === 9 /* Call */) {
|
15074
|
+
const baseTypeResult = getTypeOfExpression(resolvedDecl.inferredTypeSource.leftExpression, 2 /* DoNotSpecialize */);
|
15075
|
+
const callType = baseTypeResult.type;
|
15076
|
+
const exemptBuiltins = [
|
15077
|
+
'TypeVar',
|
15078
|
+
'ParamSpec',
|
15079
|
+
'TypeVarTuple',
|
15080
|
+
'TypedDict',
|
15081
|
+
'NamedTuple',
|
15082
|
+
'NewType',
|
15083
|
+
];
|
15084
|
+
if ((0, types_1.isInstantiableClass)(callType) && types_1.ClassType.isBuiltIn(callType, exemptBuiltins)) {
|
15085
|
+
isUnambiguousType = true;
|
15086
|
+
}
|
15087
|
+
else if ((0, types_1.isFunction)(callType) &&
|
15088
|
+
exemptBuiltins.some((name) => callType.details.builtInName === name)) {
|
15089
|
+
isUnambiguousType = true;
|
15090
|
+
}
|
15091
|
+
}
|
14985
15092
|
}
|
14986
15093
|
}
|
14987
15094
|
// If the resolved declaration had no defined type, use the
|
14988
15095
|
// inferred type for this node.
|
14989
15096
|
if (resolvedDecl.type === 2 /* Parameter */) {
|
14990
|
-
return (
|
15097
|
+
return (_b = evaluateTypeForSubnode(resolvedDecl.node.name, () => {
|
14991
15098
|
evaluateTypeOfParameter(resolvedDecl.node);
|
14992
|
-
})) === null ||
|
15099
|
+
})) === null || _b === void 0 ? void 0 : _b.type;
|
14993
15100
|
}
|
14994
15101
|
if (resolvedDecl.type === 1 /* Variable */ && resolvedDecl.inferredTypeSource) {
|
14995
15102
|
const isTypeAlias = isExplicitTypeAliasDeclaration(resolvedDecl) || isPossibleTypeAliasOrTypedDict(resolvedDecl);
|
@@ -14998,9 +15105,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14998
15105
|
const typeSource = isTypeAlias && resolvedDecl.inferredTypeSource.parent
|
14999
15106
|
? resolvedDecl.inferredTypeSource.parent
|
15000
15107
|
: resolvedDecl.inferredTypeSource;
|
15001
|
-
let inferredType = (
|
15108
|
+
let inferredType = (_c = evaluateTypeForSubnode(resolvedDecl.node, () => {
|
15002
15109
|
evaluateTypesForStatement(typeSource);
|
15003
|
-
})) === null ||
|
15110
|
+
})) === null || _c === void 0 ? void 0 : _c.type;
|
15004
15111
|
if (inferredType && resolvedDecl.node.nodeType === 38 /* Name */) {
|
15005
15112
|
// See if this is an enum member. If so, we need to handle it as a special case.
|
15006
15113
|
const enumMemberType = (0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, resolvedDecl.node, () => {
|
@@ -15114,18 +15221,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15114
15221
|
}
|
15115
15222
|
function getEffectiveTypeOfSymbolForUsage(symbol, usageNode, useLastDecl = false) {
|
15116
15223
|
var _a, _b;
|
15117
|
-
// Look in the cache to see if we've computed this already.
|
15118
|
-
let cacheEntries = effectiveTypeCache.get(symbol.id);
|
15119
|
-
const usageNodeId = usageNode ? usageNode.id : undefined;
|
15120
|
-
const effectiveTypeCacheKey = `${usageNodeId === undefined ? '.' : usageNodeId.toString()}${useLastDecl ? '*' : ''}`;
|
15121
|
-
if (cacheEntries) {
|
15122
|
-
const result = cacheEntries.get(effectiveTypeCacheKey);
|
15123
|
-
if (result) {
|
15124
|
-
if (!result.isIncomplete) {
|
15125
|
-
return result;
|
15126
|
-
}
|
15127
|
-
}
|
15128
|
-
}
|
15129
15224
|
let declaredTypeInfo;
|
15130
15225
|
// If there's a declared type, it takes precedence over inferred types.
|
15131
15226
|
if (symbol.hasTypedDeclarations()) {
|
@@ -15150,10 +15245,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15150
15245
|
includesIllegalTypeAliasDecl: !typedDecls.every((decl) => isPossibleTypeAliasDeclaration(decl)),
|
15151
15246
|
isRecursiveDefinition: !declaredType,
|
15152
15247
|
};
|
15153
|
-
addToEffectiveTypeCache(result);
|
15154
15248
|
return result;
|
15155
15249
|
}
|
15156
15250
|
}
|
15251
|
+
// Look in the inferred type cache to see if we've computed this already.
|
15252
|
+
let cacheEntries = effectiveTypeCache.get(symbol.id);
|
15253
|
+
const usageNodeId = usageNode ? usageNode.id : undefined;
|
15254
|
+
const effectiveTypeCacheKey = `${usageNodeId === undefined ? '.' : usageNodeId.toString()}${useLastDecl ? '*' : ''}`;
|
15255
|
+
if (cacheEntries) {
|
15256
|
+
const result = cacheEntries.get(effectiveTypeCacheKey);
|
15257
|
+
if (result) {
|
15258
|
+
if (!result.isIncomplete) {
|
15259
|
+
return result;
|
15260
|
+
}
|
15261
|
+
}
|
15262
|
+
}
|
15157
15263
|
// Infer the type.
|
15158
15264
|
const typesToCombine = [];
|
15159
15265
|
const decls = symbol.getDeclarations();
|
@@ -16669,6 +16775,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16669
16775
|
if ((0, types_1.isTypeSame)(srcType, destType, {}, recursionCount)) {
|
16670
16776
|
return true;
|
16671
16777
|
}
|
16778
|
+
// Sort the subtypes so we have a deterministic order for unions.
|
16779
|
+
let sortedSrcTypes = (0, typeUtils_1.sortTypes)(srcType.subtypes);
|
16672
16780
|
// Handle the case where the source and dest are both unions. Try
|
16673
16781
|
// to eliminate as many exact type matches between the src and dest.
|
16674
16782
|
if ((0, types_1.isUnion)(destType)) {
|
@@ -16683,8 +16791,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16683
16791
|
return true;
|
16684
16792
|
}
|
16685
16793
|
const remainingDestSubtypes = [];
|
16686
|
-
let remainingSrcSubtypes =
|
16687
|
-
let
|
16794
|
+
let remainingSrcSubtypes = sortedSrcTypes;
|
16795
|
+
let canUseFastPath = true;
|
16688
16796
|
// First attempt to match all of the non-generic types in the dest
|
16689
16797
|
// to non-generic types in the source.
|
16690
16798
|
destType.subtypes.forEach((destSubtype) => {
|
@@ -16703,7 +16811,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16703
16811
|
});
|
16704
16812
|
// For all remaining source subtypes, attempt to find a dest subtype
|
16705
16813
|
// whose primary type matches.
|
16706
|
-
|
16814
|
+
remainingSrcSubtypes.forEach((srcSubtype) => {
|
16707
16815
|
const destTypeIndex = remainingDestSubtypes.findIndex((destSubtype) => {
|
16708
16816
|
if ((0, types_1.isClass)(srcSubtype) &&
|
16709
16817
|
(0, types_1.isClass)(destSubtype) &&
|
@@ -16720,7 +16828,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16720
16828
|
});
|
16721
16829
|
if (destTypeIndex >= 0) {
|
16722
16830
|
if (!assignType(remainingDestSubtypes[destTypeIndex], srcSubtype, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
16723
|
-
|
16831
|
+
canUseFastPath = false;
|
16724
16832
|
}
|
16725
16833
|
remainingDestSubtypes.splice(destTypeIndex, 1);
|
16726
16834
|
remainingSrcSubtypes = remainingSrcSubtypes.filter((t) => t !== srcSubtype);
|
@@ -16728,11 +16836,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16728
16836
|
});
|
16729
16837
|
// If there is are remaining dest subtypes and they're all type variables,
|
16730
16838
|
// attempt to assign the remaining source subtypes to them.
|
16731
|
-
if (
|
16839
|
+
if (canUseFastPath && (remainingDestSubtypes.length !== 0 || remainingSrcSubtypes.length !== 0)) {
|
16732
16840
|
const isReversed = (flags & 2 /* ReverseTypeVarMatching */) !== 0;
|
16733
16841
|
const effectiveDestSubtypes = isReversed ? remainingSrcSubtypes : remainingDestSubtypes;
|
16734
16842
|
if (effectiveDestSubtypes.length === 0 || effectiveDestSubtypes.some((t) => !(0, types_1.isTypeVar)(t))) {
|
16735
|
-
|
16843
|
+
canUseFastPath = false;
|
16844
|
+
// We can avoid checking the source subtypes that have already been checked.
|
16845
|
+
sortedSrcTypes = remainingSrcSubtypes;
|
16736
16846
|
}
|
16737
16847
|
else if (remainingDestSubtypes.length === remainingSrcSubtypes.length) {
|
16738
16848
|
// If the number of remaining source subtypes is the same as the number
|
@@ -16740,9 +16850,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16740
16850
|
remainingDestSubtypes.forEach((destSubtype, index) => {
|
16741
16851
|
const srcSubtype = remainingSrcSubtypes[index];
|
16742
16852
|
if (!assignType(destSubtype, srcSubtype, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
16743
|
-
|
16853
|
+
canUseFastPath = false;
|
16744
16854
|
}
|
16745
16855
|
});
|
16856
|
+
// We can avoid checking the source subtypes that have already been checked.
|
16857
|
+
sortedSrcTypes = remainingSrcSubtypes;
|
16746
16858
|
}
|
16747
16859
|
else if (remainingSrcSubtypes.length === 0) {
|
16748
16860
|
if ((flags & 1024 /* PopulatingExpectedType */) !== 0) {
|
@@ -16756,24 +16868,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16756
16868
|
}
|
16757
16869
|
// If we've assigned all of the source subtypes but one or more dest
|
16758
16870
|
// TypeVars have gone unmatched, treat this as success.
|
16759
|
-
return true;
|
16760
16871
|
}
|
16761
16872
|
else {
|
16762
16873
|
// Try to assign a union of the remaining source types to
|
16763
16874
|
// the first destination TypeVar.
|
16764
16875
|
if (!assignType(isReversed ? (0, types_1.combineTypes)(remainingDestSubtypes) : remainingDestSubtypes[0], isReversed ? remainingSrcSubtypes[0] : (0, types_1.combineTypes)(remainingSrcSubtypes), diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
16765
|
-
|
16876
|
+
canUseFastPath = false;
|
16766
16877
|
}
|
16767
16878
|
}
|
16768
16879
|
}
|
16769
|
-
if (
|
16880
|
+
if (canUseFastPath) {
|
16770
16881
|
return true;
|
16771
16882
|
}
|
16772
16883
|
}
|
16773
|
-
// For union sources, all of the types need to be assignable to the dest.
|
16774
16884
|
let isIncompatible = false;
|
16775
|
-
|
16776
|
-
(0, typeUtils_1.doForEachSubtype)(srcType, (subtype, subtypeIndex, allSubtypes) => {
|
16885
|
+
sortedSrcTypes.forEach((subtype) => {
|
16777
16886
|
if (isIncompatible) {
|
16778
16887
|
return;
|
16779
16888
|
}
|
@@ -16783,11 +16892,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16783
16892
|
// Determine if the current subtype is subsumed by another subtype
|
16784
16893
|
// in the same union. If so, we can ignore this.
|
16785
16894
|
let isSubtypeSubsumed = false;
|
16786
|
-
|
16787
|
-
if (isSubtypeSubsumed
|
16788
|
-
|
16789
|
-
|
16790
|
-
|
16895
|
+
srcType.subtypes.forEach((innerSubtype) => {
|
16896
|
+
if (!isSubtypeSubsumed &&
|
16897
|
+
!(0, types_1.isTypeSame)(innerSubtype, subtype) &&
|
16898
|
+
!(0, types_1.isAnyOrUnknown)(innerSubtype) &&
|
16899
|
+
isProperSubtype(innerSubtype, concreteSubtype, recursionCount)) {
|
16791
16900
|
isSubtypeSubsumed = true;
|
16792
16901
|
}
|
16793
16902
|
});
|
@@ -16797,8 +16906,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16797
16906
|
isIncompatible = true;
|
16798
16907
|
}
|
16799
16908
|
}
|
16800
|
-
},
|
16801
|
-
/* sortSubtypes */ true);
|
16909
|
+
}, /* sortSubtypes */ true);
|
16802
16910
|
if (isIncompatible) {
|
16803
16911
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format({
|
16804
16912
|
sourceType: printType(srcType),
|