@zzzen/pyright-internal 1.2.0-dev.20221127 → 1.2.0-dev.20221211
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/aliasDeclarationUtils.js +23 -9
- package/dist/analyzer/aliasDeclarationUtils.js.map +1 -1
- package/dist/analyzer/analyzerFileInfo.d.ts +1 -0
- package/dist/analyzer/analyzerFileInfo.js.map +1 -1
- package/dist/analyzer/backgroundAnalysisProgram.d.ts +1 -0
- package/dist/analyzer/backgroundAnalysisProgram.js +3 -0
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/binder.js +2 -2
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +16 -7
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +10 -0
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/dataClasses.d.ts +1 -1
- package/dist/analyzer/dataClasses.js +18 -5
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/docStringConversion.js +3 -2
- package/dist/analyzer/docStringConversion.js.map +1 -1
- package/dist/analyzer/importResolver.js +2 -2
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/program.d.ts +1 -0
- package/dist/analyzer/program.js +24 -6
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/service.d.ts +2 -0
- package/dist/analyzer/service.js +79 -44
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.js +2 -2
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.d.ts +2 -0
- package/dist/analyzer/typeDocStringUtils.js +14 -13
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.d.ts +0 -1
- package/dist/analyzer/typeEvaluator.js +124 -47
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +1 -0
- package/dist/analyzer/typePrinter.js +8 -2
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +1 -1
- package/dist/analyzer/typeUtils.js +4 -1
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +3 -2
- package/dist/analyzer/types.js +19 -4
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +1 -1
- package/dist/common/commandLineOptions.d.ts +1 -1
- package/dist/common/commandLineOptions.js +0 -2
- package/dist/common/commandLineOptions.js.map +1 -1
- package/dist/common/configOptions.d.ts +1 -1
- package/dist/common/configOptions.js +4 -3
- 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/common/pathUtils.js +4 -1
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/positionUtils.js +3 -9
- package/dist/common/positionUtils.js.map +1 -1
- package/dist/languageServerBase.d.ts +9 -3
- package/dist/languageServerBase.js +48 -12
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/analyzerServiceExecutor.js +1 -2
- package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +2 -0
- package/dist/languageService/completionProvider.js +23 -5
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/documentSymbolProvider.d.ts +1 -1
- package/dist/languageService/documentSymbolProvider.js +1 -1
- package/dist/languageService/documentSymbolProvider.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +1 -0
- package/dist/languageService/hoverProvider.js +19 -3
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/indentationUtils.d.ts +3 -0
- package/dist/languageService/indentationUtils.js +4 -3
- package/dist/languageService/indentationUtils.js.map +1 -1
- package/dist/localization/localize.d.ts +3 -1
- package/dist/localization/localize.js +1 -1
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +1 -1
- package/dist/parser/tokenizer.js +1 -3
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/pyright.js +3 -1
- package/dist/pyright.js.map +1 -1
- package/dist/tests/chainedSourceFiles.test.js +2 -0
- package/dist/tests/chainedSourceFiles.test.js.map +1 -1
- package/dist/tests/docStringConversion.test.js +46 -12
- package/dist/tests/docStringConversion.test.js.map +1 -1
- package/dist/tests/fourslash/completions.classVariable.fourslash.js +108 -35
- package/dist/tests/fourslash/completions.classVariable.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.docFromSrc.fourslash.js +9 -7
- package/dist/tests/fourslash/hover.docFromSrc.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module2.fourslash.js +4 -1
- package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module2.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport2.fourslash.js +2 -1
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport2.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport3.fourslash.js +8 -1
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport3.fourslash.js.map +1 -1
- package/dist/tests/fourslash/shadowedImports.fourslash.js +12 -0
- package/dist/tests/fourslash/shadowedImports.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.js +1 -2
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +2 -2
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/indentationUtils.ptvs.test.js +2 -6
- package/dist/tests/indentationUtils.ptvs.test.js.map +1 -1
- package/dist/tests/service.test.d.ts +1 -0
- package/dist/tests/service.test.js +159 -0
- package/dist/tests/service.test.js.map +1 -0
- package/dist/tests/tokenizer.test.js +2 -2
- package/dist/tests/typeEvaluator3.test.js +27 -3
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/workspaceMap.d.ts +2 -1
- package/dist/workspaceMap.js +19 -4
- package/dist/workspaceMap.js.map +1 -1
- package/package.json +1 -1
@@ -196,12 +196,21 @@ const maxEntriesToUseForInference = 64;
|
|
196
196
|
// when inferring its type? We need to cut it off at some point
|
197
197
|
// to avoid excessive computation.
|
198
198
|
const maxDeclarationsToUseForInference = 64;
|
199
|
+
// Maximum number of times to attempt effective type evaluation
|
200
|
+
// of a variable that has no type declaration.
|
201
|
+
const maxEffectiveTypeEvaluationAttempts = 16;
|
199
202
|
// Maximum number of combinatoric union type expansions allowed
|
200
203
|
// when resolving an overload.
|
201
204
|
const maxOverloadUnionExpansionCount = 64;
|
202
205
|
// Maximum number of recursive function return type inference attempts
|
203
206
|
// that can be concurrently pending before we give up.
|
204
207
|
const maxInferFunctionReturnRecursionCount = 12;
|
208
|
+
// Maximum recursion amount when comparing two recursive type aliases.
|
209
|
+
// Increasing this can greatly increase the time required to evaluate
|
210
|
+
// two recursive type aliases that have the same definition. Decreasing
|
211
|
+
// it can increase the chance of false negatives for such recursive
|
212
|
+
// type aliases.
|
213
|
+
const maxRecursiveTypeAliasRecursionCount = 10;
|
205
214
|
// This switch enables a special debug mode that attempts to catch
|
206
215
|
// bugs due to inconsistent evaluation flags used when reading types
|
207
216
|
// from the type cache.
|
@@ -694,7 +703,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
694
703
|
}
|
695
704
|
}
|
696
705
|
if (flags & 65536 /* DisallowRecursiveTypeAliasPlaceholder */) {
|
697
|
-
if ((0, typeUtils_1.isTypeAliasPlaceholder)(typeResult.type)) {
|
706
|
+
if ((0, types_1.isTypeVar)(typeResult.type) && (0, typeUtils_1.isTypeAliasPlaceholder)(typeResult.type)) {
|
698
707
|
typeResult.type.details.illegalRecursionDetected = true;
|
699
708
|
}
|
700
709
|
}
|
@@ -1977,6 +1986,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1977
1986
|
if (diagLevel === 'none') {
|
1978
1987
|
return undefined;
|
1979
1988
|
}
|
1989
|
+
// Should we suppress this diagnostic because it's within an unannotated function?
|
1990
|
+
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
1991
|
+
if (!fileInfo.diagnosticRuleSet.analyzeUnannotatedFunctions) {
|
1992
|
+
const containingFunction = ParseTreeUtils.getEnclosingFunction(node);
|
1993
|
+
// Is the target node within the body of the function? If so, suppress the diagnostic.
|
1994
|
+
if (containingFunction &&
|
1995
|
+
ParseTreeUtils.isUnannotatedFunction(containingFunction) &&
|
1996
|
+
ParseTreeUtils.isNodeContainedWithin(node, containingFunction.suite)) {
|
1997
|
+
return undefined;
|
1998
|
+
}
|
1999
|
+
}
|
1980
2000
|
const diagnostic = addDiagnosticWithSuppressionCheck(diagLevel, message, node, range);
|
1981
2001
|
if (diagnostic) {
|
1982
2002
|
diagnostic.setRule(rule);
|
@@ -2749,15 +2769,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2749
2769
|
let type;
|
2750
2770
|
let isIncomplete = false;
|
2751
2771
|
const allowForwardReferences = (flags & 4 /* AllowForwardReferences */) !== 0 || fileInfo.isStubFile;
|
2752
|
-
if (!evaluatorOptions.analyzeUnannotatedFunctions) {
|
2753
|
-
const containingFunction = ParseTreeUtils.getEnclosingFunction(node);
|
2754
|
-
if (containingFunction && ParseTreeUtils.isUnannotatedFunction(containingFunction)) {
|
2755
|
-
return {
|
2756
|
-
type: types_1.AnyType.create(),
|
2757
|
-
isIncomplete: false,
|
2758
|
-
};
|
2759
|
-
}
|
2760
|
-
}
|
2761
2772
|
// Does this name refer to a PEP 695-style type parameter?
|
2762
2773
|
const typeParamSymbol = AnalyzerNodeInfo.getTypeParameterSymbol(node);
|
2763
2774
|
if (typeParamSymbol) {
|
@@ -2786,6 +2797,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2786
2797
|
useCodeFlowAnalysis = false;
|
2787
2798
|
}
|
2788
2799
|
symbol = symbolWithScope.symbol;
|
2800
|
+
setSymbolAccessed(fileInfo, symbol, node);
|
2801
|
+
// If we're not supposed to be analyzing this function, skip the remaining work
|
2802
|
+
// to determine the name's type. Simply evaluate its type as Any.
|
2803
|
+
if (!fileInfo.diagnosticRuleSet.analyzeUnannotatedFunctions) {
|
2804
|
+
const containingFunction = ParseTreeUtils.getEnclosingFunction(node);
|
2805
|
+
if (containingFunction && ParseTreeUtils.isUnannotatedFunction(containingFunction)) {
|
2806
|
+
return {
|
2807
|
+
type: types_1.AnyType.create(),
|
2808
|
+
isIncomplete: false,
|
2809
|
+
};
|
2810
|
+
}
|
2811
|
+
}
|
2789
2812
|
// Get the effective type (either the declared type or the inferred type).
|
2790
2813
|
// If we're using code flow analysis, pass the usage node so we consider
|
2791
2814
|
// only the assignment nodes that are reachable from this usage.
|
@@ -2842,7 +2865,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2842
2865
|
}
|
2843
2866
|
// Detect, report, and fill in missing type arguments if appropriate.
|
2844
2867
|
type = reportMissingTypeArguments(node, type, flags);
|
2845
|
-
setSymbolAccessed(fileInfo, symbol, node);
|
2846
2868
|
if ((flags & 1024 /* ExpectingTypeAnnotation */) !== 0) {
|
2847
2869
|
// Verify that the name does not refer to a (non type alias) variable.
|
2848
2870
|
if (effectiveTypeInfo.includesVariableDecl && !type.typeAliasInfo) {
|
@@ -4399,7 +4421,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4399
4421
|
if (typeAliasResult) {
|
4400
4422
|
return typeAliasResult;
|
4401
4423
|
}
|
4402
|
-
if ((0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
|
4424
|
+
if ((0, types_1.isTypeVar)(baseTypeResult.type) && (0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
|
4403
4425
|
const typeArgTypes = getTypeArgs(node, flags).map((t) => (0, typeUtils_1.convertToInstance)(t.type));
|
4404
4426
|
const type = types_1.TypeBase.cloneForTypeAlias(baseTypeResult.type, baseTypeResult.type.details.recursiveTypeAliasName, '', baseTypeResult.type.details.recursiveTypeAliasScopeId, baseTypeResult.type.details.recursiveTypeParameters, typeArgTypes);
|
4405
4427
|
return { type };
|
@@ -5784,7 +5806,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5784
5806
|
}
|
5785
5807
|
});
|
5786
5808
|
}
|
5787
|
-
if (!validatedTypes && argList.
|
5809
|
+
if (!validatedTypes && argList.some((arg) => arg.argumentCategory === 0 /* Simple */)) {
|
5788
5810
|
// Suppress this error if the class was instantiated from a custom
|
5789
5811
|
// metaclass because it's likely that it's a false positive. Also
|
5790
5812
|
// suppress the error if the class's metaclass has a __call__ method.
|
@@ -6971,9 +6993,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6971
6993
|
((0, types_1.isClassInstance)(argType) &&
|
6972
6994
|
(0, typeUtils_1.isTupleClass)(argType) &&
|
6973
6995
|
argType.tupleTypeArguments &&
|
6974
|
-
argType.tupleTypeArguments.
|
6996
|
+
argType.tupleTypeArguments.length === 1 &&
|
6997
|
+
(0, types_1.isUnpackedVariadicTypeVar)(argType.tupleTypeArguments[0].type));
|
6975
6998
|
if (containsVariadicTypeVar &&
|
6976
|
-
argParam.argument.argumentCategory !== 1 /* UnpackedList */
|
6999
|
+
argParam.argument.argumentCategory !== 1 /* UnpackedList */ &&
|
7000
|
+
!argParam.mapsToVarArgList) {
|
6977
7001
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeVarTupleMustBeUnpacked(), (_a = argParam.argument.valueExpression) !== null && _a !== void 0 ? _a : errorNode);
|
6978
7002
|
reportedArgError = true;
|
6979
7003
|
}
|
@@ -8740,13 +8764,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8740
8764
|
let effectiveExpectedType = expectedType;
|
8741
8765
|
if (expectedType && (0, types_1.isUnion)(expectedType)) {
|
8742
8766
|
let matchingSubtype;
|
8767
|
+
let matchingSubtypeResult;
|
8743
8768
|
(0, typeUtils_1.doForEachSubtype)(expectedType, (subtype) => {
|
8744
|
-
if
|
8745
|
-
|
8746
|
-
|
8747
|
-
|
8748
|
-
|
8769
|
+
// Use shortcut if we've already found a match.
|
8770
|
+
if (matchingSubtypeResult && !matchingSubtypeResult.typeErrors) {
|
8771
|
+
return;
|
8772
|
+
}
|
8773
|
+
const subtypeResult = useSpeculativeMode(node, () => {
|
8774
|
+
return getTypeOfDictionaryExpected(node, subtype);
|
8775
|
+
});
|
8776
|
+
if (subtypeResult && assignType(subtype, subtypeResult.type)) {
|
8777
|
+
// If this is the first result we're seeing or it's the first result
|
8778
|
+
// without errors, select it as the match.
|
8779
|
+
if (!matchingSubtypeResult || (matchingSubtypeResult.typeErrors && !subtypeResult.typeErrors)) {
|
8749
8780
|
matchingSubtype = subtype;
|
8781
|
+
matchingSubtypeResult = subtypeResult;
|
8750
8782
|
}
|
8751
8783
|
}
|
8752
8784
|
});
|
@@ -9008,13 +9040,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9008
9040
|
let effectiveExpectedType = expectedType;
|
9009
9041
|
if (expectedType && (0, types_1.isUnion)(expectedType)) {
|
9010
9042
|
let matchingSubtype;
|
9043
|
+
let matchingSubtypeResult;
|
9011
9044
|
(0, typeUtils_1.doForEachSubtype)(expectedType, (subtype) => {
|
9012
|
-
if
|
9013
|
-
|
9014
|
-
|
9015
|
-
|
9016
|
-
|
9045
|
+
// Use shortcut if we've already found a match.
|
9046
|
+
if (matchingSubtypeResult && !matchingSubtypeResult.typeErrors) {
|
9047
|
+
return;
|
9048
|
+
}
|
9049
|
+
const subtypeResult = useSpeculativeMode(node, () => {
|
9050
|
+
return getTypeOfListOrSetExpected(node, subtype);
|
9051
|
+
});
|
9052
|
+
if (subtypeResult && assignType(subtype, subtypeResult.type)) {
|
9053
|
+
// If this is the first result we're seeing or it's the first result
|
9054
|
+
// without errors, select it as the match.
|
9055
|
+
if (!matchingSubtypeResult || (matchingSubtypeResult.typeErrors && !subtypeResult.typeErrors)) {
|
9017
9056
|
matchingSubtype = subtype;
|
9057
|
+
matchingSubtypeResult = subtypeResult;
|
9018
9058
|
}
|
9019
9059
|
}
|
9020
9060
|
});
|
@@ -9102,8 +9142,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9102
9142
|
entryTypeResult = getElementTypeFromListComprehension(entry);
|
9103
9143
|
}
|
9104
9144
|
else {
|
9105
|
-
entryTypeResult = getTypeOfExpression(entry
|
9106
|
-
/* flags */ undefined, hasExpectedType ? types_1.NeverType.createNever() : undefined);
|
9145
|
+
entryTypeResult = getTypeOfExpression(entry);
|
9107
9146
|
}
|
9108
9147
|
if (entryTypeResult.isIncomplete) {
|
9109
9148
|
isIncomplete = true;
|
@@ -11097,7 +11136,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11097
11136
|
}
|
11098
11137
|
if (dataClassBehaviors) {
|
11099
11138
|
(0, dataClasses_1.applyDataClassDefaultBehaviors)(classType, dataClassBehaviors);
|
11100
|
-
(0, dataClasses_1.applyDataClassClassBehaviorOverrides)(evaluatorInterface, node.name, classType, initSubclassArgs);
|
11139
|
+
(0, dataClasses_1.applyDataClassClassBehaviorOverrides)(evaluatorInterface, node.name, classType, initSubclassArgs, dataClassBehaviors);
|
11101
11140
|
}
|
11102
11141
|
// Run any class hooks that depend on this class.
|
11103
11142
|
runClassTypeHooks(classType);
|
@@ -14415,6 +14454,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14415
14454
|
return getEffectiveTypeOfSymbolForUsage(symbol).type;
|
14416
14455
|
}
|
14417
14456
|
function getEffectiveTypeOfSymbolForUsage(symbol, usageNode, useLastDecl = false) {
|
14457
|
+
var _a;
|
14418
14458
|
// If there's a declared type, it takes precedence over inferred types.
|
14419
14459
|
if (symbol.hasTypedDeclarations()) {
|
14420
14460
|
const declaredType = getDeclaredTypeOfSymbol(symbol, usageNode);
|
@@ -14438,12 +14478,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14438
14478
|
}
|
14439
14479
|
// Look in the cache to see if we've computed this already.
|
14440
14480
|
let cacheEntries = effectiveTypeCache.get(symbol.id);
|
14481
|
+
let evaluationAttempts = 0;
|
14441
14482
|
const usageNodeId = usageNode ? usageNode.id : undefined;
|
14442
14483
|
const effectiveTypeCacheKey = `${usageNodeId === undefined ? '.' : usageNodeId.toString()}${useLastDecl ? '*' : ''}`;
|
14443
14484
|
if (cacheEntries) {
|
14444
14485
|
const result = cacheEntries.get(effectiveTypeCacheKey);
|
14445
14486
|
if (result) {
|
14446
|
-
|
14487
|
+
if (!result.isIncomplete) {
|
14488
|
+
return result;
|
14489
|
+
}
|
14490
|
+
evaluationAttempts = ((_a = result.evaluationAttempts) !== null && _a !== void 0 ? _a : 0) + 1;
|
14447
14491
|
}
|
14448
14492
|
}
|
14449
14493
|
// Infer the type.
|
@@ -14571,8 +14615,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14571
14615
|
}
|
14572
14616
|
isIncomplete = true;
|
14573
14617
|
// Note that at least one decl could not be evaluated because
|
14574
|
-
// it was already in the process of being evaluated.
|
14575
|
-
|
14618
|
+
// it was already in the process of being evaluated. Don't set
|
14619
|
+
// this flag if we've already attempted the type evaluation
|
14620
|
+
// many times because this probably means there's a cyclical
|
14621
|
+
// dependency that cannot be broken.
|
14622
|
+
if (evaluationAttempts < maxEffectiveTypeEvaluationAttempts) {
|
14623
|
+
sawPendingEvaluation = true;
|
14624
|
+
}
|
14576
14625
|
}
|
14577
14626
|
}
|
14578
14627
|
});
|
@@ -14583,6 +14632,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14583
14632
|
includesVariableDecl,
|
14584
14633
|
includesIllegalTypeAliasDecl: !decls.every((decl) => (0, declarationUtils_1.isPossibleTypeAliasDeclaration)(decl)),
|
14585
14634
|
isRecursiveDefinition: false,
|
14635
|
+
evaluationAttempts,
|
14586
14636
|
};
|
14587
14637
|
if (!includesSpeculativeResult) {
|
14588
14638
|
// Add the entry to the cache so we don't need to compute it next time.
|
@@ -14600,6 +14650,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14600
14650
|
includesVariableDecl,
|
14601
14651
|
includesIllegalTypeAliasDecl: !decls.every((decl) => (0, declarationUtils_1.isPossibleTypeAliasDeclaration)(decl)),
|
14602
14652
|
isRecursiveDefinition: false,
|
14653
|
+
evaluationAttempts,
|
14603
14654
|
};
|
14604
14655
|
}
|
14605
14656
|
function getDeclaredTypeOfSymbol(symbol, usageNode) {
|
@@ -14702,6 +14753,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14702
14753
|
var _a;
|
14703
14754
|
let returnType;
|
14704
14755
|
let isIncomplete = false;
|
14756
|
+
let analyzeUnannotatedFunctions = true;
|
14705
14757
|
// Don't attempt to infer the return type for a stub file.
|
14706
14758
|
if (types_1.FunctionType.isStubDefinition(type)) {
|
14707
14759
|
return types_1.UnknownType.create();
|
@@ -14719,8 +14771,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14719
14771
|
}
|
14720
14772
|
else if (type.details.declaration) {
|
14721
14773
|
const functionNode = type.details.declaration.node;
|
14774
|
+
analyzeUnannotatedFunctions =
|
14775
|
+
AnalyzerNodeInfo.getFileInfo(functionNode).diagnosticRuleSet.analyzeUnannotatedFunctions;
|
14722
14776
|
// Skip return type inference if we are in "skip unannotated function" mode.
|
14723
|
-
if (
|
14777
|
+
if (analyzeUnannotatedFunctions && !checkCodeFlowTooComplex(functionNode.suite)) {
|
14724
14778
|
const codeFlowComplexity = AnalyzerNodeInfo.getCodeFlowComplexity(functionNode);
|
14725
14779
|
// For very complex functions that have no annotated parameter types,
|
14726
14780
|
// don't attempt to infer the return type because it can be extremely
|
@@ -14757,7 +14811,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14757
14811
|
// params, try to analyze the function with the provided argument types and
|
14758
14812
|
// attempt to do a better job at inference.
|
14759
14813
|
if (!isIncomplete &&
|
14760
|
-
|
14814
|
+
analyzeUnannotatedFunctions &&
|
14761
14815
|
(0, typeUtils_1.isPartlyUnknown)(returnType) &&
|
14762
14816
|
types_1.FunctionType.hasUnannotatedParams(type) &&
|
14763
14817
|
!types_1.FunctionType.isStubDefinition(type) &&
|
@@ -15391,8 +15445,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15391
15445
|
}
|
15392
15446
|
}
|
15393
15447
|
// Transform recursive type aliases if necessary.
|
15394
|
-
|
15395
|
-
|
15448
|
+
const transformedDestType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(destType);
|
15449
|
+
const transformedSrcType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(srcType);
|
15450
|
+
// Did both the source and dest include recursive type aliases?
|
15451
|
+
// If so, we are potentially dealing with different recursive type
|
15452
|
+
// aliases that are defined in the same way.
|
15453
|
+
if (transformedDestType !== destType &&
|
15454
|
+
transformedSrcType !== srcType &&
|
15455
|
+
(0, types_1.isUnion)(transformedDestType) &&
|
15456
|
+
(0, types_1.isUnion)(transformedSrcType)) {
|
15457
|
+
// Use a smaller recursive limit in this case to prevent runaway recursion.
|
15458
|
+
if (recursionCount > maxRecursiveTypeAliasRecursionCount) {
|
15459
|
+
return true;
|
15460
|
+
}
|
15461
|
+
}
|
15462
|
+
destType = transformedDestType;
|
15463
|
+
srcType = transformedSrcType;
|
15396
15464
|
// If the source or dest is unbound, allow the assignment. The
|
15397
15465
|
// error will be reported elsewhere.
|
15398
15466
|
if ((0, types_1.isUnbound)(destType) || (0, types_1.isUnbound)(srcType)) {
|
@@ -15603,6 +15671,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15603
15671
|
if ((0, types_1.isClassInstance)(expandedSrcType) && types_1.ClassType.isBuiltIn(expandedSrcType, 'type')) {
|
15604
15672
|
const srcTypeArgs = expandedSrcType.typeArguments;
|
15605
15673
|
let typeTypeArg;
|
15674
|
+
let instantiableType;
|
15606
15675
|
if (srcTypeArgs && srcTypeArgs.length >= 1) {
|
15607
15676
|
typeTypeArg = srcTypeArgs[0];
|
15608
15677
|
if ((0, types_1.isAnyOrUnknown)(typeTypeArg)) {
|
@@ -15611,19 +15680,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15611
15680
|
}
|
15612
15681
|
return types_1.TypeBase.isInstantiable(destType);
|
15613
15682
|
}
|
15683
|
+
instantiableType = (0, typeUtils_1.convertToInstantiable)(typeTypeArg);
|
15614
15684
|
}
|
15615
|
-
else {
|
15685
|
+
else if (types_1.TypeBase.isInstantiable(destType)) {
|
15616
15686
|
typeTypeArg = objectType !== null && objectType !== void 0 ? objectType : types_1.AnyType.create();
|
15687
|
+
instantiableType = expandedSrcType;
|
15617
15688
|
}
|
15618
|
-
if (
|
15619
|
-
if (
|
15620
|
-
|
15689
|
+
if (instantiableType && typeTypeArg) {
|
15690
|
+
if ((0, types_1.isClassInstance)(typeTypeArg) || (0, types_1.isTypeVar)(typeTypeArg)) {
|
15691
|
+
if (assignType(destType, instantiableType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
15692
|
+
return true;
|
15693
|
+
}
|
15694
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format({
|
15695
|
+
sourceType: printType(srcType),
|
15696
|
+
destType: printType(destType),
|
15697
|
+
}));
|
15698
|
+
return false;
|
15621
15699
|
}
|
15622
|
-
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format({
|
15623
|
-
sourceType: printType(srcType),
|
15624
|
-
destType: printType(destType),
|
15625
|
-
}));
|
15626
|
-
return false;
|
15627
15700
|
}
|
15628
15701
|
}
|
15629
15702
|
if ((0, types_1.isInstantiableClass)(destType)) {
|
@@ -16086,7 +16159,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16086
16159
|
// in case the destType is a union with hundreds of literals.
|
16087
16160
|
if ((0, types_1.isClassInstance)(srcType) &&
|
16088
16161
|
(0, typeUtils_1.isLiteralType)(srcType) &&
|
16089
|
-
types_1.UnionType.containsType(destType, srcType, recursionCount)) {
|
16162
|
+
types_1.UnionType.containsType(destType, srcType, /* exclusionSet */ undefined, recursionCount)) {
|
16090
16163
|
return true;
|
16091
16164
|
}
|
16092
16165
|
(0, typeUtils_1.doForEachSubtype)(destType, (subtype) => {
|
@@ -16792,6 +16865,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16792
16865
|
name: p.name,
|
16793
16866
|
isNameSynthesized: p.isNameSynthesized,
|
16794
16867
|
hasDefault: !!p.hasDefault,
|
16868
|
+
defaultValueExpression: p.defaultValueExpression,
|
16795
16869
|
type: types_1.FunctionType.getEffectiveParameterType(effectiveSrcType, index),
|
16796
16870
|
});
|
16797
16871
|
}
|
@@ -17230,7 +17304,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17230
17304
|
if ((0, types_1.isAnyOrUnknown)(srcType)) {
|
17231
17305
|
return srcType;
|
17232
17306
|
}
|
17233
|
-
let effectiveSrcType = srcType;
|
17307
|
+
let effectiveSrcType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(srcType);
|
17234
17308
|
if ((0, types_1.isTypeVar)(srcType)) {
|
17235
17309
|
if ((0, types_1.isTypeSame)(srcType, destType)) {
|
17236
17310
|
return srcType;
|
@@ -17244,7 +17318,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17244
17318
|
return srcType;
|
17245
17319
|
}
|
17246
17320
|
// If there's a bound type, make sure the source is derived from it.
|
17247
|
-
if (destType.details.boundType) {
|
17321
|
+
if (destType.details.boundType && !(0, typeUtils_1.isTypeAliasPlaceholder)(effectiveSrcType)) {
|
17248
17322
|
if (!assignType(destType.details.boundType, effectiveSrcType, diag.createAddendum(),
|
17249
17323
|
/* destTypeVarContext */ undefined,
|
17250
17324
|
/* srcTypeVarContext */ undefined)) {
|
@@ -17285,6 +17359,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17285
17359
|
if (constraints.length === 0) {
|
17286
17360
|
return srcType;
|
17287
17361
|
}
|
17362
|
+
if ((0, typeUtils_1.isTypeAliasPlaceholder)(srcType)) {
|
17363
|
+
return srcType;
|
17364
|
+
}
|
17288
17365
|
if ((0, types_1.isTypeVar)(srcType) && srcType.details.constraints.length > 0) {
|
17289
17366
|
// Make sure all the source constraint types map to constraint types in the dest.
|
17290
17367
|
if (srcType.details.constraints.every((sourceConstraint) => {
|