@zzzen/pyright-internal 1.2.0-dev.20230312 → 1.2.0-dev.20230326
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 +15 -0
- package/dist/analyzer/aliasDeclarationUtils.js.map +1 -1
- 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/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 +77 -27
- 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/dataClasses.js +10 -0
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/patternMatching.js +18 -3
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +1 -1
- package/dist/analyzer/program.js +24 -28
- 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/protocols.js +18 -3
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/service.d.ts +2 -1
- package/dist/analyzer/service.js +15 -20
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +2 -2
- package/dist/analyzer/sourceFile.js +2 -2
- 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 +149 -84
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +0 -2
- package/dist/analyzer/typeEvaluatorTypes.js +0 -3
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeStubWriter.js +2 -0
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.js +40 -1
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.js +27 -0
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +5 -1
- package/dist/analyzer/types.js +3 -1
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +4 -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 +5 -1
- 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.map +1 -1
- package/dist/common/extensions.js +3 -1
- package/dist/common/extensions.js.map +1 -1
- package/dist/common/fileBasedCancellationUtils.js +4 -0
- package/dist/common/fileBasedCancellationUtils.js.map +1 -1
- package/dist/languageServerBase.d.ts +21 -46
- package/dist/languageServerBase.js +110 -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.js +4 -6
- 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/signatureHelpProvider.js +9 -7
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +14 -6
- package/dist/localization/localize.js +5 -4
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +7 -6
- package/dist/parser/parser.js +4 -2
- package/dist/parser/parser.js.map +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 +42 -2
- package/dist/tests/completions.test.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 +50 -0
- package/dist/tests/hoverProvider.test.js.map +1 -1
- package/dist/tests/moveSymbol.misc.test.js +1 -1
- 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 +10 -2
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +6 -2
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +6 -2
- 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
@@ -7,9 +7,25 @@
|
|
7
7
|
* Collection of functions that operate on SourceFileInfo objects.
|
8
8
|
*/
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
10
|
-
exports.isUserCode = void 0;
|
10
|
+
exports.collectImportedByFiles = exports.isUserCode = void 0;
|
11
11
|
function isUserCode(fileInfo) {
|
12
12
|
return !!fileInfo && fileInfo.isTracked && !fileInfo.isThirdPartyImport && !fileInfo.isTypeshedFile;
|
13
13
|
}
|
14
14
|
exports.isUserCode = isUserCode;
|
15
|
+
function collectImportedByFiles(fileInfo) {
|
16
|
+
const importedByFiles = new Set();
|
17
|
+
_collectImportedByFiles(fileInfo, importedByFiles);
|
18
|
+
return importedByFiles;
|
19
|
+
}
|
20
|
+
exports.collectImportedByFiles = collectImportedByFiles;
|
21
|
+
function _collectImportedByFiles(fileInfo, importedByFiles) {
|
22
|
+
fileInfo.importedBy.forEach((dep) => {
|
23
|
+
if (importedByFiles.has(dep)) {
|
24
|
+
// Already visited.
|
25
|
+
return;
|
26
|
+
}
|
27
|
+
importedByFiles.add(dep);
|
28
|
+
_collectImportedByFiles(dep, importedByFiles);
|
29
|
+
});
|
30
|
+
}
|
15
31
|
//# sourceMappingURL=sourceFileInfoUtils.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"sourceFileInfoUtils.js","sourceRoot":"","sources":["../../../src/analyzer/sourceFileInfoUtils.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAIH,SAAgB,UAAU,CAAC,QAAoC;IAC3D,OAAO,CAAC,CAAC,QAAQ,IAAI,QAAQ,CAAC,SAAS,IAAI,CAAC,QAAQ,CAAC,kBAAkB,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC;AACxG,CAAC;AAFD,gCAEC"}
|
1
|
+
{"version":3,"file":"sourceFileInfoUtils.js","sourceRoot":"","sources":["../../../src/analyzer/sourceFileInfoUtils.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAIH,SAAgB,UAAU,CAAC,QAAoC;IAC3D,OAAO,CAAC,CAAC,QAAQ,IAAI,QAAQ,CAAC,SAAS,IAAI,CAAC,QAAQ,CAAC,kBAAkB,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC;AACxG,CAAC;AAFD,gCAEC;AAED,SAAgB,sBAAsB,CAAC,QAAwB;IAC3D,MAAM,eAAe,GAAG,IAAI,GAAG,EAAkB,CAAC;IAClD,uBAAuB,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;IACnD,OAAO,eAAe,CAAC;AAC3B,CAAC;AAJD,wDAIC;AAED,SAAS,uBAAuB,CAAC,QAAwB,EAAE,eAAoC;IAC3F,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAChC,IAAI,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YAC1B,mBAAmB;YACnB,OAAO;SACV;QAED,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACzB,uBAAuB,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACP,CAAC"}
|
@@ -705,11 +705,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
705
705
|
}
|
706
706
|
}
|
707
707
|
}
|
708
|
-
if (flags & 65536 /* DisallowRecursiveTypeAliasPlaceholder */) {
|
709
|
-
if ((0, types_1.isTypeVar)(typeResult.type) && (0, typeUtils_1.isTypeAliasPlaceholder)(typeResult.type)) {
|
710
|
-
typeResult.type.details.illegalRecursionDetected = true;
|
711
|
-
}
|
712
|
-
}
|
713
708
|
writeTypeCache(node, typeResult, flags, inferenceContext, /* allowSpeculativeCaching */ true);
|
714
709
|
if (inferenceContext &&
|
715
710
|
!(0, types_1.isAnyOrUnknown)(inferenceContext.expectedType) &&
|
@@ -946,7 +941,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
946
941
|
return getTypeOfAnnotation(paramTypeNode, {
|
947
942
|
associateTypeVarsWithScope: true,
|
948
943
|
allowTypeVarTuple: paramCategory === 1 /* VarArgList */,
|
949
|
-
disallowRecursiveTypeAlias: true,
|
950
944
|
allowUnpackedTypedDict: paramCategory === 2 /* VarArgDictionary */,
|
951
945
|
allowUnpackedTuple: paramCategory === 1 /* VarArgList */,
|
952
946
|
});
|
@@ -990,9 +984,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
990
984
|
else {
|
991
985
|
evaluatorFlags |= 4096 /* DisallowTypeVarsWithoutScopeId */;
|
992
986
|
}
|
993
|
-
if (options === null || options === void 0 ? void 0 : options.disallowRecursiveTypeAlias) {
|
994
|
-
evaluatorFlags |= 65536 /* DisallowRecursiveTypeAliasPlaceholder */;
|
995
|
-
}
|
996
987
|
if (options === null || options === void 0 ? void 0 : options.allowUnpackedTypedDict) {
|
997
988
|
evaluatorFlags |= 8388608 /* AllowUnpackedTypedDict */;
|
998
989
|
}
|
@@ -3526,6 +3517,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3526
3517
|
}
|
3527
3518
|
}
|
3528
3519
|
}
|
3520
|
+
// If the field was not found and the module type is marked
|
3521
|
+
// such that all fields should be Any/Unknown, return that type.
|
3522
|
+
if (!type && baseType.notPresentFieldType) {
|
3523
|
+
type = baseType.notPresentFieldType;
|
3524
|
+
}
|
3529
3525
|
if (!type) {
|
3530
3526
|
if (!isIncomplete) {
|
3531
3527
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.moduleUnknownMember().format({
|
@@ -3668,7 +3664,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3668
3664
|
return { type, isIncomplete, isAsymmetricDescriptor, isRequired, isNotRequired };
|
3669
3665
|
}
|
3670
3666
|
function getTypeOfClassMemberName(errorNode, classType, isAccessedThroughObject, memberName, usage, diag, flags, bindToType) {
|
3671
|
-
var _a, _b
|
3667
|
+
var _a, _b;
|
3672
3668
|
let classLookupFlags = 0 /* Default */;
|
3673
3669
|
if (flags & 1 /* AccessClassMembersOnly */) {
|
3674
3670
|
classLookupFlags |= 8 /* SkipInstanceVariables */;
|
@@ -3709,10 +3705,27 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3709
3705
|
if (containingClassType &&
|
3710
3706
|
(0, types_1.isInstantiableClass)(containingClassType) &&
|
3711
3707
|
types_1.ClassType.isSameGenericClass(containingClassType, classType)) {
|
3712
|
-
type = (
|
3708
|
+
type = (_b = getDeclaredTypeOfSymbol(memberInfo.symbol)) === null || _b === void 0 ? void 0 : _b.type;
|
3713
3709
|
if (type && (0, types_1.isInstantiableClass)(memberInfo.classType)) {
|
3714
3710
|
type = (0, typeUtils_1.partiallySpecializeType)(type, memberInfo.classType);
|
3715
3711
|
}
|
3712
|
+
// If we're setting a class variable via a write through an object,
|
3713
|
+
// this is normally considered a type violation. But it is allowed
|
3714
|
+
// if the class variable is a descriptor object. In this case, we will
|
3715
|
+
// clear the flag that causes an error to be generated.
|
3716
|
+
if (usage.method === 'set' && memberInfo.symbol.isClassVar() && isAccessedThroughObject) {
|
3717
|
+
const selfClass = bindToType || memberName === '__new__' ? undefined : classType;
|
3718
|
+
const typeResult = getTypeOfMemberInternal(memberInfo, selfClass);
|
3719
|
+
if (typeResult) {
|
3720
|
+
if ((0, typeUtils_1.isDescriptorInstance)(typeResult.type, /* requireSetter */ true)) {
|
3721
|
+
type = typeResult.type;
|
3722
|
+
flags &= 8 /* DisallowClassVarWrites */;
|
3723
|
+
}
|
3724
|
+
}
|
3725
|
+
}
|
3726
|
+
if (!type) {
|
3727
|
+
type = types_1.UnknownType.create();
|
3728
|
+
}
|
3716
3729
|
}
|
3717
3730
|
}
|
3718
3731
|
}
|
@@ -4477,18 +4490,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4477
4490
|
typeArgType = types_1.UnknownType.create();
|
4478
4491
|
}
|
4479
4492
|
if ((flags & 16384 /* EnforceTypeVarVarianceConsistency */) !== 0) {
|
4480
|
-
|
4481
|
-
|
4482
|
-
|
4483
|
-
|
4484
|
-
|
4485
|
-
|
4486
|
-
|
4487
|
-
|
4488
|
-
|
4489
|
-
|
4490
|
-
messageDiag.addTextRange(typeArgs[index].node);
|
4491
|
-
}
|
4493
|
+
const usageVariances = inferTypeParameterVarianceForTypeAlias(baseType);
|
4494
|
+
if (usageVariances && index < usageVariances.length) {
|
4495
|
+
const usageVariance = usageVariances[index];
|
4496
|
+
if (!(0, typeUtils_1.isVarianceOfTypeArgumentCompatible)(typeArgType, usageVariance)) {
|
4497
|
+
const messageDiag = diag.createAddendum();
|
4498
|
+
messageDiag.addMessage(localize_1.Localizer.DiagnosticAddendum.varianceMismatchForTypeAlias().format({
|
4499
|
+
typeVarName: printType(typeArgType),
|
4500
|
+
typeAliasParam: printType(typeParameters[index]),
|
4501
|
+
}));
|
4502
|
+
messageDiag.addTextRange(typeArgs[index].node);
|
4492
4503
|
}
|
4493
4504
|
}
|
4494
4505
|
}
|
@@ -4548,10 +4559,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4548
4559
|
// See if the class has a custom metaclass that supports __getitem__, etc.
|
4549
4560
|
if (concreteSubtype.details.effectiveMetaclass &&
|
4550
4561
|
(0, types_1.isInstantiableClass)(concreteSubtype.details.effectiveMetaclass) &&
|
4551
|
-
!types_1.ClassType.isBuiltIn(concreteSubtype.details.effectiveMetaclass, ['type', '_InitVarMeta'])
|
4562
|
+
!types_1.ClassType.isBuiltIn(concreteSubtype.details.effectiveMetaclass, ['type', '_InitVarMeta']) &&
|
4563
|
+
(flags & 128 /* ExpectingType */) === 0) {
|
4552
4564
|
const itemMethodType = getTypeOfClassMember(node, concreteSubtype, getIndexAccessMagicMethodName(usage),
|
4553
4565
|
/* usage */ undefined,
|
4554
4566
|
/* diag */ undefined, 64 /* SkipAttributeAccessOverride */ | 32 /* ConsiderMetaclassOnly */);
|
4567
|
+
if (flags & 256 /* ExpectingTypeAnnotation */) {
|
4568
|
+
// If the class doesn't derive from Generic, a type argument should not be allowed.
|
4569
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeArgsExpectingNone().format({
|
4570
|
+
name: printType(types_1.ClassType.cloneAsInstance(concreteSubtype)),
|
4571
|
+
}), node);
|
4572
|
+
}
|
4555
4573
|
if (itemMethodType) {
|
4556
4574
|
return getTypeOfIndexedObjectOrClass(node, concreteSubtype, usage).type;
|
4557
4575
|
}
|
@@ -4725,9 +4743,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4725
4743
|
// the type alias' type parameters?
|
4726
4744
|
subtype.typeArguments.forEach((typeArg, classParamIndex) => {
|
4727
4745
|
var _a;
|
4728
|
-
if (
|
4746
|
+
if ((0, typeUtils_1.isTupleClass)(subtype)) {
|
4747
|
+
updateUsageVarianceForType(typeArg, 3 /* Covariant */);
|
4748
|
+
}
|
4749
|
+
else if (classParamIndex < subtype.details.typeParameters.length) {
|
4729
4750
|
const classTypeParam = subtype.details.typeParameters[classParamIndex];
|
4730
|
-
|
4751
|
+
if ((0, types_1.isUnpackedClass)(typeArg) && typeArg.tupleTypeArguments) {
|
4752
|
+
typeArg.tupleTypeArguments.forEach((tupleTypeArg) => {
|
4753
|
+
updateUsageVarianceForType(tupleTypeArg.type, 2 /* Invariant */);
|
4754
|
+
});
|
4755
|
+
}
|
4756
|
+
else {
|
4757
|
+
updateUsageVarianceForType(typeArg, (_a = classTypeParam.computedVariance) !== null && _a !== void 0 ? _a : classTypeParam.details.declaredVariance);
|
4758
|
+
}
|
4731
4759
|
}
|
4732
4760
|
});
|
4733
4761
|
}
|
@@ -4967,7 +4995,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4967
4995
|
adjFlags &= ~(2 /* DoNotSpecialize */ |
|
4968
4996
|
32 /* DisallowParamSpec */ |
|
4969
4997
|
64 /* DisallowTypeVarTuple */ |
|
4970
|
-
1048576 /* AllowRequired */
|
4998
|
+
1048576 /* AllowRequired */ |
|
4999
|
+
16384 /* EnforceTypeVarVarianceConsistency */);
|
4971
5000
|
if (!(options === null || options === void 0 ? void 0 : options.isAnnotatedClass)) {
|
4972
5001
|
adjFlags |= 131072 /* DisallowClassVar */ | 16 /* DisallowFinal */;
|
4973
5002
|
}
|
@@ -6277,7 +6306,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6277
6306
|
}
|
6278
6307
|
let returnType = mapSubtypesExpandTypeVars(callTypeResult.type,
|
6279
6308
|
/* conditionFilter */ undefined, (expandedSubtype, unexpandedSubtype) => {
|
6280
|
-
var _a, _b, _c, _d, _e, _f;
|
6309
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
6281
6310
|
switch (expandedSubtype.category) {
|
6282
6311
|
case 1 /* Unknown */:
|
6283
6312
|
case 2 /* Any */: {
|
@@ -6463,7 +6492,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6463
6492
|
return types_1.AnyType.create();
|
6464
6493
|
}
|
6465
6494
|
if ((0, types_1.isClass)(unexpandedSubtype) && (0, enums_1.isKnownEnumType)(className)) {
|
6466
|
-
return (0, enums_1.createEnumType)(errorNode, expandedSubtype, argList);
|
6495
|
+
return (_d = (0, enums_1.createEnumType)(errorNode, expandedSubtype, argList)) !== null && _d !== void 0 ? _d : types_1.UnknownType.create();
|
6467
6496
|
}
|
6468
6497
|
if (className === 'TypedDict') {
|
6469
6498
|
return (0, typedDicts_1.createTypedDictType)(evaluatorInterface, errorNode, expandedSubtype, argList);
|
@@ -6548,7 +6577,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6548
6577
|
return returnType;
|
6549
6578
|
}
|
6550
6579
|
else {
|
6551
|
-
const memberType = (
|
6580
|
+
const memberType = (_e = getTypeOfObjectMember(errorNode, expandedSubtype, '__call__',
|
6581
|
+
/* usage */ undefined,
|
6582
|
+
/* diag */ undefined, 64 /* SkipAttributeAccessOverride */)) === null || _e === void 0 ? void 0 : _e.type;
|
6552
6583
|
if (memberType) {
|
6553
6584
|
const functionResult = validateCallArguments(errorNode, argList, { type: memberType }, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
|
6554
6585
|
overloadsUsedForCall.push(...functionResult.overloadsUsedForCall);
|
@@ -6563,7 +6594,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6563
6594
|
// will instantiate an object of type T.
|
6564
6595
|
return (0, typeUtils_1.convertToInstance)(unexpandedSubtype);
|
6565
6596
|
}
|
6566
|
-
return (
|
6597
|
+
return (_f = functionResult.returnType) !== null && _f !== void 0 ? _f : types_1.UnknownType.create();
|
6567
6598
|
}
|
6568
6599
|
if (!memberType || !(0, types_1.isAnyOrUnknown)(memberType)) {
|
6569
6600
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.objectNotCallable().format({
|
@@ -6600,7 +6631,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6600
6631
|
if (callResult.argumentErrors) {
|
6601
6632
|
argumentErrors = true;
|
6602
6633
|
}
|
6603
|
-
return (
|
6634
|
+
return (_g = callResult.returnType) !== null && _g !== void 0 ? _g : types_1.UnknownType.create();
|
6604
6635
|
}
|
6605
6636
|
case 8 /* Module */: {
|
6606
6637
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.moduleNotCallable(), errorNode);
|
@@ -7047,7 +7078,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7047
7078
|
// Now consume any keyword arguments.
|
7048
7079
|
while (argIndex < argList.length) {
|
7049
7080
|
if (argList[argIndex].argumentCategory === 2 /* UnpackedDictionary */) {
|
7050
|
-
// Verify that the type used in this expression is a
|
7081
|
+
// Verify that the type used in this expression is a SupportsKeysAndGetItem[str, T].
|
7051
7082
|
const argType = getTypeOfArgument(argList[argIndex]).type;
|
7052
7083
|
if ((0, types_1.isAnyOrUnknown)(argType)) {
|
7053
7084
|
unpackedDictionaryArgType = argType;
|
@@ -7131,7 +7162,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7131
7162
|
}
|
7132
7163
|
}
|
7133
7164
|
else {
|
7134
|
-
|
7165
|
+
let mappingType = getTypeshedType(errorNode, 'SupportsKeysAndGetItem');
|
7166
|
+
if (!mappingType) {
|
7167
|
+
mappingType = getTypingType(errorNode, 'Mapping');
|
7168
|
+
}
|
7135
7169
|
const strObjType = getBuiltInObject(errorNode, 'str');
|
7136
7170
|
if (mappingType &&
|
7137
7171
|
(0, types_1.isInstantiableClass)(mappingType) &&
|
@@ -7707,7 +7741,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7707
7741
|
specializedReturnType.typeArguments &&
|
7708
7742
|
specializedReturnType.typeArguments.length > 0) {
|
7709
7743
|
if (boolClassType && (0, types_1.isInstantiableClass)(boolClassType)) {
|
7710
|
-
|
7744
|
+
let typeGuardType = specializedReturnType.typeArguments[0];
|
7745
|
+
// If the first argument is a simple (non-constrained) TypeVar,
|
7746
|
+
// associate that TypeVar with the resulting TypeGuard type.
|
7747
|
+
if (argResults.length > 0) {
|
7748
|
+
const arg0Type = argResults[0].argType;
|
7749
|
+
if ((0, types_1.isTypeVar)(arg0Type) &&
|
7750
|
+
!arg0Type.details.isParamSpec &&
|
7751
|
+
arg0Type.details.constraints.length === 0) {
|
7752
|
+
typeGuardType = (0, typeUtils_1.addConditionToType)(typeGuardType, [
|
7753
|
+
{
|
7754
|
+
typeVarName: types_1.TypeVarType.getNameWithScope(arg0Type),
|
7755
|
+
constraintIndex: 0,
|
7756
|
+
isConstrainedTypeVar: false,
|
7757
|
+
},
|
7758
|
+
]);
|
7759
|
+
}
|
7760
|
+
}
|
7761
|
+
specializedReturnType = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForTypeGuard(boolClassType, typeGuardType, types_1.ClassType.isBuiltIn(specializedReturnType, 'StrictTypeGuard')));
|
7711
7762
|
}
|
7712
7763
|
}
|
7713
7764
|
specializedReturnType = adjustCallableReturnType(specializedReturnType);
|
@@ -10486,7 +10537,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10486
10537
|
!ParseTreeUtils.isNodeContainedWithin(errorNode, firstParamTypeAnnotation)) {
|
10487
10538
|
const annotationType = getTypeOfAnnotation(firstParamTypeAnnotation, {
|
10488
10539
|
associateTypeVarsWithScope: true,
|
10489
|
-
disallowRecursiveTypeAlias: true,
|
10490
10540
|
});
|
10491
10541
|
if (!(0, types_1.isTypeVar)(annotationType) || !annotationType.details.isSynthesizedSelf) {
|
10492
10542
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.selfTypeWithTypedSelfOrCls(), errorNode);
|
@@ -11145,11 +11195,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11145
11195
|
// can be specialized.
|
11146
11196
|
typeAliasTypeVar.details.recursiveTypeParameters = (_a = rightHandType.typeAliasInfo) === null || _a === void 0 ? void 0 : _a.typeParameters;
|
11147
11197
|
}
|
11148
|
-
if (typeAliasTypeVar.details.illegalRecursionDetected) {
|
11149
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasIsRecursiveIndirect().format({
|
11150
|
-
name: typeAliasNameNode.value,
|
11151
|
-
}), node.leftExpression);
|
11152
|
-
}
|
11153
11198
|
}
|
11154
11199
|
}
|
11155
11200
|
}
|
@@ -11235,11 +11280,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11235
11280
|
// Set the resulting type to the boundType of the original type alias
|
11236
11281
|
// to support recursive type aliases.
|
11237
11282
|
typeAliasTypeVar.details.boundType = aliasType;
|
11238
|
-
if (typeAliasTypeVar.details.illegalRecursionDetected) {
|
11239
|
-
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasIsRecursiveIndirect().format({
|
11240
|
-
name: node.name.value,
|
11241
|
-
}), node.name);
|
11242
|
-
}
|
11243
11283
|
writeTypeCache(node.name, { type: aliasType, isIncomplete }, 0 /* None */);
|
11244
11284
|
return aliasType;
|
11245
11285
|
}
|
@@ -12437,7 +12477,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12437
12477
|
functionType.details.declaredReturnType = types_1.UnknownType.create();
|
12438
12478
|
const returnType = getTypeOfAnnotation(returnTypeAnnotationNode, {
|
12439
12479
|
associateTypeVarsWithScope: true,
|
12440
|
-
disallowRecursiveTypeAlias: true,
|
12441
12480
|
});
|
12442
12481
|
functionType.details.declaredReturnType = returnType;
|
12443
12482
|
}
|
@@ -13609,7 +13648,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13609
13648
|
annotationNode === annotationParent.returnTypeAnnotation) {
|
13610
13649
|
getTypeOfAnnotation(annotationNode, {
|
13611
13650
|
associateTypeVarsWithScope: true,
|
13612
|
-
disallowRecursiveTypeAlias: true,
|
13613
13651
|
});
|
13614
13652
|
return;
|
13615
13653
|
}
|
@@ -15001,8 +15039,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15001
15039
|
moduleType.fields = lookupResults.symbolTable;
|
15002
15040
|
moduleType.docString = lookupResults.docString;
|
15003
15041
|
}
|
15004
|
-
else
|
15005
|
-
|
15042
|
+
else {
|
15043
|
+
// Note that all module attributes that are not found in the
|
15044
|
+
// symbol table should be treated as Any or Unknown rather than
|
15045
|
+
// as an error.
|
15046
|
+
moduleType.notPresentFieldType = evaluatorOptions.evaluateUnknownImportsAsAny
|
15047
|
+
? types_1.AnyType.create()
|
15048
|
+
: types_1.UnknownType.create();
|
15006
15049
|
}
|
15007
15050
|
}
|
15008
15051
|
if (loaderActions.implicitImports) {
|
@@ -15085,15 +15128,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15085
15128
|
if (((_a = resolvedDecl.inferredTypeSource) === null || _a === void 0 ? void 0 : _a.nodeType) === 9 /* Call */) {
|
15086
15129
|
const baseTypeResult = getTypeOfExpression(resolvedDecl.inferredTypeSource.leftExpression, 2 /* DoNotSpecialize */);
|
15087
15130
|
const callType = baseTypeResult.type;
|
15088
|
-
|
15089
|
-
|
15090
|
-
|
15091
|
-
|
15092
|
-
|
15093
|
-
|
15094
|
-
|
15095
|
-
|
15096
|
-
|
15131
|
+
const exemptBuiltins = [
|
15132
|
+
'TypeVar',
|
15133
|
+
'ParamSpec',
|
15134
|
+
'TypeVarTuple',
|
15135
|
+
'TypedDict',
|
15136
|
+
'NamedTuple',
|
15137
|
+
'NewType',
|
15138
|
+
];
|
15139
|
+
if ((0, types_1.isInstantiableClass)(callType) && types_1.ClassType.isBuiltIn(callType, exemptBuiltins)) {
|
15140
|
+
isUnambiguousType = true;
|
15141
|
+
}
|
15142
|
+
else if ((0, types_1.isFunction)(callType) &&
|
15143
|
+
exemptBuiltins.some((name) => callType.details.builtInName === name)) {
|
15097
15144
|
isUnambiguousType = true;
|
15098
15145
|
}
|
15099
15146
|
}
|
@@ -15320,6 +15367,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15320
15367
|
if (sawExplicitTypeAlias) {
|
15321
15368
|
considerDecl = false;
|
15322
15369
|
}
|
15370
|
+
// If the symbol is explicitly marked as a ClassVar, consider only the
|
15371
|
+
// declarations that assign to it from within the class body, not through
|
15372
|
+
// a member access expression.
|
15373
|
+
if (symbol.isClassVar() && decl.type === 1 /* Variable */ && decl.isDefinedByMemberAccess) {
|
15374
|
+
considerDecl = false;
|
15375
|
+
}
|
15323
15376
|
if (usageNode !== undefined) {
|
15324
15377
|
if (decl.type !== 8 /* Alias */) {
|
15325
15378
|
// Is the declaration in the same execution scope as the "usageNode" node?
|
@@ -16783,6 +16836,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16783
16836
|
if ((0, types_1.isTypeSame)(srcType, destType, {}, recursionCount)) {
|
16784
16837
|
return true;
|
16785
16838
|
}
|
16839
|
+
// Sort the subtypes so we have a deterministic order for unions.
|
16840
|
+
let sortedSrcTypes = (0, typeUtils_1.sortTypes)(srcType.subtypes);
|
16786
16841
|
// Handle the case where the source and dest are both unions. Try
|
16787
16842
|
// to eliminate as many exact type matches between the src and dest.
|
16788
16843
|
if ((0, types_1.isUnion)(destType)) {
|
@@ -16797,8 +16852,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16797
16852
|
return true;
|
16798
16853
|
}
|
16799
16854
|
const remainingDestSubtypes = [];
|
16800
|
-
let remainingSrcSubtypes =
|
16801
|
-
let
|
16855
|
+
let remainingSrcSubtypes = sortedSrcTypes;
|
16856
|
+
let canUseFastPath = true;
|
16802
16857
|
// First attempt to match all of the non-generic types in the dest
|
16803
16858
|
// to non-generic types in the source.
|
16804
16859
|
destType.subtypes.forEach((destSubtype) => {
|
@@ -16817,7 +16872,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16817
16872
|
});
|
16818
16873
|
// For all remaining source subtypes, attempt to find a dest subtype
|
16819
16874
|
// whose primary type matches.
|
16820
|
-
|
16875
|
+
remainingSrcSubtypes.forEach((srcSubtype) => {
|
16821
16876
|
const destTypeIndex = remainingDestSubtypes.findIndex((destSubtype) => {
|
16822
16877
|
if ((0, types_1.isClass)(srcSubtype) &&
|
16823
16878
|
(0, types_1.isClass)(destSubtype) &&
|
@@ -16834,7 +16889,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16834
16889
|
});
|
16835
16890
|
if (destTypeIndex >= 0) {
|
16836
16891
|
if (!assignType(remainingDestSubtypes[destTypeIndex], srcSubtype, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
16837
|
-
|
16892
|
+
canUseFastPath = false;
|
16838
16893
|
}
|
16839
16894
|
remainingDestSubtypes.splice(destTypeIndex, 1);
|
16840
16895
|
remainingSrcSubtypes = remainingSrcSubtypes.filter((t) => t !== srcSubtype);
|
@@ -16842,11 +16897,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16842
16897
|
});
|
16843
16898
|
// If there is are remaining dest subtypes and they're all type variables,
|
16844
16899
|
// attempt to assign the remaining source subtypes to them.
|
16845
|
-
if (
|
16900
|
+
if (canUseFastPath && (remainingDestSubtypes.length !== 0 || remainingSrcSubtypes.length !== 0)) {
|
16846
16901
|
const isReversed = (flags & 2 /* ReverseTypeVarMatching */) !== 0;
|
16847
16902
|
const effectiveDestSubtypes = isReversed ? remainingSrcSubtypes : remainingDestSubtypes;
|
16848
16903
|
if (effectiveDestSubtypes.length === 0 || effectiveDestSubtypes.some((t) => !(0, types_1.isTypeVar)(t))) {
|
16849
|
-
|
16904
|
+
canUseFastPath = false;
|
16905
|
+
// We can avoid checking the source subtypes that have already been checked.
|
16906
|
+
sortedSrcTypes = remainingSrcSubtypes;
|
16850
16907
|
}
|
16851
16908
|
else if (remainingDestSubtypes.length === remainingSrcSubtypes.length) {
|
16852
16909
|
// If the number of remaining source subtypes is the same as the number
|
@@ -16854,9 +16911,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16854
16911
|
remainingDestSubtypes.forEach((destSubtype, index) => {
|
16855
16912
|
const srcSubtype = remainingSrcSubtypes[index];
|
16856
16913
|
if (!assignType(destSubtype, srcSubtype, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
16857
|
-
|
16914
|
+
canUseFastPath = false;
|
16858
16915
|
}
|
16859
16916
|
});
|
16917
|
+
// We can avoid checking the source subtypes that have already been checked.
|
16918
|
+
sortedSrcTypes = remainingSrcSubtypes;
|
16860
16919
|
}
|
16861
16920
|
else if (remainingSrcSubtypes.length === 0) {
|
16862
16921
|
if ((flags & 1024 /* PopulatingExpectedType */) !== 0) {
|
@@ -16870,24 +16929,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16870
16929
|
}
|
16871
16930
|
// If we've assigned all of the source subtypes but one or more dest
|
16872
16931
|
// TypeVars have gone unmatched, treat this as success.
|
16873
|
-
return true;
|
16874
16932
|
}
|
16875
16933
|
else {
|
16876
16934
|
// Try to assign a union of the remaining source types to
|
16877
16935
|
// the first destination TypeVar.
|
16878
16936
|
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)) {
|
16879
|
-
|
16937
|
+
canUseFastPath = false;
|
16880
16938
|
}
|
16881
16939
|
}
|
16882
16940
|
}
|
16883
|
-
if (
|
16941
|
+
if (canUseFastPath) {
|
16884
16942
|
return true;
|
16885
16943
|
}
|
16886
16944
|
}
|
16887
|
-
// For union sources, all of the types need to be assignable to the dest.
|
16888
16945
|
let isIncompatible = false;
|
16889
|
-
|
16890
|
-
(0, typeUtils_1.doForEachSubtype)(srcType, (subtype, subtypeIndex, allSubtypes) => {
|
16946
|
+
sortedSrcTypes.forEach((subtype) => {
|
16891
16947
|
if (isIncompatible) {
|
16892
16948
|
return;
|
16893
16949
|
}
|
@@ -16897,11 +16953,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16897
16953
|
// Determine if the current subtype is subsumed by another subtype
|
16898
16954
|
// in the same union. If so, we can ignore this.
|
16899
16955
|
let isSubtypeSubsumed = false;
|
16900
|
-
|
16901
|
-
if (isSubtypeSubsumed
|
16902
|
-
|
16903
|
-
|
16904
|
-
|
16956
|
+
srcType.subtypes.forEach((innerSubtype) => {
|
16957
|
+
if (!isSubtypeSubsumed &&
|
16958
|
+
!(0, types_1.isTypeSame)(innerSubtype, subtype) &&
|
16959
|
+
!(0, types_1.isAnyOrUnknown)(innerSubtype) &&
|
16960
|
+
isProperSubtype(innerSubtype, concreteSubtype, recursionCount)) {
|
16905
16961
|
isSubtypeSubsumed = true;
|
16906
16962
|
}
|
16907
16963
|
});
|
@@ -16911,8 +16967,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16911
16967
|
isIncompatible = true;
|
16912
16968
|
}
|
16913
16969
|
}
|
16914
|
-
},
|
16915
|
-
/* sortSubtypes */ true);
|
16970
|
+
}, /* sortSubtypes */ true);
|
16916
16971
|
if (isIncompatible) {
|
16917
16972
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format({
|
16918
16973
|
sourceType: printType(srcType),
|
@@ -17134,6 +17189,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17134
17189
|
if (!constructorFunction.details.docString && classType.details.docString) {
|
17135
17190
|
constructorFunction.details.docString = classType.details.docString;
|
17136
17191
|
}
|
17192
|
+
constructorFunction.details.flags &= ~4 /* StaticMethod */;
|
17137
17193
|
}
|
17138
17194
|
return constructorFunction;
|
17139
17195
|
};
|
@@ -17171,6 +17227,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17171
17227
|
if (!constructorFunction.details.docString && classType.details.docString) {
|
17172
17228
|
constructorFunction.details.docString = classType.details.docString;
|
17173
17229
|
}
|
17230
|
+
constructorFunction.details.flags &= ~(4 /* StaticMethod */ | 1 /* ConstructorMethod */);
|
17174
17231
|
}
|
17175
17232
|
return constructorFunction;
|
17176
17233
|
};
|
@@ -17195,7 +17252,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17195
17252
|
}
|
17196
17253
|
}
|
17197
17254
|
// Return a generic constructor.
|
17198
|
-
const constructorFunction = types_1.FunctionType.createSynthesizedInstance('__new__',
|
17255
|
+
const constructorFunction = types_1.FunctionType.createSynthesizedInstance('__new__', 0 /* None */);
|
17199
17256
|
constructorFunction.details.declaredReturnType = types_1.ClassType.cloneAsInstance(classType);
|
17200
17257
|
types_1.FunctionType.addDefaultParameters(constructorFunction);
|
17201
17258
|
if (!constructorFunction.details.docString && classType.details.docString) {
|
@@ -17908,12 +17965,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17908
17965
|
return narrowedSubtype;
|
17909
17966
|
});
|
17910
17967
|
// If the result of narrowing is Any, stick with the declared (unnarrowed) type.
|
17911
|
-
// If the result of narrowing is an Unknown that is
|
17912
|
-
//
|
17913
|
-
//
|
17914
|
-
|
17968
|
+
// If the result of narrowing is an Unknown that is incomplete, propagate the
|
17969
|
+
// incomplete type for the benefit of code flow analysis.
|
17970
|
+
// If the result of narrowing is a complete Unknown, combine the Unknown type
|
17971
|
+
// with the declared type. In strict mode, this will retain the "unknown type"
|
17972
|
+
// diagnostics while still providing reasonable completion suggestions.
|
17973
|
+
if ((0, types_1.isAny)(narrowedType)) {
|
17915
17974
|
return declaredType;
|
17916
17975
|
}
|
17976
|
+
else if ((0, typeUtils_1.isIncompleteUnknown)(narrowedType)) {
|
17977
|
+
return narrowedType;
|
17978
|
+
}
|
17979
|
+
else if ((0, types_1.isUnknown)(narrowedType)) {
|
17980
|
+
return (0, types_1.combineTypes)([narrowedType, declaredType]);
|
17981
|
+
}
|
17917
17982
|
return narrowedType;
|
17918
17983
|
}
|
17919
17984
|
function validateOverrideMethod(baseMethod, overrideMethod, diag, enforceParamNames = true) {
|