@zzzen/pyright-internal 1.2.0-dev.20230730 → 1.2.0-dev.20230813
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 +6 -5
- package/dist/analyzer/backgroundAnalysisProgram.js +6 -5
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/binder.js +3 -0
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +5 -3
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +10 -6
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolver.d.ts +1 -0
- package/dist/analyzer/constraintSolver.js +30 -23
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/dataClasses.js +2 -2
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/decorators.js +8 -8
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/docStringConversion.js +9 -5
- package/dist/analyzer/docStringConversion.js.map +1 -1
- package/dist/analyzer/enums.js +1 -1
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/importResolver.js +15 -14
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +4 -1
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parameterUtils.js +5 -1
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +3 -3
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +4 -1
- package/dist/analyzer/program.js +8 -10
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/protocols.js +28 -20
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/service.d.ts +3 -0
- package/dist/analyzer/service.js +44 -9
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +127 -78
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +5 -1
- package/dist/analyzer/typeEvaluatorTypes.js +8 -0
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +6 -6
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +1 -1
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +4 -6
- package/dist/analyzer/typeUtils.js +56 -31
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +9 -4
- package/dist/analyzer/types.js +4 -8
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysis.d.ts +2 -1
- package/dist/backgroundAnalysis.js +2 -2
- package/dist/backgroundAnalysis.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +3 -2
- package/dist/backgroundAnalysisBase.js +3 -3
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.d.ts +7 -5
- package/dist/backgroundThreadBase.js +20 -6
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +0 -1
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/chokidarFileWatcherProvider.d.ts +1 -1
- package/dist/common/console.js.map +1 -1
- package/dist/common/extensibility.d.ts +4 -29
- package/dist/common/extensibility.js +5 -1
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/fileSystem.d.ts +2 -15
- package/dist/common/fileSystem.js +1 -31
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/fileWatcher.d.ts +15 -0
- package/dist/common/fileWatcher.js +34 -0
- package/dist/common/fileWatcher.js.map +1 -0
- package/dist/common/pathUtils.d.ts +1 -0
- package/dist/common/pathUtils.js +19 -5
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/realFileSystem.d.ts +2 -1
- package/dist/common/realFileSystem.js +13 -9
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/serviceProvider.d.ts +14 -0
- package/dist/common/serviceProvider.js +37 -0
- package/dist/common/serviceProvider.js.map +1 -0
- package/dist/common/serviceProviderExtensions.d.ts +16 -0
- package/dist/common/serviceProviderExtensions.js +27 -0
- package/dist/common/serviceProviderExtensions.js.map +1 -0
- package/dist/languageServerBase.d.ts +11 -7
- package/dist/languageServerBase.js +21 -13
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/hoverProvider.js +1 -6
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/navigationUtils.js +1 -1
- package/dist/languageService/navigationUtils.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +7 -1
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/localization/localize.d.ts +3 -0
- package/dist/localization/localize.js +1 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +1 -0
- package/dist/localization/package.nls.de.json +1 -0
- package/dist/localization/package.nls.en-us.json +3 -2
- package/dist/localization/package.nls.es.json +1 -0
- package/dist/localization/package.nls.fr.json +1 -0
- package/dist/localization/package.nls.it.json +1 -0
- package/dist/localization/package.nls.ja.json +1 -0
- package/dist/localization/package.nls.ko.json +1 -0
- package/dist/localization/package.nls.pl.json +1 -0
- package/dist/localization/package.nls.pt-br.json +1 -0
- package/dist/localization/package.nls.qps-ploc.json +1 -0
- package/dist/localization/package.nls.ru.json +1 -0
- package/dist/localization/package.nls.tr.json +1 -0
- package/dist/localization/package.nls.zh-cn.json +1 -0
- package/dist/localization/package.nls.zh-tw.json +1 -0
- package/dist/nodeMain.js +2 -1
- package/dist/nodeMain.js.map +1 -1
- package/dist/parser/parser.js +2 -2
- package/dist/parser/parser.js.map +1 -1
- package/dist/pyright.js +2 -0
- package/dist/pyright.js.map +1 -1
- package/dist/pyrightFileSystem.d.ts +3 -1
- package/dist/pyrightFileSystem.js.map +1 -1
- package/dist/readonlyAugmentedFileSystem.d.ts +3 -2
- package/dist/readonlyAugmentedFileSystem.js +2 -2
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/server.js +8 -1
- package/dist/server.js.map +1 -1
- package/dist/tests/docStringConversion.test.js +94 -0
- package/dist/tests/docStringConversion.test.js.map +1 -1
- package/dist/tests/fourslash/completions.importPrivateNoPytyped.fourslash.d.ts +0 -0
- package/dist/tests/fourslash/completions.importPrivateNoPytyped.fourslash.js +30 -0
- package/dist/tests/fourslash/completions.importPrivateNoPytyped.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.importPytyped.fourslash.d.ts +0 -0
- package/dist/tests/fourslash/completions.importPytyped.fourslash.js +29 -0
- package/dist/tests/fourslash/completions.importPytyped.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.importPytypedLocal.fourslash.d.ts +0 -0
- package/dist/tests/fourslash/completions.importPytypedLocal.fourslash.js +29 -0
- package/dist/tests/fourslash/completions.importPytypedLocal.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.async.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.async.fourslash.js +12 -0
- package/dist/tests/fourslash/hover.async.fourslash.js.map +1 -0
- package/dist/tests/harness/fourslash/runner.js +1 -1
- package/dist/tests/harness/fourslash/runner.js.map +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.js +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.d.ts +1 -1
- package/dist/tests/harness/fourslash/testState.js +7 -2
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +3 -2
- package/dist/tests/harness/vfs/filesystem.js +1 -1
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/service.test.js +65 -0
- package/dist/tests/service.test.js.map +1 -1
- package/dist/tests/testUtils.js +6 -1
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +2 -2
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +1 -1
- package/dist/tests/zipfs.test.js +8 -5
- package/dist/tests/zipfs.test.js.map +1 -1
- package/package.json +1 -1
@@ -157,7 +157,7 @@ const maxRecursiveTypeAliasRecursionCount = 10;
|
|
157
157
|
// This switch enables a special debug mode that attempts to catch
|
158
158
|
// bugs due to inconsistent evaluation flags used when reading types
|
159
159
|
// from the type cache.
|
160
|
-
const verifyTypeCacheEvaluatorFlags =
|
160
|
+
const verifyTypeCacheEvaluatorFlags = true;
|
161
161
|
// This debugging option prints each expression and its evaluated type.
|
162
162
|
const printExpressionTypes = false;
|
163
163
|
// The following number is chosen somewhat arbitrarily. We need to cut
|
@@ -683,6 +683,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
683
683
|
}
|
684
684
|
return typeResult;
|
685
685
|
}
|
686
|
+
function reportInvalidUseOfPep695TypeAlias(type, node) {
|
687
|
+
var _a;
|
688
|
+
// PEP 695 type aliases cannot be used as instantiable classes.
|
689
|
+
if (((_a = type.typeAliasInfo) === null || _a === void 0 ? void 0 : _a.name) && type.typeAliasInfo.isPep695Syntax) {
|
690
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasNotAllowed().format({ name: type.typeAliasInfo.name }), node);
|
691
|
+
return true;
|
692
|
+
}
|
693
|
+
return false;
|
694
|
+
}
|
686
695
|
function validateTypeIsInstantiable(typeResult, flags, node) {
|
687
696
|
var _a;
|
688
697
|
// If the type is incomplete, don't log any diagnostics yet.
|
@@ -772,6 +781,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
772
781
|
};
|
773
782
|
typeResult = {
|
774
783
|
type: iteratorTypeResult.type,
|
784
|
+
typeErrors: iterTypeResult.typeErrors,
|
775
785
|
unpackedType: iterType,
|
776
786
|
isIncomplete: iteratorTypeResult.isIncomplete,
|
777
787
|
};
|
@@ -1450,7 +1460,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1450
1460
|
return getDeclaredTypeForExpression(expression.valueExpression, usage);
|
1451
1461
|
}
|
1452
1462
|
case 35 /* MemberAccess */: {
|
1453
|
-
const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.leftExpression,
|
1463
|
+
const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.leftExpression, 16777218 /* MemberAccessBaseDefaults */).type);
|
1454
1464
|
let classMemberInfo;
|
1455
1465
|
if ((0, types_1.isClassInstance)(baseType)) {
|
1456
1466
|
classMemberInfo = (0, typeUtils_1.lookUpObjectMember)(baseType, expression.memberName.value, 16 /* DeclaredTypesOnly */);
|
@@ -1474,7 +1484,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1474
1484
|
break;
|
1475
1485
|
}
|
1476
1486
|
case 24 /* Index */: {
|
1477
|
-
const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.baseExpression, 2 /*
|
1487
|
+
const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.baseExpression, 2 /* IndexBaseDefaults */).type);
|
1478
1488
|
if (baseType && (0, types_1.isClassInstance)(baseType)) {
|
1479
1489
|
const setItemMember = (0, typeUtils_1.lookUpClassMember)(baseType, '__setitem__');
|
1480
1490
|
if (setItemMember) {
|
@@ -2035,7 +2045,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2035
2045
|
writeTypeCache(nameNode, { type: destType, isIncomplete: isTypeIncomplete }, 0 /* None */);
|
2036
2046
|
}
|
2037
2047
|
function assignTypeToMemberAccessNode(target, type, isTypeIncomplete, srcExpr, expectedTypeDiagAddendum) {
|
2038
|
-
const baseTypeResult = getTypeOfExpression(target.leftExpression,
|
2048
|
+
const baseTypeResult = getTypeOfExpression(target.leftExpression, 16777218 /* MemberAccessBaseDefaults */);
|
2039
2049
|
const baseType = makeTopLevelTypeVarsConcrete(baseTypeResult.type);
|
2040
2050
|
// Handle member accesses (e.g. self.x or cls.y).
|
2041
2051
|
if (target.leftExpression.nodeType === 38 /* Name */) {
|
@@ -2492,7 +2502,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2492
2502
|
// Is the source expression a TypeVar() call?
|
2493
2503
|
if ((0, types_1.isTypeVar)(type)) {
|
2494
2504
|
if (srcExpr && srcExpr.nodeType === 9 /* Call */) {
|
2495
|
-
const callType = getTypeOfExpression(srcExpr.leftExpression,
|
2505
|
+
const callType = getTypeOfExpression(srcExpr.leftExpression, 16777218 /* CallBaseDefaults */).type;
|
2496
2506
|
if ((0, types_1.isInstantiableClass)(callType) &&
|
2497
2507
|
(types_1.ClassType.isBuiltIn(callType, 'TypeVar') ||
|
2498
2508
|
types_1.ClassType.isBuiltIn(callType, 'TypeVarTuple') ||
|
@@ -2523,7 +2533,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2523
2533
|
break;
|
2524
2534
|
}
|
2525
2535
|
case 24 /* Index */: {
|
2526
|
-
const baseTypeResult = getTypeOfExpression(target.baseExpression, 2 /*
|
2536
|
+
const baseTypeResult = getTypeOfExpression(target.baseExpression, 2 /* IndexBaseDefaults */);
|
2527
2537
|
getTypeOfIndexWithBaseType(target, baseTypeResult, {
|
2528
2538
|
method: 'set',
|
2529
2539
|
setType: { type, isIncomplete: isTypeIncomplete },
|
@@ -2560,8 +2570,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2560
2570
|
}
|
2561
2571
|
}
|
2562
2572
|
}
|
2563
|
-
assignTypeToExpression(target.valueExpression, type,
|
2564
|
-
/* isIncomplete */ false, srcExpr, ignoreEmptyContainers, allowAssignmentToFinalVar, expectedTypeDiagAddendum);
|
2573
|
+
assignTypeToExpression(target.valueExpression, type, isTypeIncomplete, srcExpr, ignoreEmptyContainers, allowAssignmentToFinalVar, expectedTypeDiagAddendum);
|
2565
2574
|
break;
|
2566
2575
|
}
|
2567
2576
|
case 56 /* Unpack */: {
|
@@ -2651,14 +2660,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2651
2660
|
break;
|
2652
2661
|
}
|
2653
2662
|
case 35 /* MemberAccess */: {
|
2654
|
-
const baseTypeResult = getTypeOfExpression(node.leftExpression,
|
2663
|
+
const baseTypeResult = getTypeOfExpression(node.leftExpression, 16777218 /* MemberAccessBaseDefaults */);
|
2655
2664
|
const memberType = getTypeOfMemberAccessWithBaseType(node, baseTypeResult, { method: 'del' }, 0 /* None */);
|
2656
2665
|
writeTypeCache(node.memberName, { type: memberType.type }, 0 /* None */);
|
2657
2666
|
writeTypeCache(node, { type: memberType.type }, 0 /* None */);
|
2658
2667
|
break;
|
2659
2668
|
}
|
2660
2669
|
case 24 /* Index */: {
|
2661
|
-
const baseTypeResult = getTypeOfExpression(node.baseExpression, 2 /*
|
2670
|
+
const baseTypeResult = getTypeOfExpression(node.baseExpression, 2 /* IndexBaseDefaults */);
|
2662
2671
|
getTypeOfIndexWithBaseType(node, baseTypeResult, { method: 'del' }, 0 /* None */);
|
2663
2672
|
writeTypeCache(node, { type: types_1.UnboundType.create() }, 0 /* None */);
|
2664
2673
|
break;
|
@@ -2913,6 +2922,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2913
2922
|
}
|
2914
2923
|
}
|
2915
2924
|
}
|
2925
|
+
if ((flags & 16777216 /* DisallowPep695TypeAlias */) !== 0) {
|
2926
|
+
if (reportInvalidUseOfPep695TypeAlias(type, node)) {
|
2927
|
+
type = types_1.UnknownType.create();
|
2928
|
+
}
|
2929
|
+
}
|
2916
2930
|
if ((flags & 128 /* ExpectingInstantiableType */) !== 0) {
|
2917
2931
|
if ((flags & 1024 /* AllowGenericClassType */) === 0) {
|
2918
2932
|
if ((0, types_1.isInstantiableClass)(type) && types_1.ClassType.isBuiltIn(type, 'Generic')) {
|
@@ -2967,10 +2981,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2967
2981
|
if (decl.type === 2 /* Parameter */) {
|
2968
2982
|
return true;
|
2969
2983
|
}
|
2970
|
-
// Assume alias declarations are also always safe to narrow.
|
2971
|
-
if (decl.type === 8 /* Alias */) {
|
2972
|
-
return true;
|
2973
|
-
}
|
2974
2984
|
const declCodeFlowNode = AnalyzerNodeInfo.getFlowNode(decl.node);
|
2975
2985
|
if (!declCodeFlowNode) {
|
2976
2986
|
return false;
|
@@ -3146,7 +3156,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3146
3156
|
name: type.typeAliasInfo.name,
|
3147
3157
|
}), node);
|
3148
3158
|
}
|
3149
|
-
type = types_1.TypeBase.cloneForTypeAlias((0, typeUtils_1.applySolvedTypeVars)(type, typeVarContext, { unknownIfNotFound: true }), type.typeAliasInfo.name, type.typeAliasInfo.fullName, type.typeAliasInfo.typeVarScopeId, type.typeAliasInfo.typeParameters, defaultTypeArgs);
|
3159
|
+
type = types_1.TypeBase.cloneForTypeAlias((0, typeUtils_1.applySolvedTypeVars)(type, typeVarContext, { unknownIfNotFound: true }), type.typeAliasInfo.name, type.typeAliasInfo.fullName, type.typeAliasInfo.typeVarScopeId, type.typeAliasInfo.isPep695Syntax, type.typeAliasInfo.typeParameters, defaultTypeArgs);
|
3150
3160
|
}
|
3151
3161
|
return type;
|
3152
3162
|
}
|
@@ -3254,7 +3264,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3254
3264
|
return { type, isRescoped: false, foundInterveningClass: false };
|
3255
3265
|
}
|
3256
3266
|
function getTypeOfMemberAccess(node, flags) {
|
3257
|
-
const baseTypeFlags =
|
3267
|
+
const baseTypeFlags = 16777218 /* MemberAccessBaseDefaults */ |
|
3258
3268
|
(flags &
|
3259
3269
|
(256 /* ExpectingTypeAnnotation */ |
|
3260
3270
|
32768 /* VariableTypeAnnotation */ |
|
@@ -3704,7 +3714,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3704
3714
|
// to leave the Self type generic (not specialized). We'll also
|
3705
3715
|
// skip this for __new__ methods because they are not bound
|
3706
3716
|
// to the class but rather assume the type of the cls argument.
|
3707
|
-
const selfClass = bindToType || memberName === '__new__' ? undefined : classType;
|
3717
|
+
const selfClass = !!bindToType || memberName === '__new__' ? undefined : classType;
|
3708
3718
|
const typeResult = getTypeOfMemberInternal(memberInfo, selfClass);
|
3709
3719
|
if (typeResult) {
|
3710
3720
|
type = typeResult.type;
|
@@ -4236,7 +4246,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4236
4246
|
return undefined;
|
4237
4247
|
}
|
4238
4248
|
function getTypeOfIndex(node, flags = 0 /* None */) {
|
4239
|
-
const baseTypeResult = getTypeOfExpression(node.baseExpression, flags | 2 /*
|
4249
|
+
const baseTypeResult = getTypeOfExpression(node.baseExpression, flags | 2 /* IndexBaseDefaults */);
|
4240
4250
|
// If this is meant to be a type and the base expression is a string expression,
|
4241
4251
|
// emit an error because this will generate a runtime exception in Python versions
|
4242
4252
|
// less than 3.10.
|
@@ -4548,7 +4558,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4548
4558
|
}
|
4549
4559
|
aliasTypeArgs.push(typeVarType || types_1.UnknownType.create());
|
4550
4560
|
});
|
4551
|
-
const type = types_1.TypeBase.cloneForTypeAlias((0, typeUtils_1.applySolvedTypeVars)(baseType, typeVarContext), baseType.typeAliasInfo.name, baseType.typeAliasInfo.fullName, baseType.typeAliasInfo.typeVarScopeId, baseType.typeAliasInfo.typeParameters, aliasTypeArgs);
|
4561
|
+
const type = types_1.TypeBase.cloneForTypeAlias((0, typeUtils_1.applySolvedTypeVars)(baseType, typeVarContext), baseType.typeAliasInfo.name, baseType.typeAliasInfo.fullName, baseType.typeAliasInfo.typeVarScopeId, baseType.typeAliasInfo.isPep695Syntax, baseType.typeAliasInfo.typeParameters, aliasTypeArgs);
|
4552
4562
|
return { type, node };
|
4553
4563
|
}
|
4554
4564
|
function getTypeOfIndexWithBaseType(node, baseTypeResult, usage, flags) {
|
@@ -4559,7 +4569,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4559
4569
|
}
|
4560
4570
|
if ((0, types_1.isTypeVar)(baseTypeResult.type) && (0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
|
4561
4571
|
const typeArgTypes = getTypeArgs(node, flags).map((t) => (0, typeUtils_1.convertToInstance)(t.type));
|
4562
|
-
const type = types_1.TypeBase.cloneForTypeAlias(baseTypeResult.type, baseTypeResult.type.details.recursiveTypeAliasName, '', baseTypeResult.type.details.recursiveTypeAliasScopeId, baseTypeResult.type.details.recursiveTypeParameters, typeArgTypes);
|
4572
|
+
const type = types_1.TypeBase.cloneForTypeAlias(baseTypeResult.type, baseTypeResult.type.details.recursiveTypeAliasName, '', baseTypeResult.type.details.recursiveTypeAliasScopeId, baseTypeResult.type.details.recursiveTypeAliasIsPep695Syntax, baseTypeResult.type.details.recursiveTypeParameters, typeArgTypes);
|
4563
4573
|
return { type };
|
4564
4574
|
}
|
4565
4575
|
let isIncomplete = baseTypeResult.isIncomplete;
|
@@ -5343,7 +5353,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5343
5353
|
baseTypeResult = getTypeOfLambdaForCall(node, inferenceContext);
|
5344
5354
|
}
|
5345
5355
|
else {
|
5346
|
-
baseTypeResult = getTypeOfExpression(node.leftExpression,
|
5356
|
+
baseTypeResult = getTypeOfExpression(node.leftExpression, 16777218 /* CallBaseDefaults */ | (flags & 4 /* AllowForwardReferences */));
|
5347
5357
|
}
|
5348
5358
|
const argList = node.arguments.map((arg) => {
|
5349
5359
|
const functionArg = {
|
@@ -5478,7 +5488,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5478
5488
|
}
|
5479
5489
|
}
|
5480
5490
|
function getLambdaType() {
|
5481
|
-
return getTypeOfExpression(node.leftExpression,
|
5491
|
+
return getTypeOfExpression(node.leftExpression, 16777218 /* CallBaseDefaults */, (0, typeUtils_1.makeInferenceContext)(expectedType));
|
5482
5492
|
}
|
5483
5493
|
// If one or more of the arguments are incomplete, use speculative mode
|
5484
5494
|
// for the lambda evaluation because it may need to be reevaluated once
|
@@ -5488,7 +5498,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5488
5498
|
: getLambdaType();
|
5489
5499
|
// If bidirectional type inference failed, use normal type inference instead.
|
5490
5500
|
if (typeResult.typeErrors) {
|
5491
|
-
typeResult = getTypeOfExpression(node.leftExpression,
|
5501
|
+
typeResult = getTypeOfExpression(node.leftExpression, 16777218 /* CallBaseDefaults */);
|
5492
5502
|
}
|
5493
5503
|
return typeResult;
|
5494
5504
|
}
|
@@ -7487,13 +7497,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7487
7497
|
}
|
7488
7498
|
if ((0, types_1.isClassInstance)(effectiveExpectedType) && !(0, types_1.isTypeSame)(effectiveReturnType, effectiveExpectedType)) {
|
7489
7499
|
const tempTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(effectiveReturnType));
|
7490
|
-
(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, effectiveReturnType, effectiveExpectedType, tempTypeVarContext, liveTypeVarScopes, errorNode.start)
|
7491
|
-
|
7492
|
-
|
7493
|
-
|
7494
|
-
|
7495
|
-
|
7496
|
-
|
7500
|
+
if ((0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, effectiveReturnType, effectiveExpectedType, tempTypeVarContext, liveTypeVarScopes, errorNode.start)) {
|
7501
|
+
const genericReturnType = types_1.ClassType.cloneForSpecialization(effectiveReturnType,
|
7502
|
+
/* typeArguments */ undefined,
|
7503
|
+
/* isTypeArgumentExplicit */ false);
|
7504
|
+
effectiveExpectedType = (0, typeUtils_1.applySolvedTypeVars)(genericReturnType, tempTypeVarContext, {
|
7505
|
+
unknownIfNotFound: true,
|
7506
|
+
});
|
7507
|
+
}
|
7497
7508
|
}
|
7498
7509
|
}
|
7499
7510
|
else if ((0, types_1.isFunction)(effectiveReturnType)) {
|
@@ -7708,8 +7719,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7708
7719
|
eliminateUnsolvedInUnions = false;
|
7709
7720
|
}
|
7710
7721
|
// We'll leave TypeVars unsolved if the call is a recursive
|
7711
|
-
// call to a generic function
|
7712
|
-
|
7722
|
+
// call to a generic function or if this isn't a callable
|
7723
|
+
// return with type parameters that are rescoped from the original
|
7724
|
+
// function to the returned callable.
|
7725
|
+
const unknownIfNotFound = !ParseTreeUtils.getTypeVarScopesForNode(errorNode).some((typeVarScope) => typeVarContext.hasSolveForScope(typeVarScope)) && !type.details.rescopedTypeParameters;
|
7713
7726
|
let specializedReturnType = (0, typeUtils_1.applySolvedTypeVars)(returnType, typeVarContext, {
|
7714
7727
|
unknownIfNotFound,
|
7715
7728
|
unknownExemptTypeVars: getUnknownExemptTypeVarsForReturnType(type, returnType),
|
@@ -7775,7 +7788,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7775
7788
|
specializedReturnType = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForTypeGuard(boolClassType, typeGuardType, useStrictTypeGuardSemantics));
|
7776
7789
|
}
|
7777
7790
|
}
|
7778
|
-
specializedReturnType = adjustCallableReturnType(specializedReturnType);
|
7791
|
+
specializedReturnType = adjustCallableReturnType(specializedReturnType, signatureTracker.getTrackedSignatures());
|
7779
7792
|
if (specializedInitSelfType) {
|
7780
7793
|
specializedInitSelfType = (0, typeUtils_1.applySolvedTypeVars)(specializedInitSelfType, typeVarContext);
|
7781
7794
|
}
|
@@ -7817,19 +7830,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7817
7830
|
}
|
7818
7831
|
return [];
|
7819
7832
|
}
|
7820
|
-
|
7821
|
-
|
7822
|
-
|
7823
|
-
|
7824
|
-
|
7825
|
-
|
7833
|
+
// If the return type includes a generic Callable type, set the type var
|
7834
|
+
// scope to a wildcard to allow these type vars to be solved. This won't
|
7835
|
+
// work with overloads or unions of callables. It's intended for a
|
7836
|
+
// specific use case. We may need to make this more sophisticated in
|
7837
|
+
// the future.
|
7838
|
+
// The trackedSignatures parameter supplies a list of function signatures
|
7839
|
+
// that were used for the function and the arguments passed to it. This is
|
7840
|
+
// important because the callable return value may be called again with
|
7841
|
+
// one of these signatures, so we may need to "uniquify" the type parameters
|
7842
|
+
// to avoid conflicts.
|
7843
|
+
function adjustCallableReturnType(returnType, trackedSignatures) {
|
7826
7844
|
if ((0, types_1.isFunction)(returnType) && !returnType.details.name) {
|
7827
7845
|
const typeVarsInReturnType = (0, typeUtils_1.getTypeVarArgumentsRecursive)(returnType);
|
7828
7846
|
// If there are no unsolved type variables, we're done. If there are
|
7829
7847
|
// unsolved type parameters, treat them as though they are rescoped
|
7830
7848
|
// to the callable.
|
7831
7849
|
if (typeVarsInReturnType.length > 0) {
|
7832
|
-
return types_1.FunctionType.cloneWithNewTypeVarScopeId(returnType, types_1.WildcardTypeVarScopeId, typeVarsInReturnType);
|
7850
|
+
return types_1.FunctionType.cloneWithNewTypeVarScopeId(returnType, types_1.WildcardTypeVarScopeId, typeVarsInReturnType, trackedSignatures);
|
7833
7851
|
}
|
7834
7852
|
}
|
7835
7853
|
return returnType;
|
@@ -8067,7 +8085,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8067
8085
|
? 512 /* AllowMissingTypeArgs */ |
|
8068
8086
|
8 /* EvaluateStringLiteralAsType */ |
|
8069
8087
|
32 /* DisallowParamSpec */ |
|
8070
|
-
64 /* DisallowTypeVarTuple */
|
8088
|
+
64 /* DisallowTypeVarTuple */ |
|
8089
|
+
16777216 /* DisallowPep695TypeAlias */
|
8071
8090
|
: 2 /* DoNotSpecialize */;
|
8072
8091
|
const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType, !!(typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete), signatureTracker));
|
8073
8092
|
argType = exprTypeResult.type;
|
@@ -8638,6 +8657,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8638
8657
|
}
|
8639
8658
|
}
|
8640
8659
|
return getTypeOfTypeAliasCommon(nameNode, nameNode, valueExpr,
|
8660
|
+
/* isPep695Syntax */ false,
|
8641
8661
|
/* typeParamNodes */ undefined, () => typeParameters !== null && typeParameters !== void 0 ? typeParameters : []);
|
8642
8662
|
}
|
8643
8663
|
function getBooleanValue(node) {
|
@@ -8807,7 +8827,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8807
8827
|
if ((0, types_1.isClassInstance)(concreteSubtype)) {
|
8808
8828
|
magicMethodType = (_a = getTypeOfObjectMember(errorNode, concreteSubtype, magicMethodName,
|
8809
8829
|
/* usage */ undefined,
|
8810
|
-
/* diag */ undefined, 64 /* SkipAttributeAccessOverride */ | 1 /* AccessClassMembersOnly
|
8830
|
+
/* diag */ undefined, 64 /* SkipAttributeAccessOverride */ | 1 /* AccessClassMembersOnly */)) === null || _a === void 0 ? void 0 : _a.type;
|
8811
8831
|
}
|
8812
8832
|
else if ((0, types_1.isInstantiableClass)(concreteSubtype)) {
|
8813
8833
|
magicMethodType = (_b = getTypeOfClassMember(errorNode, concreteSubtype, magicMethodName,
|
@@ -10485,7 +10505,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10485
10505
|
}
|
10486
10506
|
return createSpecialType(classType, typeArgs, /* paramLimit */ undefined, /* allowParamSpec */ true);
|
10487
10507
|
}
|
10488
|
-
function transformTypeForTypeAlias(type, name, errorNode, typeParameters, typeParamNodes) {
|
10508
|
+
function transformTypeForTypeAlias(type, name, errorNode, isPep695Syntax, typeParameters, typeParamNodes) {
|
10489
10509
|
if (!types_1.TypeBase.isInstantiable(type)) {
|
10490
10510
|
return type;
|
10491
10511
|
}
|
@@ -10535,7 +10555,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10535
10555
|
names: boundTypeVars.map((t) => `${t.details.name}`).join(', '),
|
10536
10556
|
}), errorNode);
|
10537
10557
|
}
|
10538
|
-
return types_1.TypeBase.cloneForTypeAlias(type, name.value, ParseTreeUtils.getClassFullName(name, fileInfo.moduleName, name.value), typeAliasScopeId, typeParameters.length > 0 ? typeParameters : undefined);
|
10558
|
+
return types_1.TypeBase.cloneForTypeAlias(type, name.value, ParseTreeUtils.getClassFullName(name, fileInfo.moduleName, name.value), typeAliasScopeId, isPep695Syntax, typeParameters.length > 0 ? typeParameters : undefined);
|
10539
10559
|
}
|
10540
10560
|
function createSpecialBuiltInClass(node, assignedName, aliasMapEntry) {
|
10541
10561
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
@@ -10756,6 +10776,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10756
10776
|
typeAliasTypeVar.details.recursiveTypeAliasName = typeAliasNameNode.value;
|
10757
10777
|
const scopeId = ParseTreeUtils.getScopeIdForNode(typeAliasNameNode);
|
10758
10778
|
typeAliasTypeVar.details.recursiveTypeAliasScopeId = scopeId;
|
10779
|
+
typeAliasTypeVar.details.recursiveTypeAliasIsPep695Syntax = false;
|
10759
10780
|
typeAliasTypeVar.scopeId = scopeId;
|
10760
10781
|
// Write the type back to the type cache. It will be replaced below.
|
10761
10782
|
writeTypeCache(node, { type: typeAliasTypeVar }, /* flags */ undefined);
|
@@ -10800,7 +10821,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10800
10821
|
if (!isSpeculativeTypeAlias ||
|
10801
10822
|
(types_1.TypeBase.isInstantiable(rightHandType) && !(0, types_1.isUnknown)(rightHandType))) {
|
10802
10823
|
// If this is a type alias, record its name based on the assignment target.
|
10803
|
-
rightHandType = transformTypeForTypeAlias(rightHandType, typeAliasNameNode, node.rightExpression
|
10824
|
+
rightHandType = transformTypeForTypeAlias(rightHandType, typeAliasNameNode, node.rightExpression,
|
10825
|
+
/* isPep695Syntax */ false);
|
10804
10826
|
if ((0, typeUtils_1.isTypeAliasRecursive)(typeAliasTypeVar, rightHandType)) {
|
10805
10827
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasIsRecursiveDirect().format({
|
10806
10828
|
name: typeAliasNameNode.value,
|
@@ -10841,7 +10863,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10841
10863
|
callLeftNode.leftExpression.nodeType === 38 /* Name */)) {
|
10842
10864
|
// See if this is a call to TypedDict. We want to support
|
10843
10865
|
// recursive type references in a TypedDict call.
|
10844
|
-
const callType = getTypeOfExpression(callLeftNode,
|
10866
|
+
const callType = getTypeOfExpression(callLeftNode, 16777218 /* CallBaseDefaults */).type;
|
10845
10867
|
if ((0, types_1.isInstantiableClass)(callType) && types_1.ClassType.isBuiltIn(callType, 'TypedDict')) {
|
10846
10868
|
return true;
|
10847
10869
|
}
|
@@ -10854,7 +10876,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10854
10876
|
// variables since they use normal variable assignment syntax.
|
10855
10877
|
function getTypeOfTypeAlias(node) {
|
10856
10878
|
var _a;
|
10857
|
-
return getTypeOfTypeAliasCommon(node, node.name, node.expression,
|
10879
|
+
return getTypeOfTypeAliasCommon(node, node.name, node.expression,
|
10880
|
+
/* isPep695Syntax */ true, (_a = node.typeParameters) === null || _a === void 0 ? void 0 : _a.parameters, () => {
|
10858
10881
|
let typeParameters = [];
|
10859
10882
|
if (node.typeParameters) {
|
10860
10883
|
typeParameters = evaluateTypeParameterList(node.typeParameters);
|
@@ -10864,7 +10887,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10864
10887
|
}
|
10865
10888
|
// This function is common to the handling of "type" statements and explicit
|
10866
10889
|
// calls to the TypeAliasType constructor.
|
10867
|
-
function getTypeOfTypeAliasCommon(declNode, nameNode, valueNode, typeParamNodes, getTypeParamCallback) {
|
10890
|
+
function getTypeOfTypeAliasCommon(declNode, nameNode, valueNode, isPep695Syntax, typeParamNodes, getTypeParamCallback) {
|
10868
10891
|
const cachedType = readTypeCache(nameNode, 0 /* None */);
|
10869
10892
|
if (cachedType) {
|
10870
10893
|
return cachedType;
|
@@ -10876,6 +10899,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10876
10899
|
typeAliasTypeVar.details.recursiveTypeAliasName = nameNode.value;
|
10877
10900
|
const scopeId = ParseTreeUtils.getScopeIdForNode(nameNode);
|
10878
10901
|
typeAliasTypeVar.details.recursiveTypeAliasScopeId = scopeId;
|
10902
|
+
typeAliasTypeVar.details.recursiveTypeAliasIsPep695Syntax = isPep695Syntax;
|
10879
10903
|
typeAliasTypeVar.scopeId = scopeId;
|
10880
10904
|
// Write the type to the type cache. It will be replaced below.
|
10881
10905
|
writeTypeCache(nameNode, { type: typeAliasTypeVar }, /* flags */ undefined);
|
@@ -10897,7 +10921,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10897
10921
|
if (aliasTypeResult.isIncomplete) {
|
10898
10922
|
isIncomplete = true;
|
10899
10923
|
}
|
10900
|
-
aliasType = transformTypeForTypeAlias(aliasType, nameNode, valueNode, typeParameters, typeParamNodes);
|
10924
|
+
aliasType = transformTypeForTypeAlias(aliasType, nameNode, valueNode, isPep695Syntax, typeParameters, typeParamNodes);
|
10901
10925
|
if ((0, typeUtils_1.isTypeAliasRecursive)(typeAliasTypeVar, aliasType)) {
|
10902
10926
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(valueNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasIsRecursiveDirect().format({
|
10903
10927
|
name: nameNode.value,
|
@@ -10993,7 +11017,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10993
11017
|
262144 /* DisallowNakedGeneric */ |
|
10994
11018
|
2048 /* DisallowTypeVarsWithScopeId */ |
|
10995
11019
|
8192 /* AssociateTypeVarsWithCurrentScope */ |
|
10996
|
-
16384 /* EnforceTypeVarVarianceConsistency
|
11020
|
+
16384 /* EnforceTypeVarVarianceConsistency */ |
|
11021
|
+
16777216 /* DisallowPep695TypeAlias */;
|
10997
11022
|
if (fileInfo.isStubFile) {
|
10998
11023
|
exprFlags |= 4 /* AllowForwardReferences */;
|
10999
11024
|
}
|
@@ -12147,7 +12172,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12147
12172
|
(0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, typeVarsInReturnType);
|
12148
12173
|
// Note that the type parameters have been rescoped so they are not
|
12149
12174
|
// considered valid for the body of this function.
|
12150
|
-
|
12175
|
+
if (rescopedTypeVars.length > 0) {
|
12176
|
+
functionType.details.rescopedTypeParameters = rescopedTypeVars;
|
12177
|
+
}
|
12151
12178
|
}
|
12152
12179
|
function adjustParameterAnnotatedType(param, type) {
|
12153
12180
|
var _a;
|
@@ -12292,16 +12319,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12292
12319
|
}
|
12293
12320
|
}
|
12294
12321
|
function createAsyncFunction(node, functionType) {
|
12322
|
+
(0, debug_1.assert)(types_1.FunctionType.isAsync(functionType));
|
12295
12323
|
// Clone the original function and replace its return type with an
|
12296
|
-
// Awaitable[<returnType>].
|
12297
|
-
const awaitableFunctionType = types_1.FunctionType.
|
12324
|
+
// Awaitable[<returnType>]. Mark the new function as no longer async.
|
12325
|
+
const awaitableFunctionType = types_1.FunctionType.cloneWithNewFlags(functionType, functionType.details.flags & ~512 /* Async */);
|
12298
12326
|
if (functionType.details.declaredReturnType) {
|
12299
12327
|
awaitableFunctionType.details.declaredReturnType = createAwaitableReturnType(node, functionType.details.declaredReturnType, types_1.FunctionType.isGenerator(functionType));
|
12300
12328
|
}
|
12301
|
-
|
12302
|
-
|
12303
|
-
|
12304
|
-
awaitableFunctionType.details.flags |= 1024 /* WrapReturnTypeInAwait */;
|
12329
|
+
else {
|
12330
|
+
awaitableFunctionType.inferredReturnType = createAwaitableReturnType(node, getFunctionInferredReturnType(functionType), types_1.FunctionType.isGenerator(functionType));
|
12331
|
+
}
|
12305
12332
|
return awaitableFunctionType;
|
12306
12333
|
}
|
12307
12334
|
function createAwaitableReturnType(node, returnType, isGenerator) {
|
@@ -13022,14 +13049,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13022
13049
|
nodeToEvaluate = parent;
|
13023
13050
|
continue;
|
13024
13051
|
}
|
13025
|
-
flags =
|
13052
|
+
flags = 16777218 /* CallBaseDefaults */;
|
13026
13053
|
break;
|
13027
13054
|
}
|
13028
13055
|
}
|
13029
13056
|
else if (parent.nodeType === 24 /* Index */) {
|
13030
13057
|
// The base expression of an index expression is not contextual.
|
13031
13058
|
if (nodeToEvaluate === parent.baseExpression) {
|
13032
|
-
flags = 2 /*
|
13059
|
+
flags = 2 /* IndexBaseDefaults */;
|
13033
13060
|
break;
|
13034
13061
|
}
|
13035
13062
|
}
|
@@ -14474,7 +14501,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14474
14501
|
}
|
14475
14502
|
// Special-case calls to certain built-in type functions.
|
14476
14503
|
if (((_a = resolvedDecl.inferredTypeSource) === null || _a === void 0 ? void 0 : _a.nodeType) === 9 /* Call */) {
|
14477
|
-
const baseTypeResult = getTypeOfExpression(resolvedDecl.inferredTypeSource.leftExpression,
|
14504
|
+
const baseTypeResult = getTypeOfExpression(resolvedDecl.inferredTypeSource.leftExpression, 16777218 /* CallBaseDefaults */);
|
14478
14505
|
const callType = baseTypeResult.type;
|
14479
14506
|
const exemptBuiltins = [
|
14480
14507
|
'TypeVar',
|
@@ -14530,7 +14557,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14530
14557
|
if (types_1.TypeBase.isInstantiable(inferredType) &&
|
14531
14558
|
!(0, types_1.isUnknown)(inferredType) &&
|
14532
14559
|
!(0, typeUtils_1.isEllipsisType)(inferredType)) {
|
14533
|
-
inferredType = transformTypeForTypeAlias(inferredType, resolvedDecl.typeAliasName, resolvedDecl.node
|
14560
|
+
inferredType = transformTypeForTypeAlias(inferredType, resolvedDecl.typeAliasName, resolvedDecl.node,
|
14561
|
+
/* isPep695Syntax */ false);
|
14534
14562
|
isUnambiguousType = true;
|
14535
14563
|
}
|
14536
14564
|
}
|
@@ -14957,7 +14985,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14957
14985
|
function getFunctionEffectiveReturnType(type, args, inferTypeIfNeeded = true) {
|
14958
14986
|
const specializedReturnType = types_1.FunctionType.getSpecializedReturnType(type);
|
14959
14987
|
if (specializedReturnType) {
|
14960
|
-
return adjustCallableReturnType(specializedReturnType);
|
14988
|
+
return adjustCallableReturnType(specializedReturnType, /* trackedSignatures */ undefined);
|
14961
14989
|
}
|
14962
14990
|
if (inferTypeIfNeeded) {
|
14963
14991
|
return getFunctionInferredReturnType(type, args);
|
@@ -15012,10 +15040,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15012
15040
|
if (returnTypeResult === null || returnTypeResult === void 0 ? void 0 : returnTypeResult.isIncomplete) {
|
15013
15041
|
isIncomplete = true;
|
15014
15042
|
}
|
15015
|
-
// Do we need to wrap this in an awaitable?
|
15016
|
-
if (returnType && types_1.FunctionType.isWrapReturnTypeInAwait(type)) {
|
15017
|
-
returnType = createAwaitableReturnType(functionNode, returnType, !!((_a = type.details.declaration) === null || _a === void 0 ? void 0 : _a.isGenerator));
|
15018
|
-
}
|
15019
15043
|
}
|
15020
15044
|
}
|
15021
15045
|
}
|
@@ -15036,17 +15060,30 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15036
15060
|
types_1.FunctionType.hasUnannotatedParams(type) &&
|
15037
15061
|
!types_1.FunctionType.isStubDefinition(type) &&
|
15038
15062
|
!types_1.FunctionType.isPyTypedDefinition(type) &&
|
15039
|
-
!types_1.FunctionType.isWrapReturnTypeInAwait(type) &&
|
15040
15063
|
args) {
|
15041
|
-
|
15042
|
-
|
15043
|
-
|
15064
|
+
let hasDecorators = false;
|
15065
|
+
let isAsync = false;
|
15066
|
+
const declNode = (_a = type.details.declaration) === null || _a === void 0 ? void 0 : _a.node;
|
15067
|
+
if (declNode) {
|
15068
|
+
if (declNode.decorators.length > 0) {
|
15069
|
+
hasDecorators = true;
|
15070
|
+
}
|
15071
|
+
if (declNode.isAsync) {
|
15072
|
+
isAsync = true;
|
15073
|
+
}
|
15074
|
+
}
|
15075
|
+
// We can't use this technique if decorators or async are used because they
|
15076
|
+
// would need to be applied to the inferred return type.
|
15077
|
+
if (!hasDecorators && !isAsync) {
|
15078
|
+
const contextualReturnType = getFunctionInferredReturnTypeUsingArguments(type, args);
|
15079
|
+
if (contextualReturnType) {
|
15080
|
+
returnType = contextualReturnType;
|
15081
|
+
}
|
15044
15082
|
}
|
15045
15083
|
}
|
15046
15084
|
return returnType;
|
15047
15085
|
}
|
15048
15086
|
function getFunctionInferredReturnTypeUsingArguments(type, args) {
|
15049
|
-
var _a;
|
15050
15087
|
let contextualReturnType;
|
15051
15088
|
if (!type.details.declaration) {
|
15052
15089
|
return undefined;
|
@@ -15158,10 +15195,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15158
15195
|
});
|
15159
15196
|
if (contextualReturnType) {
|
15160
15197
|
contextualReturnType = (0, types_1.removeUnbound)(contextualReturnType);
|
15161
|
-
// Do we need to wrap this in an awaitable?
|
15162
|
-
if (types_1.FunctionType.isWrapReturnTypeInAwait(type) && !(0, types_1.isNever)(contextualReturnType)) {
|
15163
|
-
contextualReturnType = createAwaitableReturnType(functionNode, contextualReturnType, !!((_a = type.details.declaration) === null || _a === void 0 ? void 0 : _a.isGenerator));
|
15164
|
-
}
|
15165
15198
|
if (!isResultFromCache) {
|
15166
15199
|
// Cache the resulting type.
|
15167
15200
|
if (!functionType.functionType.callSiteReturnTypeCache) {
|
@@ -17080,6 +17113,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17080
17113
|
!(0, types_1.isTypeSame)(srcParamSpec, destParamSpec, { ignoreTypeFlags: true })) {
|
17081
17114
|
const remainingFunction = types_1.FunctionType.createInstance('', '', '', effectiveSrcType.details.flags | 64 /* SynthesizedMethod */, effectiveSrcType.details.docString);
|
17082
17115
|
remainingFunction.details.typeVarScopeId = effectiveSrcType.details.typeVarScopeId;
|
17116
|
+
remainingFunction.details.constructorTypeVarScopeId =
|
17117
|
+
effectiveSrcType.details.constructorTypeVarScopeId;
|
17083
17118
|
remainingParams.forEach((param) => {
|
17084
17119
|
types_1.FunctionType.addParameter(remainingFunction, param);
|
17085
17120
|
});
|
@@ -17178,7 +17213,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17178
17213
|
const typeParam = assignedType.details.typeParameters[index];
|
17179
17214
|
const expectedTypeArgType = typeVarContext.getPrimarySignature().getTypeVarType(typeParam);
|
17180
17215
|
if (expectedTypeArgType) {
|
17181
|
-
if ((0,
|
17216
|
+
if ((0, types_1.isAnyOrUnknown)(expectedTypeArgType) || (0, types_1.isAnyOrUnknown)(typeArg)) {
|
17182
17217
|
replacedTypeArg = true;
|
17183
17218
|
return expectedTypeArgType;
|
17184
17219
|
}
|
@@ -17190,6 +17225,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17190
17225
|
return recursiveReplacement;
|
17191
17226
|
}
|
17192
17227
|
}
|
17228
|
+
else if ((0, typeUtils_1.containsAnyRecursive)(expectedTypeArgType)) {
|
17229
|
+
// If the expected type arg contains an Any, we can replace it with
|
17230
|
+
// a version that doesn't contain Any if the replacement doesn't violate
|
17231
|
+
// the variance of the type parameter.
|
17232
|
+
const variance = types_1.TypeVarType.getVariance(typeParam);
|
17233
|
+
const isSubtype = assignType(expectedTypeArgType, typeArg);
|
17234
|
+
const isSupertype = assignType(typeArg, expectedTypeArgType);
|
17235
|
+
if ((variance === 4 /* Contravariant */ || isSubtype) &&
|
17236
|
+
(variance === 3 /* Covariant */ || isSupertype)) {
|
17237
|
+
replacedTypeArg = true;
|
17238
|
+
return expectedTypeArgType;
|
17239
|
+
}
|
17240
|
+
}
|
17193
17241
|
}
|
17194
17242
|
return typeArg;
|
17195
17243
|
});
|
@@ -17312,7 +17360,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17312
17360
|
/* exemptSelfClsParam */ false);
|
17313
17361
|
});
|
17314
17362
|
if (matchIndex < 0) {
|
17315
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideOverloadNoMatch().format({ index: overrideOverloadIndex }));
|
17363
|
+
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideOverloadNoMatch().format({ index: overrideOverloadIndex + 1 }));
|
17316
17364
|
return false;
|
17317
17365
|
}
|
17318
17366
|
if (matchIndex < previousMatchIndex) {
|
@@ -17471,7 +17519,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17471
17519
|
}
|
17472
17520
|
else if (i < overrideParamDetails.positionOnlyParamCount &&
|
17473
17521
|
i >= baseParamDetails.positionOnlyParamCount) {
|
17474
|
-
if (!baseParam.isNameSynthesized
|
17522
|
+
if (!baseParam.isNameSynthesized &&
|
17523
|
+
baseParamDetails.params[i].source !== parameterUtils_1.ParameterSource.PositionOnly) {
|
17475
17524
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNamePositionOnly().format({
|
17476
17525
|
index: i + 1,
|
17477
17526
|
baseName: baseParam.name || '*',
|