@zzzen/pyright-internal 1.2.0-dev.20230806 → 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/checker.js +2 -2
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +5 -5
- 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/packageTypeVerifier.js +4 -1
- package/dist/analyzer/packageTypeVerifier.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 +37 -2
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +87 -35
- 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.js +27 -27
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +3 -1
- package/dist/analyzer/types.js +2 -1
- 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 -3
- package/dist/backgroundAnalysisBase.js +3 -3
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.d.ts +7 -6
- package/dist/backgroundThreadBase.js +20 -6
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/common/console.js.map +1 -1
- package/dist/common/extensibility.d.ts +2 -18
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/fileSystem.d.ts +1 -1
- 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 +1 -1
- package/dist/common/realFileSystem.js +12 -8
- 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 +4 -3
- package/dist/languageServerBase.js +4 -4
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/navigationUtils.js +1 -1
- package/dist/languageService/navigationUtils.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 -1
- package/dist/localization/package.nls.de.json +1 -1
- package/dist/localization/package.nls.en-us.json +1 -0
- package/dist/localization/package.nls.es.json +1 -1
- package/dist/localization/package.nls.fr.json +1 -1
- package/dist/localization/package.nls.it.json +1 -1
- package/dist/localization/package.nls.ja.json +1 -1
- package/dist/localization/package.nls.ko.json +1 -1
- package/dist/localization/package.nls.pl.json +1 -1
- package/dist/localization/package.nls.pt-br.json +1 -1
- package/dist/localization/package.nls.ru.json +1 -1
- package/dist/localization/package.nls.tr.json +1 -1
- package/dist/localization/package.nls.zh-cn.json +1 -1
- package/dist/localization/package.nls.zh-tw.json +1 -1
- 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/pyrightFileSystem.d.ts +3 -1
- package/dist/pyrightFileSystem.js.map +1 -1
- package/dist/readonlyAugmentedFileSystem.d.ts +1 -1
- package/dist/readonlyAugmentedFileSystem.js +2 -2
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/server.js +7 -1
- package/dist/server.js.map +1 -1
- 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 +2 -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 +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.
|
@@ -1451,7 +1460,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1451
1460
|
return getDeclaredTypeForExpression(expression.valueExpression, usage);
|
1452
1461
|
}
|
1453
1462
|
case 35 /* MemberAccess */: {
|
1454
|
-
const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.leftExpression,
|
1463
|
+
const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.leftExpression, 16777218 /* MemberAccessBaseDefaults */).type);
|
1455
1464
|
let classMemberInfo;
|
1456
1465
|
if ((0, types_1.isClassInstance)(baseType)) {
|
1457
1466
|
classMemberInfo = (0, typeUtils_1.lookUpObjectMember)(baseType, expression.memberName.value, 16 /* DeclaredTypesOnly */);
|
@@ -1475,7 +1484,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1475
1484
|
break;
|
1476
1485
|
}
|
1477
1486
|
case 24 /* Index */: {
|
1478
|
-
const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.baseExpression, 2 /*
|
1487
|
+
const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.baseExpression, 2 /* IndexBaseDefaults */).type);
|
1479
1488
|
if (baseType && (0, types_1.isClassInstance)(baseType)) {
|
1480
1489
|
const setItemMember = (0, typeUtils_1.lookUpClassMember)(baseType, '__setitem__');
|
1481
1490
|
if (setItemMember) {
|
@@ -2036,7 +2045,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2036
2045
|
writeTypeCache(nameNode, { type: destType, isIncomplete: isTypeIncomplete }, 0 /* None */);
|
2037
2046
|
}
|
2038
2047
|
function assignTypeToMemberAccessNode(target, type, isTypeIncomplete, srcExpr, expectedTypeDiagAddendum) {
|
2039
|
-
const baseTypeResult = getTypeOfExpression(target.leftExpression,
|
2048
|
+
const baseTypeResult = getTypeOfExpression(target.leftExpression, 16777218 /* MemberAccessBaseDefaults */);
|
2040
2049
|
const baseType = makeTopLevelTypeVarsConcrete(baseTypeResult.type);
|
2041
2050
|
// Handle member accesses (e.g. self.x or cls.y).
|
2042
2051
|
if (target.leftExpression.nodeType === 38 /* Name */) {
|
@@ -2493,7 +2502,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2493
2502
|
// Is the source expression a TypeVar() call?
|
2494
2503
|
if ((0, types_1.isTypeVar)(type)) {
|
2495
2504
|
if (srcExpr && srcExpr.nodeType === 9 /* Call */) {
|
2496
|
-
const callType = getTypeOfExpression(srcExpr.leftExpression,
|
2505
|
+
const callType = getTypeOfExpression(srcExpr.leftExpression, 16777218 /* CallBaseDefaults */).type;
|
2497
2506
|
if ((0, types_1.isInstantiableClass)(callType) &&
|
2498
2507
|
(types_1.ClassType.isBuiltIn(callType, 'TypeVar') ||
|
2499
2508
|
types_1.ClassType.isBuiltIn(callType, 'TypeVarTuple') ||
|
@@ -2524,7 +2533,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2524
2533
|
break;
|
2525
2534
|
}
|
2526
2535
|
case 24 /* Index */: {
|
2527
|
-
const baseTypeResult = getTypeOfExpression(target.baseExpression, 2 /*
|
2536
|
+
const baseTypeResult = getTypeOfExpression(target.baseExpression, 2 /* IndexBaseDefaults */);
|
2528
2537
|
getTypeOfIndexWithBaseType(target, baseTypeResult, {
|
2529
2538
|
method: 'set',
|
2530
2539
|
setType: { type, isIncomplete: isTypeIncomplete },
|
@@ -2561,8 +2570,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2561
2570
|
}
|
2562
2571
|
}
|
2563
2572
|
}
|
2564
|
-
assignTypeToExpression(target.valueExpression, type,
|
2565
|
-
/* isIncomplete */ false, srcExpr, ignoreEmptyContainers, allowAssignmentToFinalVar, expectedTypeDiagAddendum);
|
2573
|
+
assignTypeToExpression(target.valueExpression, type, isTypeIncomplete, srcExpr, ignoreEmptyContainers, allowAssignmentToFinalVar, expectedTypeDiagAddendum);
|
2566
2574
|
break;
|
2567
2575
|
}
|
2568
2576
|
case 56 /* Unpack */: {
|
@@ -2652,14 +2660,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2652
2660
|
break;
|
2653
2661
|
}
|
2654
2662
|
case 35 /* MemberAccess */: {
|
2655
|
-
const baseTypeResult = getTypeOfExpression(node.leftExpression,
|
2663
|
+
const baseTypeResult = getTypeOfExpression(node.leftExpression, 16777218 /* MemberAccessBaseDefaults */);
|
2656
2664
|
const memberType = getTypeOfMemberAccessWithBaseType(node, baseTypeResult, { method: 'del' }, 0 /* None */);
|
2657
2665
|
writeTypeCache(node.memberName, { type: memberType.type }, 0 /* None */);
|
2658
2666
|
writeTypeCache(node, { type: memberType.type }, 0 /* None */);
|
2659
2667
|
break;
|
2660
2668
|
}
|
2661
2669
|
case 24 /* Index */: {
|
2662
|
-
const baseTypeResult = getTypeOfExpression(node.baseExpression, 2 /*
|
2670
|
+
const baseTypeResult = getTypeOfExpression(node.baseExpression, 2 /* IndexBaseDefaults */);
|
2663
2671
|
getTypeOfIndexWithBaseType(node, baseTypeResult, { method: 'del' }, 0 /* None */);
|
2664
2672
|
writeTypeCache(node, { type: types_1.UnboundType.create() }, 0 /* None */);
|
2665
2673
|
break;
|
@@ -2914,6 +2922,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2914
2922
|
}
|
2915
2923
|
}
|
2916
2924
|
}
|
2925
|
+
if ((flags & 16777216 /* DisallowPep695TypeAlias */) !== 0) {
|
2926
|
+
if (reportInvalidUseOfPep695TypeAlias(type, node)) {
|
2927
|
+
type = types_1.UnknownType.create();
|
2928
|
+
}
|
2929
|
+
}
|
2917
2930
|
if ((flags & 128 /* ExpectingInstantiableType */) !== 0) {
|
2918
2931
|
if ((flags & 1024 /* AllowGenericClassType */) === 0) {
|
2919
2932
|
if ((0, types_1.isInstantiableClass)(type) && types_1.ClassType.isBuiltIn(type, 'Generic')) {
|
@@ -3143,7 +3156,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3143
3156
|
name: type.typeAliasInfo.name,
|
3144
3157
|
}), node);
|
3145
3158
|
}
|
3146
|
-
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);
|
3147
3160
|
}
|
3148
3161
|
return type;
|
3149
3162
|
}
|
@@ -3251,7 +3264,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3251
3264
|
return { type, isRescoped: false, foundInterveningClass: false };
|
3252
3265
|
}
|
3253
3266
|
function getTypeOfMemberAccess(node, flags) {
|
3254
|
-
const baseTypeFlags =
|
3267
|
+
const baseTypeFlags = 16777218 /* MemberAccessBaseDefaults */ |
|
3255
3268
|
(flags &
|
3256
3269
|
(256 /* ExpectingTypeAnnotation */ |
|
3257
3270
|
32768 /* VariableTypeAnnotation */ |
|
@@ -4233,7 +4246,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4233
4246
|
return undefined;
|
4234
4247
|
}
|
4235
4248
|
function getTypeOfIndex(node, flags = 0 /* None */) {
|
4236
|
-
const baseTypeResult = getTypeOfExpression(node.baseExpression, flags | 2 /*
|
4249
|
+
const baseTypeResult = getTypeOfExpression(node.baseExpression, flags | 2 /* IndexBaseDefaults */);
|
4237
4250
|
// If this is meant to be a type and the base expression is a string expression,
|
4238
4251
|
// emit an error because this will generate a runtime exception in Python versions
|
4239
4252
|
// less than 3.10.
|
@@ -4545,7 +4558,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4545
4558
|
}
|
4546
4559
|
aliasTypeArgs.push(typeVarType || types_1.UnknownType.create());
|
4547
4560
|
});
|
4548
|
-
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);
|
4549
4562
|
return { type, node };
|
4550
4563
|
}
|
4551
4564
|
function getTypeOfIndexWithBaseType(node, baseTypeResult, usage, flags) {
|
@@ -4556,7 +4569,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4556
4569
|
}
|
4557
4570
|
if ((0, types_1.isTypeVar)(baseTypeResult.type) && (0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
|
4558
4571
|
const typeArgTypes = getTypeArgs(node, flags).map((t) => (0, typeUtils_1.convertToInstance)(t.type));
|
4559
|
-
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);
|
4560
4573
|
return { type };
|
4561
4574
|
}
|
4562
4575
|
let isIncomplete = baseTypeResult.isIncomplete;
|
@@ -5340,7 +5353,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5340
5353
|
baseTypeResult = getTypeOfLambdaForCall(node, inferenceContext);
|
5341
5354
|
}
|
5342
5355
|
else {
|
5343
|
-
baseTypeResult = getTypeOfExpression(node.leftExpression,
|
5356
|
+
baseTypeResult = getTypeOfExpression(node.leftExpression, 16777218 /* CallBaseDefaults */ | (flags & 4 /* AllowForwardReferences */));
|
5344
5357
|
}
|
5345
5358
|
const argList = node.arguments.map((arg) => {
|
5346
5359
|
const functionArg = {
|
@@ -5475,7 +5488,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5475
5488
|
}
|
5476
5489
|
}
|
5477
5490
|
function getLambdaType() {
|
5478
|
-
return getTypeOfExpression(node.leftExpression,
|
5491
|
+
return getTypeOfExpression(node.leftExpression, 16777218 /* CallBaseDefaults */, (0, typeUtils_1.makeInferenceContext)(expectedType));
|
5479
5492
|
}
|
5480
5493
|
// If one or more of the arguments are incomplete, use speculative mode
|
5481
5494
|
// for the lambda evaluation because it may need to be reevaluated once
|
@@ -5485,7 +5498,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5485
5498
|
: getLambdaType();
|
5486
5499
|
// If bidirectional type inference failed, use normal type inference instead.
|
5487
5500
|
if (typeResult.typeErrors) {
|
5488
|
-
typeResult = getTypeOfExpression(node.leftExpression,
|
5501
|
+
typeResult = getTypeOfExpression(node.leftExpression, 16777218 /* CallBaseDefaults */);
|
5489
5502
|
}
|
5490
5503
|
return typeResult;
|
5491
5504
|
}
|
@@ -8072,7 +8085,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8072
8085
|
? 512 /* AllowMissingTypeArgs */ |
|
8073
8086
|
8 /* EvaluateStringLiteralAsType */ |
|
8074
8087
|
32 /* DisallowParamSpec */ |
|
8075
|
-
64 /* DisallowTypeVarTuple */
|
8088
|
+
64 /* DisallowTypeVarTuple */ |
|
8089
|
+
16777216 /* DisallowPep695TypeAlias */
|
8076
8090
|
: 2 /* DoNotSpecialize */;
|
8077
8091
|
const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType, !!(typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete), signatureTracker));
|
8078
8092
|
argType = exprTypeResult.type;
|
@@ -8643,6 +8657,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8643
8657
|
}
|
8644
8658
|
}
|
8645
8659
|
return getTypeOfTypeAliasCommon(nameNode, nameNode, valueExpr,
|
8660
|
+
/* isPep695Syntax */ false,
|
8646
8661
|
/* typeParamNodes */ undefined, () => typeParameters !== null && typeParameters !== void 0 ? typeParameters : []);
|
8647
8662
|
}
|
8648
8663
|
function getBooleanValue(node) {
|
@@ -10490,7 +10505,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10490
10505
|
}
|
10491
10506
|
return createSpecialType(classType, typeArgs, /* paramLimit */ undefined, /* allowParamSpec */ true);
|
10492
10507
|
}
|
10493
|
-
function transformTypeForTypeAlias(type, name, errorNode, typeParameters, typeParamNodes) {
|
10508
|
+
function transformTypeForTypeAlias(type, name, errorNode, isPep695Syntax, typeParameters, typeParamNodes) {
|
10494
10509
|
if (!types_1.TypeBase.isInstantiable(type)) {
|
10495
10510
|
return type;
|
10496
10511
|
}
|
@@ -10540,7 +10555,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10540
10555
|
names: boundTypeVars.map((t) => `${t.details.name}`).join(', '),
|
10541
10556
|
}), errorNode);
|
10542
10557
|
}
|
10543
|
-
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);
|
10544
10559
|
}
|
10545
10560
|
function createSpecialBuiltInClass(node, assignedName, aliasMapEntry) {
|
10546
10561
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
@@ -10761,6 +10776,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10761
10776
|
typeAliasTypeVar.details.recursiveTypeAliasName = typeAliasNameNode.value;
|
10762
10777
|
const scopeId = ParseTreeUtils.getScopeIdForNode(typeAliasNameNode);
|
10763
10778
|
typeAliasTypeVar.details.recursiveTypeAliasScopeId = scopeId;
|
10779
|
+
typeAliasTypeVar.details.recursiveTypeAliasIsPep695Syntax = false;
|
10764
10780
|
typeAliasTypeVar.scopeId = scopeId;
|
10765
10781
|
// Write the type back to the type cache. It will be replaced below.
|
10766
10782
|
writeTypeCache(node, { type: typeAliasTypeVar }, /* flags */ undefined);
|
@@ -10805,7 +10821,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10805
10821
|
if (!isSpeculativeTypeAlias ||
|
10806
10822
|
(types_1.TypeBase.isInstantiable(rightHandType) && !(0, types_1.isUnknown)(rightHandType))) {
|
10807
10823
|
// If this is a type alias, record its name based on the assignment target.
|
10808
|
-
rightHandType = transformTypeForTypeAlias(rightHandType, typeAliasNameNode, node.rightExpression
|
10824
|
+
rightHandType = transformTypeForTypeAlias(rightHandType, typeAliasNameNode, node.rightExpression,
|
10825
|
+
/* isPep695Syntax */ false);
|
10809
10826
|
if ((0, typeUtils_1.isTypeAliasRecursive)(typeAliasTypeVar, rightHandType)) {
|
10810
10827
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasIsRecursiveDirect().format({
|
10811
10828
|
name: typeAliasNameNode.value,
|
@@ -10846,7 +10863,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10846
10863
|
callLeftNode.leftExpression.nodeType === 38 /* Name */)) {
|
10847
10864
|
// See if this is a call to TypedDict. We want to support
|
10848
10865
|
// recursive type references in a TypedDict call.
|
10849
|
-
const callType = getTypeOfExpression(callLeftNode,
|
10866
|
+
const callType = getTypeOfExpression(callLeftNode, 16777218 /* CallBaseDefaults */).type;
|
10850
10867
|
if ((0, types_1.isInstantiableClass)(callType) && types_1.ClassType.isBuiltIn(callType, 'TypedDict')) {
|
10851
10868
|
return true;
|
10852
10869
|
}
|
@@ -10859,7 +10876,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10859
10876
|
// variables since they use normal variable assignment syntax.
|
10860
10877
|
function getTypeOfTypeAlias(node) {
|
10861
10878
|
var _a;
|
10862
|
-
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, () => {
|
10863
10881
|
let typeParameters = [];
|
10864
10882
|
if (node.typeParameters) {
|
10865
10883
|
typeParameters = evaluateTypeParameterList(node.typeParameters);
|
@@ -10869,7 +10887,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10869
10887
|
}
|
10870
10888
|
// This function is common to the handling of "type" statements and explicit
|
10871
10889
|
// calls to the TypeAliasType constructor.
|
10872
|
-
function getTypeOfTypeAliasCommon(declNode, nameNode, valueNode, typeParamNodes, getTypeParamCallback) {
|
10890
|
+
function getTypeOfTypeAliasCommon(declNode, nameNode, valueNode, isPep695Syntax, typeParamNodes, getTypeParamCallback) {
|
10873
10891
|
const cachedType = readTypeCache(nameNode, 0 /* None */);
|
10874
10892
|
if (cachedType) {
|
10875
10893
|
return cachedType;
|
@@ -10881,6 +10899,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10881
10899
|
typeAliasTypeVar.details.recursiveTypeAliasName = nameNode.value;
|
10882
10900
|
const scopeId = ParseTreeUtils.getScopeIdForNode(nameNode);
|
10883
10901
|
typeAliasTypeVar.details.recursiveTypeAliasScopeId = scopeId;
|
10902
|
+
typeAliasTypeVar.details.recursiveTypeAliasIsPep695Syntax = isPep695Syntax;
|
10884
10903
|
typeAliasTypeVar.scopeId = scopeId;
|
10885
10904
|
// Write the type to the type cache. It will be replaced below.
|
10886
10905
|
writeTypeCache(nameNode, { type: typeAliasTypeVar }, /* flags */ undefined);
|
@@ -10902,7 +10921,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10902
10921
|
if (aliasTypeResult.isIncomplete) {
|
10903
10922
|
isIncomplete = true;
|
10904
10923
|
}
|
10905
|
-
aliasType = transformTypeForTypeAlias(aliasType, nameNode, valueNode, typeParameters, typeParamNodes);
|
10924
|
+
aliasType = transformTypeForTypeAlias(aliasType, nameNode, valueNode, isPep695Syntax, typeParameters, typeParamNodes);
|
10906
10925
|
if ((0, typeUtils_1.isTypeAliasRecursive)(typeAliasTypeVar, aliasType)) {
|
10907
10926
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(valueNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasIsRecursiveDirect().format({
|
10908
10927
|
name: nameNode.value,
|
@@ -10998,7 +11017,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10998
11017
|
262144 /* DisallowNakedGeneric */ |
|
10999
11018
|
2048 /* DisallowTypeVarsWithScopeId */ |
|
11000
11019
|
8192 /* AssociateTypeVarsWithCurrentScope */ |
|
11001
|
-
16384 /* EnforceTypeVarVarianceConsistency
|
11020
|
+
16384 /* EnforceTypeVarVarianceConsistency */ |
|
11021
|
+
16777216 /* DisallowPep695TypeAlias */;
|
11002
11022
|
if (fileInfo.isStubFile) {
|
11003
11023
|
exprFlags |= 4 /* AllowForwardReferences */;
|
11004
11024
|
}
|
@@ -13029,14 +13049,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13029
13049
|
nodeToEvaluate = parent;
|
13030
13050
|
continue;
|
13031
13051
|
}
|
13032
|
-
flags =
|
13052
|
+
flags = 16777218 /* CallBaseDefaults */;
|
13033
13053
|
break;
|
13034
13054
|
}
|
13035
13055
|
}
|
13036
13056
|
else if (parent.nodeType === 24 /* Index */) {
|
13037
13057
|
// The base expression of an index expression is not contextual.
|
13038
13058
|
if (nodeToEvaluate === parent.baseExpression) {
|
13039
|
-
flags = 2 /*
|
13059
|
+
flags = 2 /* IndexBaseDefaults */;
|
13040
13060
|
break;
|
13041
13061
|
}
|
13042
13062
|
}
|
@@ -14481,7 +14501,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14481
14501
|
}
|
14482
14502
|
// Special-case calls to certain built-in type functions.
|
14483
14503
|
if (((_a = resolvedDecl.inferredTypeSource) === null || _a === void 0 ? void 0 : _a.nodeType) === 9 /* Call */) {
|
14484
|
-
const baseTypeResult = getTypeOfExpression(resolvedDecl.inferredTypeSource.leftExpression,
|
14504
|
+
const baseTypeResult = getTypeOfExpression(resolvedDecl.inferredTypeSource.leftExpression, 16777218 /* CallBaseDefaults */);
|
14485
14505
|
const callType = baseTypeResult.type;
|
14486
14506
|
const exemptBuiltins = [
|
14487
14507
|
'TypeVar',
|
@@ -14537,7 +14557,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14537
14557
|
if (types_1.TypeBase.isInstantiable(inferredType) &&
|
14538
14558
|
!(0, types_1.isUnknown)(inferredType) &&
|
14539
14559
|
!(0, typeUtils_1.isEllipsisType)(inferredType)) {
|
14540
|
-
inferredType = transformTypeForTypeAlias(inferredType, resolvedDecl.typeAliasName, resolvedDecl.node
|
14560
|
+
inferredType = transformTypeForTypeAlias(inferredType, resolvedDecl.typeAliasName, resolvedDecl.node,
|
14561
|
+
/* isPep695Syntax */ false);
|
14541
14562
|
isUnambiguousType = true;
|
14542
14563
|
}
|
14543
14564
|
}
|
@@ -14972,6 +14993,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14972
14993
|
return types_1.UnknownType.create();
|
14973
14994
|
}
|
14974
14995
|
function getFunctionInferredReturnType(type, args) {
|
14996
|
+
var _a;
|
14975
14997
|
let returnType;
|
14976
14998
|
let isIncomplete = false;
|
14977
14999
|
let analyzeUnannotatedFunctions = true;
|
@@ -15039,9 +15061,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15039
15061
|
!types_1.FunctionType.isStubDefinition(type) &&
|
15040
15062
|
!types_1.FunctionType.isPyTypedDefinition(type) &&
|
15041
15063
|
args) {
|
15042
|
-
|
15043
|
-
|
15044
|
-
|
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
|
+
}
|
15045
15082
|
}
|
15046
15083
|
}
|
15047
15084
|
return returnType;
|
@@ -17076,6 +17113,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17076
17113
|
!(0, types_1.isTypeSame)(srcParamSpec, destParamSpec, { ignoreTypeFlags: true })) {
|
17077
17114
|
const remainingFunction = types_1.FunctionType.createInstance('', '', '', effectiveSrcType.details.flags | 64 /* SynthesizedMethod */, effectiveSrcType.details.docString);
|
17078
17115
|
remainingFunction.details.typeVarScopeId = effectiveSrcType.details.typeVarScopeId;
|
17116
|
+
remainingFunction.details.constructorTypeVarScopeId =
|
17117
|
+
effectiveSrcType.details.constructorTypeVarScopeId;
|
17079
17118
|
remainingParams.forEach((param) => {
|
17080
17119
|
types_1.FunctionType.addParameter(remainingFunction, param);
|
17081
17120
|
});
|
@@ -17174,7 +17213,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17174
17213
|
const typeParam = assignedType.details.typeParameters[index];
|
17175
17214
|
const expectedTypeArgType = typeVarContext.getPrimarySignature().getTypeVarType(typeParam);
|
17176
17215
|
if (expectedTypeArgType) {
|
17177
|
-
if ((0,
|
17216
|
+
if ((0, types_1.isAnyOrUnknown)(expectedTypeArgType) || (0, types_1.isAnyOrUnknown)(typeArg)) {
|
17178
17217
|
replacedTypeArg = true;
|
17179
17218
|
return expectedTypeArgType;
|
17180
17219
|
}
|
@@ -17186,6 +17225,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17186
17225
|
return recursiveReplacement;
|
17187
17226
|
}
|
17188
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
|
+
}
|
17189
17241
|
}
|
17190
17242
|
return typeArg;
|
17191
17243
|
});
|