@zzzen/pyright-internal 1.2.0-dev.20240630 → 1.2.0-dev.20240707
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/binder.js +1 -1
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +4 -0
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +58 -23
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolver.d.ts +1 -1
- package/dist/analyzer/constraintSolver.js +3 -3
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructors.js +34 -29
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +6 -3
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declaration.d.ts +1 -1
- package/dist/analyzer/decorators.js +12 -12
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/enums.js +1 -1
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/operations.d.ts +4 -4
- package/dist/analyzer/operations.js +6 -6
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/patternMatching.js +27 -12
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/protocols.js +1 -1
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +3 -2
- package/dist/analyzer/sourceFile.js +5 -5
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +547 -531
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +28 -27
- package/dist/analyzer/typeEvaluatorTypes.js +45 -41
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +22 -18
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +12 -6
- package/dist/analyzer/typeUtils.js +36 -10
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +3 -1
- package/dist/analyzer/types.js +7 -0
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/diagnostic.d.ts +14 -0
- package/dist/common/diagnostic.js +41 -1
- package/dist/common/diagnostic.js.map +1 -1
- package/dist/common/diagnosticSink.d.ts +4 -0
- package/dist/common/diagnosticSink.js +21 -1
- package/dist/common/diagnosticSink.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +1 -1
- package/dist/languageService/completionProvider.js +3 -3
- package/dist/languageService/completionProvider.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.en-us.json +2 -1
- package/dist/parser/parser.js +6 -3
- package/dist/parser/parser.js.map +1 -1
- package/dist/pyright.js +265 -5
- package/dist/pyright.js.map +1 -1
- package/dist/tests/fourslash/hover.init.fourslash.js +1 -1
- package/dist/tests/fourslash/hover.init.fourslash.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +2 -2
- package/dist/tests/typeEvaluator3.test.js +2 -2
- package/dist/tests/typeEvaluator4.test.js +1 -1
- package/dist/tests/typeEvaluator7.test.js +2 -2
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/package.json +1 -1
@@ -303,7 +303,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
303
303
|
}
|
304
304
|
}
|
305
305
|
}
|
306
|
-
function setTypeResultForNode(node, typeResult, flags = 0 /*
|
306
|
+
function setTypeResultForNode(node, typeResult, flags = 0 /* EvalFlags.None */) {
|
307
307
|
writeTypeCache(node, typeResult, flags);
|
308
308
|
}
|
309
309
|
function setAsymmetricDescriptorAssignment(node) {
|
@@ -419,7 +419,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
419
419
|
}
|
420
420
|
// Reads the type of the node from the cache.
|
421
421
|
function getCachedType(node) {
|
422
|
-
return readTypeCache(node, 0 /*
|
422
|
+
return readTypeCache(node, 0 /* EvalFlags.None */);
|
423
423
|
}
|
424
424
|
// Determines the expected type of a specified node based on surrounding
|
425
425
|
// context. For example, if it's a subexpression of an argument expression,
|
@@ -487,7 +487,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
487
487
|
}
|
488
488
|
// Wire up the `Any` class to the special-form version of our internal AnyType.
|
489
489
|
if (objectClass && (0, types_1.isInstantiableClass)(objectClass) && typeClass && (0, types_1.isInstantiableClass)(typeClass)) {
|
490
|
-
const anyClass = types_1.ClassType.createInstantiable('Any', 'typing.Any', 'typing', uri_1.Uri.empty(), 1 /* ClassTypeFlags.BuiltInClass */ |
|
490
|
+
const anyClass = types_1.ClassType.createInstantiable('Any', 'typing.Any', 'typing', uri_1.Uri.empty(), 1 /* ClassTypeFlags.BuiltInClass */ |
|
491
|
+
8388608 /* ClassTypeFlags.SpecialFormClass */ |
|
492
|
+
16777216 /* ClassTypeFlags.IllegalIsinstanceClass */,
|
491
493
|
/* typeSourceId */ -1,
|
492
494
|
/* declaredMetaclass */ undefined,
|
493
495
|
/* effectiveMetaclass */ typeClass);
|
@@ -500,7 +502,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
500
502
|
}
|
501
503
|
}
|
502
504
|
}
|
503
|
-
function getTypeOfExpression(node, flags = 0 /*
|
505
|
+
function getTypeOfExpression(node, flags = 0 /* EvalFlags.None */, inferenceContext, signatureTracker) {
|
504
506
|
// Is this type already cached?
|
505
507
|
const cacheEntry = readTypeCacheEntry(node);
|
506
508
|
if (cacheEntry &&
|
@@ -584,9 +586,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
584
586
|
return typeResult;
|
585
587
|
}
|
586
588
|
// This is a helper function that implements the core of getTypeOfExpression.
|
587
|
-
function getTypeOfExpressionCore(node, flags = 0 /*
|
589
|
+
function getTypeOfExpressionCore(node, flags = 0 /* EvalFlags.None */, inferenceContext, signatureTracker) {
|
588
590
|
let typeResult;
|
589
|
-
let expectingInstantiable = (flags & 128 /*
|
591
|
+
let expectingInstantiable = (flags & 128 /* EvalFlags.InstantiableType */) !== 0;
|
590
592
|
switch (node.nodeType) {
|
591
593
|
case 38 /* ParseNodeType.Name */: {
|
592
594
|
typeResult = getTypeOfName(node, flags);
|
@@ -613,7 +615,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
613
615
|
break;
|
614
616
|
}
|
615
617
|
case 48 /* ParseNodeType.StringList */: {
|
616
|
-
const isExpectingType = (flags & 8 /*
|
618
|
+
const isExpectingType = (flags & 8 /* EvalFlags.StrLiteralAsType */) !== 0 && !isAnnotationLiteralValue(node);
|
617
619
|
if (isExpectingType) {
|
618
620
|
// Don't report expecting type errors again. We will have already
|
619
621
|
// reported them when analyzing the contents of the string.
|
@@ -639,7 +641,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
639
641
|
// If we're expecting an instantiable type and this isn't a union operator,
|
640
642
|
// don't require that the two operands are also instantiable types.
|
641
643
|
if (expectingInstantiable && node.operator !== 6 /* OperatorType.BitwiseOr */) {
|
642
|
-
effectiveFlags &= ~128 /*
|
644
|
+
effectiveFlags &= ~128 /* EvalFlags.InstantiableType */;
|
643
645
|
}
|
644
646
|
typeResult = (0, operations_1.getTypeOfBinaryOperation)(evaluatorInterface, node, effectiveFlags, inferenceContext);
|
645
647
|
break;
|
@@ -685,7 +687,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
685
687
|
break;
|
686
688
|
}
|
687
689
|
case 4 /* ParseNodeType.AssignmentExpression */: {
|
688
|
-
if ((flags & 256 /*
|
690
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
689
691
|
addError(localize_1.LocMessage.walrusNotAllowed(), node);
|
690
692
|
}
|
691
693
|
typeResult = getTypeOfExpression(node.rightExpression, flags, inferenceContext, signatureTracker);
|
@@ -705,12 +707,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
705
707
|
break;
|
706
708
|
}
|
707
709
|
case 54 /* ParseNodeType.TypeAnnotation */: {
|
708
|
-
typeResult = getTypeOfExpression(node.typeAnnotation, 128 /*
|
709
|
-
256 /*
|
710
|
-
8 /*
|
711
|
-
32 /*
|
712
|
-
64 /*
|
713
|
-
32768 /*
|
710
|
+
typeResult = getTypeOfExpression(node.typeAnnotation, 128 /* EvalFlags.InstantiableType */ |
|
711
|
+
256 /* EvalFlags.TypeExpression */ |
|
712
|
+
8 /* EvalFlags.StrLiteralAsType */ |
|
713
|
+
32 /* EvalFlags.NoParamSpec */ |
|
714
|
+
64 /* EvalFlags.NoTypeVarTuple */ |
|
715
|
+
32768 /* EvalFlags.VarTypeAnnotation */);
|
714
716
|
break;
|
715
717
|
}
|
716
718
|
case 49 /* ParseNodeType.String */:
|
@@ -742,7 +744,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
742
744
|
}
|
743
745
|
// If this is a PEP 695 type alias, remove the special form so the type
|
744
746
|
// printer prints it as its aliased type rather than TypeAliasType.
|
745
|
-
if ((flags & 256 /*
|
747
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
746
748
|
if (typeResult.type.specialForm && types_1.ClassType.isBuiltIn(typeResult.type.specialForm, 'TypeAliasType')) {
|
747
749
|
typeResult.type = types_1.TypeBase.cloneAsSpecialForm(typeResult.type, undefined);
|
748
750
|
}
|
@@ -775,26 +777,37 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
775
777
|
if (typeResult.isIncomplete) {
|
776
778
|
return;
|
777
779
|
}
|
778
|
-
if (flags & 64 /*
|
780
|
+
if ((flags & 64 /* EvalFlags.NoTypeVarTuple */) !== 0) {
|
779
781
|
if ((0, types_1.isVariadicTypeVar)(typeResult.type) && !typeResult.type.isVariadicInUnion) {
|
780
782
|
addError(localize_1.LocMessage.typeVarTupleContext(), node);
|
781
783
|
typeResult.type = types_1.UnknownType.create();
|
782
784
|
}
|
783
785
|
}
|
784
|
-
if (
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
786
|
+
if ((0, typeUtils_1.isEffectivelyInstantiable)(typeResult.type, { honorTypeVarBounds: true })) {
|
787
|
+
return;
|
788
|
+
}
|
789
|
+
// Exempt ellipses.
|
790
|
+
if ((0, types_1.isClassInstance)(typeResult.type) && types_1.ClassType.isBuiltIn(typeResult.type, ['EllipsisType', 'ellipsis'])) {
|
791
|
+
return;
|
792
|
+
}
|
793
|
+
// Exempt empty tuples, which can be used for specializing a TypeVarTuple.
|
794
|
+
if ((0, types_1.isClassInstance)(typeResult.type) && ((_a = typeResult.type.tupleTypeArguments) === null || _a === void 0 ? void 0 : _a.length) === 0) {
|
795
|
+
return;
|
796
|
+
}
|
797
|
+
const diag = new diagnostic_1.DiagnosticAddendum();
|
798
|
+
if ((0, types_1.isUnion)(typeResult.type)) {
|
799
|
+
(0, typeUtils_1.doForEachSubtype)(typeResult.type, (subtype) => {
|
800
|
+
if (!(0, typeUtils_1.isEffectivelyInstantiable)(subtype, { honorTypeVarBounds: true })) {
|
801
|
+
diag.addMessage(localize_1.LocAddendum.typeNotClass().format({ type: printType(subtype) }));
|
802
|
+
}
|
803
|
+
});
|
794
804
|
}
|
805
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeExpectedClass().format({ type: printType(typeResult.type) }) + diag.getString(), node);
|
806
|
+
typeResult.type = types_1.UnknownType.create();
|
807
|
+
typeResult.typeErrors = true;
|
795
808
|
}
|
796
809
|
function getTypeOfAwaitOperator(node, flags, inferenceContext) {
|
797
|
-
if ((flags & 256 /*
|
810
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
798
811
|
addError(localize_1.LocMessage.awaitNotAllowed(), node);
|
799
812
|
return { type: types_1.UnknownType.create() };
|
800
813
|
}
|
@@ -816,7 +829,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
816
829
|
}
|
817
830
|
function getTypeOfEllipsis(flags, typeResult, node) {
|
818
831
|
var _a, _b;
|
819
|
-
if ((flags & 1 /*
|
832
|
+
if ((flags & 1 /* EvalFlags.ConvertEllipsisToAny */) !== 0) {
|
820
833
|
typeResult = { type: types_1.AnyType.create(/* isEllipsis */ true) };
|
821
834
|
}
|
822
835
|
else {
|
@@ -850,17 +863,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
850
863
|
}
|
851
864
|
const iterTypeResult = getTypeOfExpression(node.expression, flags, (0, typeUtils_1.makeInferenceContext)(iterExpectedType));
|
852
865
|
const iterType = iterTypeResult.type;
|
853
|
-
if ((flags & 64 /*
|
854
|
-
(0, types_1.isVariadicTypeVar)(iterType) &&
|
855
|
-
!iterType.isVariadicUnpacked) {
|
866
|
+
if ((flags & 64 /* EvalFlags.NoTypeVarTuple */) === 0 && (0, types_1.isVariadicTypeVar)(iterType) && !iterType.isVariadicUnpacked) {
|
856
867
|
typeResult = { type: types_1.TypeVarType.cloneForUnpacked(iterType) };
|
857
868
|
}
|
858
|
-
else if ((flags & 2097152 /*
|
869
|
+
else if ((flags & 2097152 /* EvalFlags.AllowUnpackedTuple */) !== 0 &&
|
859
870
|
(0, types_1.isInstantiableClass)(iterType) &&
|
860
871
|
types_1.ClassType.isBuiltIn(iterType, 'tuple')) {
|
861
872
|
typeResult = { type: types_1.ClassType.cloneForUnpacked(iterType) };
|
862
873
|
}
|
863
|
-
else if ((flags & 256 /*
|
874
|
+
else if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
864
875
|
addError(localize_1.LocMessage.unpackInAnnotation(), node, node.starToken);
|
865
876
|
typeResult = { type: types_1.UnknownType.create() };
|
866
877
|
}
|
@@ -881,11 +892,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
881
892
|
function getTypeOfStringList(node, flags, isExpectingType) {
|
882
893
|
let typeResult;
|
883
894
|
if (isExpectingType) {
|
884
|
-
let updatedFlags = flags | 4 /*
|
895
|
+
let updatedFlags = flags | 4 /* EvalFlags.ForwardRefs */ | 128 /* EvalFlags.InstantiableType */;
|
885
896
|
// In most cases, annotations within a string are not parsed by the interpreter.
|
886
897
|
// There are a few exceptions (e.g. the "bound" value for a TypeVar constructor).
|
887
|
-
if ((flags &
|
888
|
-
updatedFlags |= 524288 /*
|
898
|
+
if ((flags & 8388608 /* EvalFlags.ParsesStringLiteral */) === 0) {
|
899
|
+
updatedFlags |= 524288 /* EvalFlags.NotParsed */;
|
889
900
|
}
|
890
901
|
if (node.typeAnnotation) {
|
891
902
|
typeResult = getTypeOfExpression(node.typeAnnotation, updatedFlags);
|
@@ -1068,59 +1079,59 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1068
1079
|
return specialType;
|
1069
1080
|
}
|
1070
1081
|
}
|
1071
|
-
let evaluatorFlags = 128 /*
|
1072
|
-
256 /*
|
1073
|
-
1 /*
|
1074
|
-
8 /*
|
1082
|
+
let evaluatorFlags = 128 /* EvalFlags.InstantiableType */ |
|
1083
|
+
256 /* EvalFlags.TypeExpression */ |
|
1084
|
+
1 /* EvalFlags.ConvertEllipsisToAny */ |
|
1085
|
+
8 /* EvalFlags.StrLiteralAsType */;
|
1075
1086
|
if (options === null || options === void 0 ? void 0 : options.isVariableAnnotation) {
|
1076
|
-
evaluatorFlags |= 32768 /*
|
1087
|
+
evaluatorFlags |= 32768 /* EvalFlags.VarTypeAnnotation */;
|
1077
1088
|
}
|
1078
1089
|
if (!(options === null || options === void 0 ? void 0 : options.allowFinal)) {
|
1079
|
-
evaluatorFlags |= 16 /*
|
1090
|
+
evaluatorFlags |= 16 /* EvalFlags.NoFinal */;
|
1080
1091
|
}
|
1081
1092
|
if (!(options === null || options === void 0 ? void 0 : options.allowClassVar)) {
|
1082
|
-
evaluatorFlags |= 131072 /*
|
1093
|
+
evaluatorFlags |= 131072 /* EvalFlags.NoClassVar */;
|
1083
1094
|
}
|
1084
1095
|
if (!(options === null || options === void 0 ? void 0 : options.allowTypeVarTuple)) {
|
1085
|
-
evaluatorFlags |= 64 /*
|
1096
|
+
evaluatorFlags |= 64 /* EvalFlags.NoTypeVarTuple */;
|
1086
1097
|
}
|
1087
1098
|
else {
|
1088
|
-
evaluatorFlags |= 2097152 /*
|
1099
|
+
evaluatorFlags |= 2097152 /* EvalFlags.AllowUnpackedTuple */;
|
1089
1100
|
}
|
1090
1101
|
if (!(options === null || options === void 0 ? void 0 : options.allowParamSpec)) {
|
1091
|
-
evaluatorFlags |= 32 /*
|
1102
|
+
evaluatorFlags |= 32 /* EvalFlags.NoParamSpec */;
|
1092
1103
|
}
|
1093
1104
|
if (options === null || options === void 0 ? void 0 : options.associateTypeVarsWithScope) {
|
1094
|
-
evaluatorFlags |= 8192 /*
|
1105
|
+
evaluatorFlags |= 8192 /* EvalFlags.TypeVarGetsCurScope */;
|
1095
1106
|
}
|
1096
1107
|
if (options === null || options === void 0 ? void 0 : options.allowUnpackedTypedDict) {
|
1097
|
-
evaluatorFlags |=
|
1108
|
+
evaluatorFlags |= 4194304 /* EvalFlags.AllowUnpackedTypedDict */;
|
1098
1109
|
}
|
1099
1110
|
if (options === null || options === void 0 ? void 0 : options.allowUnpackedTuple) {
|
1100
|
-
evaluatorFlags |= 2097152 /*
|
1111
|
+
evaluatorFlags |= 2097152 /* EvalFlags.AllowUnpackedTuple */;
|
1101
1112
|
}
|
1102
1113
|
if (options === null || options === void 0 ? void 0 : options.notParsedByInterpreter) {
|
1103
|
-
evaluatorFlags |= 524288 /*
|
1114
|
+
evaluatorFlags |= 524288 /* EvalFlags.NotParsed */;
|
1104
1115
|
}
|
1105
1116
|
if (options === null || options === void 0 ? void 0 : options.allowRequired) {
|
1106
|
-
evaluatorFlags |= 1048576 /*
|
1117
|
+
evaluatorFlags |= 1048576 /* EvalFlags.AllowRequired */;
|
1107
1118
|
}
|
1108
1119
|
if ((0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(fileInfo)) {
|
1109
|
-
evaluatorFlags |= 4 /*
|
1120
|
+
evaluatorFlags |= 4 /* EvalFlags.ForwardRefs */;
|
1110
1121
|
}
|
1111
1122
|
// If the annotation is part of a comment, allow forward references
|
1112
1123
|
// even if it's not enclosed in quotes.
|
1113
1124
|
if (((_a = node === null || node === void 0 ? void 0 : node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 3 /* ParseNodeType.Assignment */ && node.parent.typeAnnotationComment === node) {
|
1114
|
-
evaluatorFlags |= 4 /*
|
1125
|
+
evaluatorFlags |= 4 /* EvalFlags.ForwardRefs */ | 524288 /* EvalFlags.NotParsed */;
|
1115
1126
|
}
|
1116
1127
|
else if (((_b = node === null || node === void 0 ? void 0 : node.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 62 /* ParseNodeType.FunctionAnnotation */) {
|
1117
1128
|
if (node.parent.returnTypeAnnotation === node || node.parent.paramTypeAnnotations.some((n) => n === node)) {
|
1118
|
-
evaluatorFlags |= 4 /*
|
1129
|
+
evaluatorFlags |= 4 /* EvalFlags.ForwardRefs */ | 524288 /* EvalFlags.NotParsed */;
|
1119
1130
|
}
|
1120
1131
|
}
|
1121
1132
|
else if (((_c = node === null || node === void 0 ? void 0 : node.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 41 /* ParseNodeType.Parameter */) {
|
1122
1133
|
if (node.parent.typeAnnotationComment === node) {
|
1123
|
-
evaluatorFlags |= 4 /*
|
1134
|
+
evaluatorFlags |= 4 /* EvalFlags.ForwardRefs */ | 524288 /* EvalFlags.NotParsed */;
|
1124
1135
|
}
|
1125
1136
|
}
|
1126
1137
|
const annotationType = getTypeOfExpression(node, evaluatorFlags).type;
|
@@ -1721,7 +1732,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1721
1732
|
return getDeclaredTypeForExpression(expression.valueExpression, usage);
|
1722
1733
|
}
|
1723
1734
|
case 35 /* ParseNodeType.MemberAccess */: {
|
1724
|
-
const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.leftExpression, 2 /*
|
1735
|
+
const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.leftExpression, 2 /* EvalFlags.MemberAccessBaseDefaults */).type);
|
1725
1736
|
let classMemberInfo;
|
1726
1737
|
if ((0, types_1.isClassInstance)(baseType)) {
|
1727
1738
|
classMemberInfo = (0, typeUtils_1.lookUpObjectMember)(baseType, expression.memberName.value, 64 /* MemberAccessFlags.DeclaredTypesOnly */);
|
@@ -1745,7 +1756,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1745
1756
|
break;
|
1746
1757
|
}
|
1747
1758
|
case 27 /* ParseNodeType.Index */: {
|
1748
|
-
const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.baseExpression, 2 /*
|
1759
|
+
const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.baseExpression, 2 /* EvalFlags.IndexBaseDefaults */).type);
|
1749
1760
|
if (baseType && (0, types_1.isClassInstance)(baseType)) {
|
1750
1761
|
const setItemType = getBoundMagicMethod(baseType, '__setitem__');
|
1751
1762
|
if (setItemType && (0, types_1.isFunction)(setItemType) && setItemType.details.parameters.length >= 2) {
|
@@ -2217,17 +2228,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2217
2228
|
}
|
2218
2229
|
return diagnostic;
|
2219
2230
|
}
|
2220
|
-
function addExpectedClassDiagnostic(type, node) {
|
2221
|
-
const diag = new diagnostic_1.DiagnosticAddendum();
|
2222
|
-
if ((0, types_1.isUnion)(type)) {
|
2223
|
-
(0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
|
2224
|
-
if (!(0, typeUtils_1.isEffectivelyInstantiable)(subtype)) {
|
2225
|
-
diag.addMessage(localize_1.LocAddendum.typeNotClass().format({ type: printType(subtype) }));
|
2226
|
-
}
|
2227
|
-
});
|
2228
|
-
}
|
2229
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeExpectedClass().format({ type: printType(type) }) + diag.getString(), node);
|
2230
|
-
}
|
2231
2231
|
function assignTypeToNameNode(nameNode, typeResult, ignoreEmptyContainers, srcExpression, allowAssignmentToFinalVar = false, expectedTypeDiagAddendum) {
|
2232
2232
|
var _a, _b, _c;
|
2233
2233
|
const nameValue = nameNode.value;
|
@@ -2310,11 +2310,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2310
2310
|
if (!typeResult.isIncomplete) {
|
2311
2311
|
reportPossibleUnknownAssignment(fileInfo.diagnosticRuleSet.reportUnknownVariableType, diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, nameNode, destType, nameNode, ignoreEmptyContainers);
|
2312
2312
|
}
|
2313
|
-
writeTypeCache(nameNode, { type: destType, isIncomplete: typeResult.isIncomplete }, 0 /*
|
2313
|
+
writeTypeCache(nameNode, { type: destType, isIncomplete: typeResult.isIncomplete }, 0 /* EvalFlags.None */);
|
2314
2314
|
}
|
2315
2315
|
function assignTypeToMemberAccessNode(target, typeResult, srcExpr, expectedTypeDiagAddendum) {
|
2316
2316
|
var _a;
|
2317
|
-
const baseTypeResult = getTypeOfExpression(target.leftExpression, 2 /*
|
2317
|
+
const baseTypeResult = getTypeOfExpression(target.leftExpression, 2 /* EvalFlags.MemberAccessBaseDefaults */);
|
2318
2318
|
const baseType = makeTopLevelTypeVarsConcrete(baseTypeResult.type);
|
2319
2319
|
// Handle member accesses (e.g. self.x or cls.y).
|
2320
2320
|
if (target.leftExpression.nodeType === 38 /* ParseNodeType.Name */) {
|
@@ -2354,7 +2354,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2354
2354
|
setType: typeResult,
|
2355
2355
|
setErrorNode: srcExpr,
|
2356
2356
|
setExpectedTypeDiag: expectedTypeDiagAddendum,
|
2357
|
-
}, 0 /*
|
2357
|
+
}, 0 /* EvalFlags.None */);
|
2358
2358
|
if (setTypeResult.isAsymmetricAccessor) {
|
2359
2359
|
setAsymmetricDescriptorAssignment(target);
|
2360
2360
|
}
|
@@ -2363,8 +2363,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2363
2363
|
isIncomplete: typeResult.isIncomplete,
|
2364
2364
|
memberAccessDeprecationInfo: setTypeResult.memberAccessDeprecationInfo,
|
2365
2365
|
};
|
2366
|
-
writeTypeCache(target.memberName, resultToCache, 0 /*
|
2367
|
-
writeTypeCache(target, resultToCache, 0 /*
|
2366
|
+
writeTypeCache(target.memberName, resultToCache, 0 /* EvalFlags.None */);
|
2367
|
+
writeTypeCache(target, resultToCache, 0 /* EvalFlags.None */);
|
2368
2368
|
}
|
2369
2369
|
function assignTypeToMemberVariable(node, typeResult, isInstanceMember, srcExprNode) {
|
2370
2370
|
var _a;
|
@@ -2539,7 +2539,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2539
2539
|
assignTypeToExpression(expr, { type: targetType, isIncomplete: typeResult.isIncomplete }, srcExpr,
|
2540
2540
|
/* ignoreEmptyContainers */ true);
|
2541
2541
|
});
|
2542
|
-
writeTypeCache(target, typeResult, 0 /*
|
2542
|
+
writeTypeCache(target, typeResult, 0 /* EvalFlags.None */);
|
2543
2543
|
}
|
2544
2544
|
// If the type includes promotion types, expand these to their constituent types.
|
2545
2545
|
function expandPromotionTypes(node, type, excludeBytes = false) {
|
@@ -2767,7 +2767,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2767
2767
|
// Is the source expression a TypeVar() call?
|
2768
2768
|
if ((0, types_1.isTypeVar)(typeResult.type)) {
|
2769
2769
|
if (srcExpr && srcExpr.nodeType === 9 /* ParseNodeType.Call */) {
|
2770
|
-
const callType = getTypeOfExpression(srcExpr.leftExpression, 2 /*
|
2770
|
+
const callType = getTypeOfExpression(srcExpr.leftExpression, 2 /* EvalFlags.CallBaseDefaults */).type;
|
2771
2771
|
if ((0, types_1.isInstantiableClass)(callType) &&
|
2772
2772
|
(types_1.ClassType.isBuiltIn(callType, 'TypeVar') ||
|
2773
2773
|
types_1.ClassType.isBuiltIn(callType, 'TypeVarTuple') ||
|
@@ -2802,14 +2802,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2802
2802
|
break;
|
2803
2803
|
}
|
2804
2804
|
case 27 /* ParseNodeType.Index */: {
|
2805
|
-
const baseTypeResult = getTypeOfExpression(target.baseExpression, 2 /*
|
2805
|
+
const baseTypeResult = getTypeOfExpression(target.baseExpression, 2 /* EvalFlags.IndexBaseDefaults */);
|
2806
2806
|
getTypeOfIndexWithBaseType(target, baseTypeResult, {
|
2807
2807
|
method: 'set',
|
2808
2808
|
setType: typeResult,
|
2809
2809
|
setErrorNode: srcExpr,
|
2810
2810
|
setExpectedTypeDiag: expectedTypeDiagAddendum,
|
2811
|
-
}, 0 /*
|
2812
|
-
writeTypeCache(target, typeResult, 0 /*
|
2811
|
+
}, 0 /* EvalFlags.None */);
|
2812
|
+
writeTypeCache(target, typeResult, 0 /* EvalFlags.None */);
|
2813
2813
|
break;
|
2814
2814
|
}
|
2815
2815
|
case 34 /* ParseNodeType.List */:
|
@@ -2931,20 +2931,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2931
2931
|
break;
|
2932
2932
|
}
|
2933
2933
|
case 35 /* ParseNodeType.MemberAccess */: {
|
2934
|
-
const baseTypeResult = getTypeOfExpression(node.leftExpression, 2 /*
|
2935
|
-
const delAccessResult = getTypeOfMemberAccessWithBaseType(node, baseTypeResult, { method: 'del' }, 0 /*
|
2934
|
+
const baseTypeResult = getTypeOfExpression(node.leftExpression, 2 /* EvalFlags.MemberAccessBaseDefaults */);
|
2935
|
+
const delAccessResult = getTypeOfMemberAccessWithBaseType(node, baseTypeResult, { method: 'del' }, 0 /* EvalFlags.None */);
|
2936
2936
|
const resultToCache = {
|
2937
2937
|
type: delAccessResult.type,
|
2938
2938
|
memberAccessDeprecationInfo: delAccessResult.memberAccessDeprecationInfo,
|
2939
2939
|
};
|
2940
|
-
writeTypeCache(node.memberName, resultToCache, 0 /*
|
2941
|
-
writeTypeCache(node, resultToCache, 0 /*
|
2940
|
+
writeTypeCache(node.memberName, resultToCache, 0 /* EvalFlags.None */);
|
2941
|
+
writeTypeCache(node, resultToCache, 0 /* EvalFlags.None */);
|
2942
2942
|
break;
|
2943
2943
|
}
|
2944
2944
|
case 27 /* ParseNodeType.Index */: {
|
2945
|
-
const baseTypeResult = getTypeOfExpression(node.baseExpression, 2 /*
|
2946
|
-
getTypeOfIndexWithBaseType(node, baseTypeResult, { method: 'del' }, 0 /*
|
2947
|
-
writeTypeCache(node, { type: types_1.UnboundType.create() }, 0 /*
|
2945
|
+
const baseTypeResult = getTypeOfExpression(node.baseExpression, 2 /* EvalFlags.IndexBaseDefaults */);
|
2946
|
+
getTypeOfIndexWithBaseType(node, baseTypeResult, { method: 'del' }, 0 /* EvalFlags.None */);
|
2947
|
+
writeTypeCache(node, { type: types_1.UnboundType.create() }, 0 /* EvalFlags.None */);
|
2948
2948
|
break;
|
2949
2949
|
}
|
2950
2950
|
case 52 /* ParseNodeType.Tuple */: {
|
@@ -2980,17 +2980,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2980
2980
|
let symbol;
|
2981
2981
|
let type;
|
2982
2982
|
let isIncomplete = false;
|
2983
|
-
const allowForwardReferences = (flags & 4 /*
|
2983
|
+
const allowForwardReferences = (flags & 4 /* EvalFlags.ForwardRefs */) !== 0 || fileInfo.isStubFile;
|
2984
2984
|
// Look for the scope that contains the value definition and
|
2985
2985
|
// see if it has a declared type.
|
2986
|
-
let symbolWithScope = lookUpSymbolRecursive(node, name, !allowForwardReferences, allowForwardReferences && (flags & 256 /*
|
2986
|
+
let symbolWithScope = lookUpSymbolRecursive(node, name, !allowForwardReferences, allowForwardReferences && (flags & 256 /* EvalFlags.TypeExpression */) !== 0);
|
2987
2987
|
if (!symbolWithScope) {
|
2988
2988
|
// If the node is part of a "from X import Y as Z" statement and the node
|
2989
2989
|
// is the "Y" (non-aliased) name, we need to look up the alias symbol
|
2990
2990
|
// since the non-aliased name is not in the symbol table.
|
2991
2991
|
const alias = getAliasFromImport(node);
|
2992
2992
|
if (alias) {
|
2993
|
-
symbolWithScope = lookUpSymbolRecursive(alias, alias.value, !allowForwardReferences, allowForwardReferences && (flags & 256 /*
|
2993
|
+
symbolWithScope = lookUpSymbolRecursive(alias, alias.value, !allowForwardReferences, allowForwardReferences && (flags & 256 /* EvalFlags.TypeExpression */) !== 0);
|
2994
2994
|
}
|
2995
2995
|
}
|
2996
2996
|
if (symbolWithScope) {
|
@@ -3059,7 +3059,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3059
3059
|
const codeFlowTypeResult = getFlowTypeOfReference(node, /* startNode */ undefined, {
|
3060
3060
|
targetSymbolId: symbol.id,
|
3061
3061
|
typeAtStart: { type: typeAtStart, isIncomplete: isTypeAtStartIncomplete },
|
3062
|
-
skipConditionalNarrowing: (flags & 256 /*
|
3062
|
+
skipConditionalNarrowing: (flags & 256 /* EvalFlags.TypeExpression */) !== 0,
|
3063
3063
|
});
|
3064
3064
|
if (codeFlowTypeResult.type) {
|
3065
3065
|
type = codeFlowTypeResult.type;
|
@@ -3070,32 +3070,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3070
3070
|
}
|
3071
3071
|
// Detect, report, and fill in missing type arguments if appropriate.
|
3072
3072
|
type = reportMissingTypeArguments(node, type, flags);
|
3073
|
-
|
3074
|
-
|
3075
|
-
|
3076
|
-
let isAllowedTypeForVariable = (0, types_1.isTypeVar)(type) || (0, typeUtils_1.isTypeAliasPlaceholder)(type);
|
3077
|
-
if ((0, types_1.isClass)(type) &&
|
3078
|
-
!type.includeSubclasses &&
|
3079
|
-
!symbol.hasTypedDeclarations() &&
|
3080
|
-
types_1.ClassType.isValidTypeAliasClass(type)) {
|
3081
|
-
// This check exempts class types that are created by calling
|
3082
|
-
// NewType, NamedTuple, etc.
|
3083
|
-
isAllowedTypeForVariable = true;
|
3084
|
-
}
|
3085
|
-
// Disable for assignments in the typings.pyi file, since it defines special forms.
|
3086
|
-
if (!isAllowedTypeForVariable && !fileInfo.isTypingStubFile) {
|
3087
|
-
// This might be a union that was previously a type alias
|
3088
|
-
// but was reconstituted in such a way that we lost the
|
3089
|
-
// typeAliasInfo. Avoid the false positive error by suppressing
|
3090
|
-
// the error when it looks like a plausible type alias type.
|
3091
|
-
if (effectiveTypeInfo.includesIllegalTypeAliasDecl ||
|
3092
|
-
!types_1.TypeBase.isInstantiable(type) ||
|
3093
|
-
(flags & 2 /* EvaluatorFlags.DoNotSpecialize */) !== 0) {
|
3094
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeAnnotationVariable(), node);
|
3095
|
-
type = types_1.UnknownType.create();
|
3096
|
-
}
|
3097
|
-
}
|
3098
|
-
}
|
3073
|
+
// Report inappropriate use of variables in type expressions.
|
3074
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
3075
|
+
type = validateSymbolIsTypeExpression(node, type, !!effectiveTypeInfo.includesVariableDecl);
|
3099
3076
|
}
|
3100
3077
|
}
|
3101
3078
|
else {
|
@@ -3109,17 +3086,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3109
3086
|
}
|
3110
3087
|
}
|
3111
3088
|
if ((0, types_1.isParamSpec)(type)) {
|
3112
|
-
if (flags & 32 /*
|
3089
|
+
if (flags & 32 /* EvalFlags.NoParamSpec */) {
|
3113
3090
|
addError(localize_1.LocMessage.paramSpecContext(), node);
|
3114
3091
|
type = types_1.UnknownType.create();
|
3115
3092
|
}
|
3116
3093
|
}
|
3117
|
-
type =
|
3118
|
-
if ((flags & 256 /*
|
3094
|
+
type = convertSpecialFormToRuntimeValue(type, flags);
|
3095
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) === 0) {
|
3119
3096
|
reportUseOfTypeCheckOnly(type, node);
|
3120
3097
|
}
|
3121
|
-
if ((flags & 128 /*
|
3122
|
-
if ((flags & 1024 /*
|
3098
|
+
if ((flags & 128 /* EvalFlags.InstantiableType */) !== 0) {
|
3099
|
+
if ((flags & 1024 /* EvalFlags.AllowGeneric */) === 0) {
|
3123
3100
|
if ((0, types_1.isInstantiableClass)(type) && types_1.ClassType.isBuiltIn(type, 'Generic')) {
|
3124
3101
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.genericNotAllowed(), node);
|
3125
3102
|
}
|
@@ -3130,26 +3107,45 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3130
3107
|
}
|
3131
3108
|
return { type, isIncomplete };
|
3132
3109
|
}
|
3133
|
-
//
|
3134
|
-
|
3135
|
-
|
3136
|
-
|
3137
|
-
if (!type.specialForm || type.typeAliasInfo) {
|
3110
|
+
// Reports diagnostics if type isn't valid within a type expression.
|
3111
|
+
function validateSymbolIsTypeExpression(node, type, includesVariableDecl) {
|
3112
|
+
// Verify that the name does not refer to a (non type alias) variable.
|
3113
|
+
if (!includesVariableDecl || type.typeAliasInfo) {
|
3138
3114
|
return type;
|
3139
3115
|
}
|
3140
|
-
if (
|
3116
|
+
if ((0, types_1.isTypeVar)(type) || (0, typeUtils_1.isTypeAliasPlaceholder)(type)) {
|
3141
3117
|
return type;
|
3142
3118
|
}
|
3143
|
-
|
3144
|
-
|
3119
|
+
// Exempts class types that are created by calling
|
3120
|
+
// NewType, NamedTuple, etc.
|
3121
|
+
if ((0, types_1.isClass)(type) && !type.includeSubclasses && types_1.ClassType.isValidTypeAliasClass(type)) {
|
3122
|
+
return type;
|
3145
3123
|
}
|
3146
|
-
//
|
3147
|
-
|
3148
|
-
|
3149
|
-
|
3150
|
-
return types_1.TypeBase.cloneAsSpecialForm(type, undefined);
|
3124
|
+
// Disable for assignments in the typings.pyi file, since it defines special forms.
|
3125
|
+
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
3126
|
+
if (fileInfo.isTypingStubFile) {
|
3127
|
+
return type;
|
3151
3128
|
}
|
3152
|
-
|
3129
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeAnnotationVariable(), node);
|
3130
|
+
return types_1.UnknownType.create();
|
3131
|
+
}
|
3132
|
+
// If the value is a special form (like a TypeVar or `Any`) and is being
|
3133
|
+
// evaluated in a value expression context, convert it from its special
|
3134
|
+
// meaning to its runtime value.
|
3135
|
+
function convertSpecialFormToRuntimeValue(type, flags) {
|
3136
|
+
var _a;
|
3137
|
+
const exemptFlags = 256 /* EvalFlags.TypeExpression */ | 128 /* EvalFlags.InstantiableType */ | 33554432 /* EvalFlags.NoConvertSpecialForm */;
|
3138
|
+
if ((flags & exemptFlags) !== 0) {
|
3139
|
+
return type;
|
3140
|
+
}
|
3141
|
+
// Isinstance treats traditional (non-PEP 695) type aliases that are unions
|
3142
|
+
// as tuples of classes rather than unions.
|
3143
|
+
if ((flags & 536870912 /* EvalFlags.IsinstanceParam */) !== 0) {
|
3144
|
+
if ((0, types_1.isUnion)(type) && type.typeAliasInfo && !type.typeAliasInfo.isPep695Syntax) {
|
3145
|
+
return type;
|
3146
|
+
}
|
3147
|
+
}
|
3148
|
+
return (_a = type.specialForm) !== null && _a !== void 0 ? _a : type;
|
3153
3149
|
}
|
3154
3150
|
// Handles the case where a variable or parameter is defined in an outer
|
3155
3151
|
// scope and captured by an inner scope (a function, lambda, or comprehension).
|
@@ -3235,7 +3231,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3235
3231
|
if (types_1.TypeBase.isInstantiable(type) && !type.scopeId && !(0, typeUtils_1.isTypeAliasPlaceholder)(type)) {
|
3236
3232
|
const scopedTypeVarInfo = findScopedTypeVar(node, type);
|
3237
3233
|
type = scopedTypeVarInfo.type;
|
3238
|
-
if ((flags & 2048 /*
|
3234
|
+
if ((flags & 2048 /* EvalFlags.NoTypeVarWithScopeId */) !== 0 && type.scopeId !== undefined) {
|
3239
3235
|
if (!type.details.isSynthesized && !type.details.isParamSpec) {
|
3240
3236
|
// This TypeVar already has a scope ID assigned to it. See if it
|
3241
3237
|
// originates from type parameter syntax. If so, allow it.
|
@@ -3254,7 +3250,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3254
3250
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarUsedByOuterScope().format({ name: type.details.name }), node);
|
3255
3251
|
}
|
3256
3252
|
}
|
3257
|
-
else if ((flags & 8192 /*
|
3253
|
+
else if ((flags & 8192 /* EvalFlags.TypeVarGetsCurScope */) !== 0) {
|
3258
3254
|
if (type.scopeId === undefined) {
|
3259
3255
|
if (!scopedTypeVarInfo.foundInterveningClass) {
|
3260
3256
|
let enclosingScope = ParseTreeUtils.getEnclosingClassOrFunction(node);
|
@@ -3298,7 +3294,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3298
3294
|
}
|
3299
3295
|
}
|
3300
3296
|
}
|
3301
|
-
else if ((flags & 4096 /*
|
3297
|
+
else if ((flags & 4096 /* EvalFlags.AllowTypeVarWithoutScopeId */) === 0) {
|
3302
3298
|
if ((type.scopeId === undefined || scopedTypeVarInfo.foundInterveningClass) &&
|
3303
3299
|
!type.details.isSynthesized) {
|
3304
3300
|
const message = (0, types_1.isParamSpec)(type)
|
@@ -3320,13 +3316,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3320
3316
|
// and optionally reports an error.
|
3321
3317
|
function reportMissingTypeArguments(node, type, flags) {
|
3322
3318
|
var _a;
|
3323
|
-
if ((flags & 2 /*
|
3319
|
+
if ((flags & 2 /* EvalFlags.NoSpecialize */) !== 0) {
|
3324
3320
|
return type;
|
3325
3321
|
}
|
3326
3322
|
// Is this a generic class that needs to be specialized?
|
3327
3323
|
if ((0, types_1.isInstantiableClass)(type)) {
|
3328
|
-
if ((flags & 128 /*
|
3329
|
-
(flags & 512 /* EvaluatorFlags.AllowMissingTypeArgs */) === 0) {
|
3324
|
+
if ((flags & 128 /* EvalFlags.InstantiableType */) !== 0 && (flags & 512 /* EvalFlags.AllowMissingTypeArgs */) === 0) {
|
3330
3325
|
if (!type.typeAliasInfo && (0, typeUtils_1.requiresTypeArguments)(type)) {
|
3331
3326
|
if (!type.typeArguments || !type.isTypeArgumentExplicit) {
|
3332
3327
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportMissingTypeArgument, localize_1.LocMessage.typeArgsMissingForClass().format({
|
@@ -3340,7 +3335,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3340
3335
|
}
|
3341
3336
|
}
|
3342
3337
|
// Is this a generic type alias that needs to be specialized?
|
3343
|
-
if ((flags & 128 /*
|
3338
|
+
if ((flags & 128 /* EvalFlags.InstantiableType */) !== 0 &&
|
3344
3339
|
type.typeAliasInfo &&
|
3345
3340
|
type.typeAliasInfo.typeParameters &&
|
3346
3341
|
type.typeAliasInfo.typeParameters.length > 0 &&
|
@@ -3354,7 +3349,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3354
3349
|
}
|
3355
3350
|
let defaultType;
|
3356
3351
|
if (param.details.isDefaultExplicit || param.details.isParamSpec) {
|
3357
|
-
defaultType = (0, typeUtils_1.applySolvedTypeVars)(param, typeVarContext, {
|
3352
|
+
defaultType = (0, typeUtils_1.applySolvedTypeVars)(param, typeVarContext, {
|
3353
|
+
unknownIfNotFound: true,
|
3354
|
+
tupleClassType: getTupleClassType(),
|
3355
|
+
});
|
3358
3356
|
}
|
3359
3357
|
else if (param.details.isVariadic && tupleClass && (0, types_1.isInstantiableClass)(tupleClass)) {
|
3360
3358
|
defaultType = makeTupleObject([{ type: types_1.UnknownType.create(), isUnbounded: true }],
|
@@ -3371,7 +3369,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3371
3369
|
name: type.typeAliasInfo.name,
|
3372
3370
|
}), node);
|
3373
3371
|
}
|
3374
|
-
type = types_1.TypeBase.cloneForTypeAlias((0, typeUtils_1.applySolvedTypeVars)(type, typeVarContext, {
|
3372
|
+
type = types_1.TypeBase.cloneForTypeAlias((0, typeUtils_1.applySolvedTypeVars)(type, typeVarContext, {
|
3373
|
+
unknownIfNotFound: true,
|
3374
|
+
tupleClassType: getTupleClassType(),
|
3375
|
+
}), type.typeAliasInfo.name, type.typeAliasInfo.fullName, type.typeAliasInfo.moduleName, type.typeAliasInfo.fileUri, type.typeAliasInfo.typeVarScopeId, type.typeAliasInfo.isPep695Syntax, type.typeAliasInfo.typeParameters, defaultTypeArgs);
|
3375
3376
|
}
|
3376
3377
|
return type;
|
3377
3378
|
}
|
@@ -3426,11 +3427,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3426
3427
|
let leftType;
|
3427
3428
|
let typeAliasNode = undefined;
|
3428
3429
|
if (curNode.nodeType === 77 /* ParseNodeType.TypeAlias */) {
|
3429
|
-
leftType = readTypeCache(curNode.name, 0 /*
|
3430
|
+
leftType = readTypeCache(curNode.name, 0 /* EvalFlags.None */);
|
3430
3431
|
typeAliasNode = curNode;
|
3431
3432
|
}
|
3432
3433
|
else if (curNode.nodeType === 3 /* ParseNodeType.Assignment */) {
|
3433
|
-
leftType = readTypeCache(curNode.leftExpression, 0 /*
|
3434
|
+
leftType = readTypeCache(curNode.leftExpression, 0 /* EvalFlags.None */);
|
3434
3435
|
}
|
3435
3436
|
if (leftType) {
|
3436
3437
|
// Is this a placeholder that was temporarily written to the cache for
|
@@ -3472,20 +3473,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3472
3473
|
function getTypeOfMemberAccess(node, flags) {
|
3473
3474
|
var _a;
|
3474
3475
|
// Compute flags specifically for evaluating the left expression.
|
3475
|
-
let leftExprFlags = 2 /*
|
3476
|
+
let leftExprFlags = 2 /* EvalFlags.MemberAccessBaseDefaults */;
|
3476
3477
|
leftExprFlags |=
|
3477
3478
|
flags &
|
3478
|
-
(256 /*
|
3479
|
-
32768 /*
|
3480
|
-
4 /*
|
3481
|
-
524288 /*
|
3482
|
-
2048 /*
|
3483
|
-
8192 /*
|
3479
|
+
(256 /* EvalFlags.TypeExpression */ |
|
3480
|
+
32768 /* EvalFlags.VarTypeAnnotation */ |
|
3481
|
+
4 /* EvalFlags.ForwardRefs */ |
|
3482
|
+
524288 /* EvalFlags.NotParsed */ |
|
3483
|
+
2048 /* EvalFlags.NoTypeVarWithScopeId */ |
|
3484
|
+
8192 /* EvalFlags.TypeVarGetsCurScope */);
|
3484
3485
|
// Handle special casing for ParamSpec "args" and "kwargs" accesses.
|
3485
|
-
if ((flags & 128 /*
|
3486
|
+
if ((flags & 128 /* EvalFlags.InstantiableType */) !== 0) {
|
3486
3487
|
const memberName = node.memberName.value;
|
3487
3488
|
if (memberName === 'args' || memberName === 'kwargs') {
|
3488
|
-
leftExprFlags |= 33554432 /*
|
3489
|
+
leftExprFlags |= 33554432 /* EvalFlags.NoConvertSpecialForm */;
|
3489
3490
|
}
|
3490
3491
|
}
|
3491
3492
|
const baseTypeResult = getTypeOfExpression(node.leftExpression, leftExprFlags);
|
@@ -3495,7 +3496,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3495
3496
|
isIncomplete: true,
|
3496
3497
|
};
|
3497
3498
|
}
|
3498
|
-
const typeResult = getTypeOfMemberAccessWithBaseType(node, baseTypeResult, { method: 'get' }, flags | 2 /*
|
3499
|
+
const typeResult = getTypeOfMemberAccessWithBaseType(node, baseTypeResult, { method: 'get' }, flags | 2 /* EvalFlags.NoSpecialize */);
|
3499
3500
|
if ((0, codeFlowTypes_1.isCodeFlowSupportedForReference)(node)) {
|
3500
3501
|
// Before performing code flow analysis, update the cache to prevent recursion.
|
3501
3502
|
writeTypeCache(node, { ...typeResult, isIncomplete: true }, flags);
|
@@ -3522,7 +3523,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3522
3523
|
const codeFlowTypeResult = getFlowTypeOfReference(node, /* startNode */ undefined, {
|
3523
3524
|
targetSymbolId: symbol_1.indeterminateSymbolId,
|
3524
3525
|
typeAtStart: { type: typeAtStart, isIncomplete: isTypeAtStartIncomplete },
|
3525
|
-
skipConditionalNarrowing: (flags & 256 /*
|
3526
|
+
skipConditionalNarrowing: (flags & 256 /* EvalFlags.TypeExpression */) !== 0,
|
3526
3527
|
});
|
3527
3528
|
if (codeFlowTypeResult.type) {
|
3528
3529
|
typeResult.type = codeFlowTypeResult.type;
|
@@ -3577,7 +3578,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3577
3578
|
if (baseTypeResult.isIncomplete && (0, types_1.isUnbound)(baseType)) {
|
3578
3579
|
return { type: types_1.UnknownType.create(/* isIncomplete */ true), isIncomplete: true };
|
3579
3580
|
}
|
3580
|
-
if (baseType.specialForm) {
|
3581
|
+
if (baseType.specialForm && (flags & 256 /* EvalFlags.TypeExpression */) === 0) {
|
3581
3582
|
baseType = baseType.specialForm;
|
3582
3583
|
}
|
3583
3584
|
if ((0, types_1.isParamSpec)(baseType) && baseType.paramSpecAccess) {
|
@@ -3618,7 +3619,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3618
3619
|
break;
|
3619
3620
|
}
|
3620
3621
|
// It's illegal to reference a member from a type variable.
|
3621
|
-
if ((flags & 256 /*
|
3622
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
3622
3623
|
if (!isIncomplete) {
|
3623
3624
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarNoMember().format({
|
3624
3625
|
type: printType(baseType),
|
@@ -3640,7 +3641,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3640
3641
|
type: makeTopLevelTypeVarsConcrete(baseType),
|
3641
3642
|
bindToSelfType: types_1.TypeBase.isInstantiable(baseType) ? (0, typeUtils_1.convertToInstance)(baseType) : baseType,
|
3642
3643
|
isIncomplete,
|
3643
|
-
}, usage, 0 /*
|
3644
|
+
}, usage, 0 /* EvalFlags.None */);
|
3644
3645
|
}
|
3645
3646
|
case 6 /* TypeCategory.Class */: {
|
3646
3647
|
let typeResult;
|
@@ -3660,8 +3661,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3660
3661
|
}
|
3661
3662
|
}
|
3662
3663
|
if (!typeResult) {
|
3663
|
-
typeResult = getTypeOfBoundMember(node.memberName, baseType, memberName, usage, diag,
|
3664
|
-
/* memberAccessFlags */ undefined, baseTypeResult.bindToSelfType);
|
3664
|
+
typeResult = getTypeOfBoundMember(node.memberName, baseType, memberName, usage, diag, (flags & 256 /* EvalFlags.TypeExpression */) === 0 ? undefined : 2048 /* MemberAccessFlags.TypeExpression */, baseTypeResult.bindToSelfType);
|
3665
3665
|
}
|
3666
3666
|
if (typeResult) {
|
3667
3667
|
if (!typeResult.typeErrors) {
|
@@ -3693,9 +3693,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3693
3693
|
if (usage.method === 'get') {
|
3694
3694
|
setSymbolAccessed(fileInfo, symbol, node.memberName);
|
3695
3695
|
}
|
3696
|
-
|
3696
|
+
const typeResult = getEffectiveTypeOfSymbolForUsage(symbol,
|
3697
3697
|
/* usageNode */ undefined,
|
3698
|
-
/* useLastDecl */ true)
|
3698
|
+
/* useLastDecl */ true);
|
3699
|
+
type = typeResult.type;
|
3700
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
3701
|
+
type = validateSymbolIsTypeExpression(node, type, !!typeResult.includesVariableDecl);
|
3702
|
+
}
|
3699
3703
|
if ((0, types_1.isTypeVar)(type)) {
|
3700
3704
|
type = validateTypeVarUsage(node, type, flags);
|
3701
3705
|
}
|
@@ -3778,7 +3782,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3778
3782
|
const typeResult = getTypeOfMemberAccessWithBaseType(node, {
|
3779
3783
|
type: subtype,
|
3780
3784
|
isIncomplete: baseTypeResult.isIncomplete,
|
3781
|
-
}, usage, 0 /*
|
3785
|
+
}, usage, 0 /* EvalFlags.None */);
|
3782
3786
|
if (typeResult.isIncomplete) {
|
3783
3787
|
isIncomplete = true;
|
3784
3788
|
}
|
@@ -3851,9 +3855,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3851
3855
|
// additional reportUnknownMemberType diagnostics.
|
3852
3856
|
type = isFunctionRule ? types_1.AnyType.create() : types_1.UnknownType.create();
|
3853
3857
|
}
|
3854
|
-
if ((flags & 256 /*
|
3858
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) === 0) {
|
3855
3859
|
reportUseOfTypeCheckOnly(type, node.memberName);
|
3856
3860
|
}
|
3861
|
+
type = convertSpecialFormToRuntimeValue(type, flags);
|
3857
3862
|
return {
|
3858
3863
|
type,
|
3859
3864
|
isIncomplete,
|
@@ -4448,22 +4453,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4448
4453
|
isAsymmetricAccessor,
|
4449
4454
|
};
|
4450
4455
|
}
|
4451
|
-
function getTypeOfIndex(node, flags = 0 /*
|
4452
|
-
const baseTypeResult = getTypeOfExpression(node.baseExpression, flags | 2 /*
|
4456
|
+
function getTypeOfIndex(node, flags = 0 /* EvalFlags.None */) {
|
4457
|
+
const baseTypeResult = getTypeOfExpression(node.baseExpression, flags | 2 /* EvalFlags.IndexBaseDefaults */);
|
4453
4458
|
// If this is meant to be a type and the base expression is a string expression,
|
4454
4459
|
// emit an error because this is an illegal annotation form and will generate a
|
4455
4460
|
// runtime exception.
|
4456
|
-
if (flags & 128 /*
|
4461
|
+
if (flags & 128 /* EvalFlags.InstantiableType */) {
|
4457
4462
|
if (node.baseExpression.nodeType === 48 /* ParseNodeType.StringList */) {
|
4458
4463
|
addError(localize_1.LocMessage.stringNotSubscriptable(), node.baseExpression);
|
4459
4464
|
}
|
4460
4465
|
}
|
4461
4466
|
// Check for builtin classes that will generate runtime exceptions if subscripted.
|
4462
|
-
if ((flags & 4 /*
|
4467
|
+
if ((flags & 4 /* EvalFlags.ForwardRefs */) === 0) {
|
4463
4468
|
// We can skip this check if the class is used within a PEP 526 variable
|
4464
4469
|
// type annotation within a class or function. For some undocumented reason,
|
4465
4470
|
// they don't result in runtime exceptions when used in this manner.
|
4466
|
-
let skipSubscriptCheck = (flags & 32768 /*
|
4471
|
+
let skipSubscriptCheck = (flags & 32768 /* EvalFlags.VarTypeAnnotation */) !== 0;
|
4467
4472
|
if (skipSubscriptCheck) {
|
4468
4473
|
const scopeNode = ParseTreeUtils.getExecutionScopeNode(node);
|
4469
4474
|
if ((scopeNode === null || scopeNode === void 0 ? void 0 : scopeNode.nodeType) === 36 /* ParseNodeType.Module */) {
|
@@ -4509,7 +4514,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4509
4514
|
type: indexTypeResult.type,
|
4510
4515
|
isIncomplete: !!baseTypeResult.isIncomplete || !!indexTypeResult.isIncomplete,
|
4511
4516
|
},
|
4512
|
-
skipConditionalNarrowing: (flags & 256 /*
|
4517
|
+
skipConditionalNarrowing: (flags & 256 /* EvalFlags.TypeExpression */) !== 0,
|
4513
4518
|
});
|
4514
4519
|
if (codeFlowTypeResult.type) {
|
4515
4520
|
indexTypeResult.type = codeFlowTypeResult.type;
|
@@ -4772,12 +4777,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4772
4777
|
typeArgType = (0, typeUtils_1.convertToInstance)(typeArgs[index].type);
|
4773
4778
|
}
|
4774
4779
|
else if (param.details.isDefaultExplicit) {
|
4775
|
-
typeArgType = (0, typeUtils_1.applySolvedTypeVars)(param, typeVarContext, {
|
4780
|
+
typeArgType = (0, typeUtils_1.applySolvedTypeVars)(param, typeVarContext, {
|
4781
|
+
unknownIfNotFound: true,
|
4782
|
+
tupleClassType: getTupleClassType(),
|
4783
|
+
});
|
4776
4784
|
}
|
4777
4785
|
else {
|
4778
4786
|
typeArgType = types_1.UnknownType.create();
|
4779
4787
|
}
|
4780
|
-
if ((flags & 16384 /*
|
4788
|
+
if ((flags & 16384 /* EvalFlags.EnforceVarianceConsistency */) !== 0) {
|
4781
4789
|
const usageVariances = inferTypeParameterVarianceForTypeAlias(baseType);
|
4782
4790
|
if (usageVariances && index < usageVariances.length) {
|
4783
4791
|
const usageVariance = usageVariances[index];
|
@@ -4847,9 +4855,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4847
4855
|
var _a;
|
4848
4856
|
const selfType = (0, types_1.isTypeVar)(unexpandedSubtype) ? unexpandedSubtype : undefined;
|
4849
4857
|
if ((0, types_1.isAnyOrUnknown)(concreteSubtype)) {
|
4858
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
4859
|
+
// If we are expecting a type annotation here, assume that
|
4860
|
+
// the subscripts are type arguments and evaluate them
|
4861
|
+
// accordingly.
|
4862
|
+
getTypeArgs(node, flags);
|
4863
|
+
}
|
4850
4864
|
return concreteSubtype;
|
4851
4865
|
}
|
4852
|
-
if (flags & 128 /*
|
4866
|
+
if (flags & 128 /* EvalFlags.InstantiableType */) {
|
4853
4867
|
if ((0, types_1.isTypeVar)(unexpandedSubtype)) {
|
4854
4868
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarNotSubscriptable().format({
|
4855
4869
|
type: printType(unexpandedSubtype),
|
@@ -4864,9 +4878,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4864
4878
|
if (concreteSubtype.details.effectiveMetaclass &&
|
4865
4879
|
(0, types_1.isInstantiableClass)(concreteSubtype.details.effectiveMetaclass) &&
|
4866
4880
|
!types_1.ClassType.isBuiltIn(concreteSubtype.details.effectiveMetaclass, ['type', '_InitVarMeta']) &&
|
4867
|
-
(flags & 128 /*
|
4881
|
+
(flags & 128 /* EvalFlags.InstantiableType */) === 0) {
|
4868
4882
|
const itemMethodType = getBoundMagicMethod(concreteSubtype, getIndexAccessMagicMethodName(usage));
|
4869
|
-
if ((flags & 256 /*
|
4883
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
4870
4884
|
// If the class doesn't derive from Generic, a type argument should not be allowed.
|
4871
4885
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.typeArgsExpectingNone().format({
|
4872
4886
|
name: printType(types_1.ClassType.cloneAsInstance(concreteSubtype)),
|
@@ -4891,8 +4905,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4891
4905
|
if (types_1.ClassType.isBuiltIn(concreteSubtype, 'InitVar')) {
|
4892
4906
|
// Special-case InitVar, used in dataclasses.
|
4893
4907
|
const typeArgs = getTypeArgs(node, flags);
|
4894
|
-
if ((flags & 256 /*
|
4895
|
-
if ((flags & 32768 /*
|
4908
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
4909
|
+
if ((flags & 32768 /* EvalFlags.VarTypeAnnotation */) === 0) {
|
4896
4910
|
addError(localize_1.LocMessage.initVarNotAllowed(), node.baseExpression);
|
4897
4911
|
}
|
4898
4912
|
}
|
@@ -4981,7 +4995,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4981
4995
|
if (!baseTypeResult.isIncomplete) {
|
4982
4996
|
node.items.forEach((item) => {
|
4983
4997
|
if (!isTypeCached(item.valueExpression)) {
|
4984
|
-
getTypeOfExpression(item.valueExpression, flags & 4 /*
|
4998
|
+
getTypeOfExpression(item.valueExpression, flags & 4 /* EvalFlags.ForwardRefs */);
|
4985
4999
|
}
|
4986
5000
|
});
|
4987
5001
|
}
|
@@ -5284,10 +5298,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5284
5298
|
const typeArgs = [];
|
5285
5299
|
let adjFlags = flags;
|
5286
5300
|
if (options === null || options === void 0 ? void 0 : options.isFinalAnnotation) {
|
5287
|
-
adjFlags |= 131072 /*
|
5301
|
+
adjFlags |= 131072 /* EvalFlags.NoClassVar */ | 16 /* EvalFlags.NoFinal */;
|
5288
5302
|
}
|
5289
5303
|
else if (options === null || options === void 0 ? void 0 : options.isClassVarAnnotation) {
|
5290
|
-
adjFlags |= 131072 /*
|
5304
|
+
adjFlags |= 131072 /* EvalFlags.NoClassVar */;
|
5291
5305
|
// If the annotation is a variable within the body of a dataclass, a
|
5292
5306
|
// Final is allowed within the ClassVar annotation. In all other cases,
|
5293
5307
|
// it's disallowed.
|
@@ -5300,19 +5314,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5300
5314
|
}
|
5301
5315
|
}
|
5302
5316
|
if (disallowFinal) {
|
5303
|
-
adjFlags |= 16 /*
|
5317
|
+
adjFlags |= 16 /* EvalFlags.NoFinal */;
|
5304
5318
|
}
|
5305
5319
|
}
|
5306
5320
|
else {
|
5307
|
-
adjFlags &= ~(2 /*
|
5308
|
-
32 /*
|
5309
|
-
64 /*
|
5310
|
-
1048576 /*
|
5311
|
-
16384 /*
|
5321
|
+
adjFlags &= ~(2 /* EvalFlags.NoSpecialize */ |
|
5322
|
+
32 /* EvalFlags.NoParamSpec */ |
|
5323
|
+
64 /* EvalFlags.NoTypeVarTuple */ |
|
5324
|
+
1048576 /* EvalFlags.AllowRequired */ |
|
5325
|
+
16384 /* EvalFlags.EnforceVarianceConsistency */);
|
5312
5326
|
if (!(options === null || options === void 0 ? void 0 : options.isAnnotatedClass)) {
|
5313
|
-
adjFlags |= 131072 /*
|
5327
|
+
adjFlags |= 131072 /* EvalFlags.NoClassVar */ | 16 /* EvalFlags.NoFinal */;
|
5314
5328
|
}
|
5315
|
-
adjFlags |= 2097152 /*
|
5329
|
+
adjFlags |= 2097152 /* EvalFlags.AllowUnpackedTuple */ | 134217728 /* EvalFlags.AllowConcatenate */;
|
5316
5330
|
}
|
5317
5331
|
// Create a local function that validates a single type argument.
|
5318
5332
|
const getTypeArgTypeResult = (expr, argIndex) => {
|
@@ -5321,10 +5335,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5321
5335
|
// treated as types.
|
5322
5336
|
if (options === null || options === void 0 ? void 0 : options.hasCustomClassGetItem) {
|
5323
5337
|
adjFlags =
|
5324
|
-
32 /*
|
5325
|
-
64 /* EvaluatorFlags.DisallowTypeVarTuple */ |
|
5326
|
-
2 /* EvaluatorFlags.DoNotSpecialize */ |
|
5327
|
-
131072 /* EvaluatorFlags.DisallowClassVar */;
|
5338
|
+
32 /* EvalFlags.NoParamSpec */ | 64 /* EvalFlags.NoTypeVarTuple */ | 2 /* EvalFlags.NoSpecialize */ | 131072 /* EvalFlags.NoClassVar */;
|
5328
5339
|
typeResult = {
|
5329
5340
|
...getTypeOfExpression(expr, adjFlags),
|
5330
5341
|
node: expr,
|
@@ -5334,12 +5345,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5334
5345
|
// If it's an Annotated[a, b, c], only the first index should be
|
5335
5346
|
// treated as a type.The others can be regular(non - type) objects.
|
5336
5347
|
adjFlags =
|
5337
|
-
32 /*
|
5338
|
-
64 /* EvaluatorFlags.DisallowTypeVarTuple */ |
|
5339
|
-
2 /* EvaluatorFlags.DoNotSpecialize */ |
|
5340
|
-
131072 /* EvaluatorFlags.DisallowClassVar */;
|
5348
|
+
32 /* EvalFlags.NoParamSpec */ | 64 /* EvalFlags.NoTypeVarTuple */ | 2 /* EvalFlags.NoSpecialize */ | 131072 /* EvalFlags.NoClassVar */;
|
5341
5349
|
if ((0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(AnalyzerNodeInfo.getFileInfo(node))) {
|
5342
|
-
adjFlags |= 4 /*
|
5350
|
+
adjFlags |= 4 /* EvalFlags.ForwardRefs */;
|
5343
5351
|
}
|
5344
5352
|
typeResult = {
|
5345
5353
|
...getTypeOfExpression(expr, adjFlags),
|
@@ -5393,13 +5401,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5393
5401
|
}
|
5394
5402
|
function getTypeArg(node, flags) {
|
5395
5403
|
let typeResult;
|
5396
|
-
let adjustedFlags = flags |
|
5397
|
-
128 /* EvaluatorFlags.ExpectingInstantiableType */ |
|
5398
|
-
1 /* EvaluatorFlags.ConvertEllipsisToAny */ |
|
5399
|
-
8 /* EvaluatorFlags.EvaluateStringLiteralAsType */;
|
5404
|
+
let adjustedFlags = flags | 128 /* EvalFlags.InstantiableType */ | 1 /* EvalFlags.ConvertEllipsisToAny */ | 8 /* EvalFlags.StrLiteralAsType */;
|
5400
5405
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
5401
5406
|
if (fileInfo.isStubFile) {
|
5402
|
-
adjustedFlags |= 4 /*
|
5407
|
+
adjustedFlags |= 4 /* EvalFlags.ForwardRefs */;
|
5403
5408
|
}
|
5404
5409
|
if (node.nodeType === 34 /* ParseNodeType.List */) {
|
5405
5410
|
typeResult = {
|
@@ -5417,7 +5422,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5417
5422
|
if (node.nodeType === 18 /* ParseNodeType.Dictionary */) {
|
5418
5423
|
addError(localize_1.LocMessage.dictInAnnotation(), node);
|
5419
5424
|
}
|
5420
|
-
if ((flags & 131072 /*
|
5425
|
+
if ((flags & 131072 /* EvalFlags.NoClassVar */) !== 0) {
|
5421
5426
|
// "ClassVar" is not allowed as a type argument.
|
5422
5427
|
if ((0, types_1.isClass)(typeResult.type) && types_1.ClassType.isBuiltIn(typeResult.type, 'ClassVar')) {
|
5423
5428
|
addError(localize_1.LocMessage.classVarNotAllowed(), node);
|
@@ -5428,8 +5433,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5428
5433
|
}
|
5429
5434
|
function getTypeOfTuple(node, flags, inferenceContext, signatureTracker) {
|
5430
5435
|
var _a;
|
5431
|
-
if ((flags & 256 /*
|
5432
|
-
((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== 1 /* ParseNodeType.Argument */) {
|
5436
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0 && ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== 1 /* ParseNodeType.Argument */) {
|
5433
5437
|
// This is allowed inside of an index trailer, specifically
|
5434
5438
|
// to support Tuple[()], which is the documented way to annotate
|
5435
5439
|
// a zero-length tuple.
|
@@ -5438,14 +5442,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5438
5442
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.tupleInAnnotation() + diag.getString(), node);
|
5439
5443
|
return { type: types_1.UnknownType.create() };
|
5440
5444
|
}
|
5441
|
-
if ((flags & 128 /*
|
5442
|
-
node.expressions.length === 0 &&
|
5443
|
-
!inferenceContext) {
|
5445
|
+
if ((flags & 128 /* EvalFlags.InstantiableType */) !== 0 && node.expressions.length === 0 && !inferenceContext) {
|
5444
5446
|
return { type: makeTupleObject([]), isEmptyTupleShorthand: true };
|
5445
5447
|
}
|
5446
|
-
flags &= ~(256 /*
|
5447
|
-
8 /* EvaluatorFlags.EvaluateStringLiteralAsType */ |
|
5448
|
-
128 /* EvaluatorFlags.ExpectingInstantiableType */);
|
5448
|
+
flags &= ~(256 /* EvalFlags.TypeExpression */ | 8 /* EvalFlags.StrLiteralAsType */ | 128 /* EvalFlags.InstantiableType */);
|
5449
5449
|
// If the expected type is a union, recursively call for each of the subtypes
|
5450
5450
|
// to find one that matches.
|
5451
5451
|
let effectiveExpectedType = inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType;
|
@@ -5511,7 +5511,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5511
5511
|
}
|
5512
5512
|
else {
|
5513
5513
|
const tupleTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(tupleClass));
|
5514
|
-
if (!(0, constraintSolver_1.
|
5514
|
+
if (!(0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(tupleClass), inferenceContext.expectedType, tupleTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
|
5515
5515
|
return undefined;
|
5516
5516
|
}
|
5517
5517
|
const specializedTuple = (0, typeUtils_1.applySolvedTypeVars)(tupleClass, tupleTypeVarContext);
|
@@ -5523,7 +5523,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5523
5523
|
expectedTypes.push(homogenousType);
|
5524
5524
|
}
|
5525
5525
|
}
|
5526
|
-
const entryTypeResults = node.expressions.map((expr, index) => getTypeOfExpression(expr, flags | 268435456 /*
|
5526
|
+
const entryTypeResults = node.expressions.map((expr, index) => getTypeOfExpression(expr, flags | 268435456 /* EvalFlags.StripTupleLiterals */, (0, typeUtils_1.makeInferenceContext)(index < expectedTypes.length ? expectedTypes[index] : undefined, inferenceContext.isTypeIncomplete), signatureTracker));
|
5527
5527
|
const isIncomplete = entryTypeResults.some((result) => result.isIncomplete);
|
5528
5528
|
const type = makeTupleObject(buildTupleTypesList(entryTypeResults, /* stripLiterals */ false));
|
5529
5529
|
// Copy any expected type diag addenda for precision error reporting.
|
@@ -5539,9 +5539,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5539
5539
|
return { type, expectedTypeDiagAddendum, isIncomplete };
|
5540
5540
|
}
|
5541
5541
|
function getTypeOfTupleInferred(node, flags) {
|
5542
|
-
const entryTypeResults = node.expressions.map((expr) => getTypeOfExpression(expr, flags | 268435456 /*
|
5542
|
+
const entryTypeResults = node.expressions.map((expr) => getTypeOfExpression(expr, flags | 268435456 /* EvalFlags.StripTupleLiterals */));
|
5543
5543
|
const isIncomplete = entryTypeResults.some((result) => result.isIncomplete);
|
5544
|
-
const type = makeTupleObject(buildTupleTypesList(entryTypeResults, (flags & 268435456 /*
|
5544
|
+
const type = makeTupleObject(buildTupleTypesList(entryTypeResults, (flags & 268435456 /* EvalFlags.StripTupleLiterals */) !== 0));
|
5545
5545
|
if (isIncomplete) {
|
5546
5546
|
if ((0, typeUtils_1.getContainerDepth)(type) > maxInferredContainerDepth) {
|
5547
5547
|
return { type: types_1.UnknownType.create() };
|
@@ -5598,7 +5598,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5598
5598
|
// Check for the use of `type(x)` within a type annotation. This isn't
|
5599
5599
|
// allowed, and it's a common mistake, so we want to emit a diagnostic
|
5600
5600
|
// that guides the user to the right solution.
|
5601
|
-
if ((flags & 256 /*
|
5601
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0 &&
|
5602
5602
|
node.leftExpression.nodeType === 38 /* ParseNodeType.Name */ &&
|
5603
5603
|
node.leftExpression.value === 'type') {
|
5604
5604
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
@@ -5610,7 +5610,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5610
5610
|
baseTypeResult = getTypeOfLambdaForCall(node, inferenceContext);
|
5611
5611
|
}
|
5612
5612
|
else {
|
5613
|
-
baseTypeResult = getTypeOfExpression(node.leftExpression, 2 /*
|
5613
|
+
baseTypeResult = getTypeOfExpression(node.leftExpression, 2 /* EvalFlags.CallBaseDefaults */ | (flags & 4 /* EvalFlags.ForwardRefs */));
|
5614
5614
|
}
|
5615
5615
|
const argList = ParseTreeUtils.getArgumentsByRuntimeOrder(node).map((arg) => {
|
5616
5616
|
const functionArg = {
|
@@ -5702,7 +5702,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5702
5702
|
});
|
5703
5703
|
}
|
5704
5704
|
}
|
5705
|
-
if ((flags & 256 /*
|
5705
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
5706
5706
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeAnnotationCall(), node);
|
5707
5707
|
typeResult = { type: types_1.UnknownType.create() };
|
5708
5708
|
}
|
@@ -5741,7 +5741,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5741
5741
|
}
|
5742
5742
|
}
|
5743
5743
|
function getLambdaType() {
|
5744
|
-
return getTypeOfExpression(node.leftExpression, 2 /*
|
5744
|
+
return getTypeOfExpression(node.leftExpression, 2 /* EvalFlags.CallBaseDefaults */, (0, typeUtils_1.makeInferenceContext)(expectedType));
|
5745
5745
|
}
|
5746
5746
|
// If one or more of the arguments are incomplete, use speculative mode
|
5747
5747
|
// for the lambda evaluation because it may need to be reevaluated once
|
@@ -5751,7 +5751,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5751
5751
|
: getLambdaType();
|
5752
5752
|
// If bidirectional type inference failed, use normal type inference instead.
|
5753
5753
|
if (typeResult.typeErrors) {
|
5754
|
-
typeResult = getTypeOfExpression(node.leftExpression, 2 /*
|
5754
|
+
typeResult = getTypeOfExpression(node.leftExpression, 2 /* EvalFlags.CallBaseDefaults */);
|
5755
5755
|
}
|
5756
5756
|
return typeResult;
|
5757
5757
|
}
|
@@ -5904,7 +5904,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5904
5904
|
/* isInClass */ true);
|
5905
5905
|
if (((functionInfo === null || functionInfo === void 0 ? void 0 : functionInfo.flags) & 4 /* FunctionTypeFlags.StaticMethod */) !== 0) {
|
5906
5906
|
addError(localize_1.LocMessage.superCallZeroArgFormStaticMethod(), node.leftExpression);
|
5907
|
-
targetClassType = types_1.UnknownType.create();
|
5908
5907
|
}
|
5909
5908
|
}
|
5910
5909
|
}
|
@@ -5913,6 +5912,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5913
5912
|
targetClassType = types_1.UnknownType.create();
|
5914
5913
|
}
|
5915
5914
|
}
|
5915
|
+
const concreteTargetClassType = makeTopLevelTypeVarsConcrete(targetClassType);
|
5916
5916
|
// Determine whether to further narrow the type.
|
5917
5917
|
let bindToType;
|
5918
5918
|
if (node.arguments.length > 1) {
|
@@ -5922,8 +5922,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5922
5922
|
// Ignore unknown or any types.
|
5923
5923
|
}
|
5924
5924
|
else if ((0, types_1.isClassInstance)(secondArgType)) {
|
5925
|
-
if ((0, types_1.isInstantiableClass)(
|
5926
|
-
if (!(0, typeUtils_1.derivesFromClassRecursive)(types_1.ClassType.cloneAsInstantiable(secondArgType),
|
5925
|
+
if ((0, types_1.isInstantiableClass)(concreteTargetClassType)) {
|
5926
|
+
if (!(0, typeUtils_1.derivesFromClassRecursive)(types_1.ClassType.cloneAsInstantiable(secondArgType), concreteTargetClassType,
|
5927
5927
|
/* ignoreUnknown */ true)) {
|
5928
5928
|
reportError = true;
|
5929
5929
|
}
|
@@ -5931,9 +5931,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5931
5931
|
bindToType = secondArgType;
|
5932
5932
|
}
|
5933
5933
|
else if ((0, types_1.isInstantiableClass)(secondArgType)) {
|
5934
|
-
if ((0, types_1.isInstantiableClass)(
|
5935
|
-
if (!types_1.ClassType.isBuiltIn(
|
5936
|
-
!(0, typeUtils_1.derivesFromClassRecursive)(secondArgType,
|
5934
|
+
if ((0, types_1.isInstantiableClass)(concreteTargetClassType)) {
|
5935
|
+
if (!types_1.ClassType.isBuiltIn(concreteTargetClassType, 'type') &&
|
5936
|
+
!(0, typeUtils_1.derivesFromClassRecursive)(secondArgType, concreteTargetClassType, /* ignoreUnknown */ true)) {
|
5937
5937
|
reportError = true;
|
5938
5938
|
}
|
5939
5939
|
}
|
@@ -5999,7 +5999,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5999
5999
|
const parentNode = node.parent;
|
6000
6000
|
if ((parentNode === null || parentNode === void 0 ? void 0 : parentNode.nodeType) === 35 /* ParseNodeType.MemberAccess */) {
|
6001
6001
|
const memberName = parentNode.memberName.value;
|
6002
|
-
let effectiveTargetClass = (0, types_1.isClass)(
|
6002
|
+
let effectiveTargetClass = (0, types_1.isClass)(concreteTargetClassType) ? concreteTargetClassType : undefined;
|
6003
6003
|
// If the bind-to type is a protocol, don't use the effective target class.
|
6004
6004
|
// This pattern is used for mixins, where the mixin type is a protocol class
|
6005
6005
|
// that is used to decorate the "self" or "cls" parameter.
|
@@ -6040,7 +6040,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6040
6040
|
};
|
6041
6041
|
}
|
6042
6042
|
// Handle the super() call when used outside of a member access expression.
|
6043
|
-
if ((0, types_1.isInstantiableClass)(
|
6043
|
+
if ((0, types_1.isInstantiableClass)(concreteTargetClassType)) {
|
6044
6044
|
// We don't know which member is going to be accessed, so we cannot
|
6045
6045
|
// deterministically determine the correct type in this case. We'll
|
6046
6046
|
// use a heuristic that produces the "correct" (desired) behavior in
|
@@ -6049,13 +6049,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6049
6049
|
// class.
|
6050
6050
|
if (bindToType) {
|
6051
6051
|
let nextBaseClassType;
|
6052
|
-
if (types_1.ClassType.isSameGenericClass(bindToType,
|
6052
|
+
if (types_1.ClassType.isSameGenericClass(bindToType, concreteTargetClassType)) {
|
6053
6053
|
if (bindToType.details.baseClasses.length > 0) {
|
6054
6054
|
nextBaseClassType = bindToType.details.baseClasses[0];
|
6055
6055
|
}
|
6056
6056
|
}
|
6057
6057
|
else {
|
6058
|
-
const baseClassIndex = bindToType.details.baseClasses.findIndex((baseClass) => (0, types_1.isClass)(baseClass) &&
|
6058
|
+
const baseClassIndex = bindToType.details.baseClasses.findIndex((baseClass) => (0, types_1.isClass)(baseClass) &&
|
6059
|
+
types_1.ClassType.isSameGenericClass(baseClass, concreteTargetClassType));
|
6059
6060
|
if (baseClassIndex >= 0 && baseClassIndex < bindToType.details.baseClasses.length - 1) {
|
6060
6061
|
nextBaseClassType = bindToType.details.baseClasses[baseClassIndex + 1];
|
6061
6062
|
}
|
@@ -6076,10 +6077,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6076
6077
|
else {
|
6077
6078
|
// If the class derives from one or more unknown classes,
|
6078
6079
|
// return unknown here to prevent spurious errors.
|
6079
|
-
if (
|
6080
|
+
if (concreteTargetClassType.details.mro.some((mroBase) => (0, types_1.isAnyOrUnknown)(mroBase))) {
|
6080
6081
|
return { type: types_1.UnknownType.create() };
|
6081
6082
|
}
|
6082
|
-
const baseClasses =
|
6083
|
+
const baseClasses = concreteTargetClassType.details.baseClasses;
|
6083
6084
|
if (baseClasses.length > 0) {
|
6084
6085
|
const baseClassType = baseClasses[0];
|
6085
6086
|
if ((0, types_1.isInstantiableClass)(baseClassType)) {
|
@@ -7655,21 +7656,29 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7655
7656
|
}
|
7656
7657
|
else if (paramDetails.kwargsIndex !== undefined) {
|
7657
7658
|
const paramType = paramDetails.params[paramDetails.kwargsIndex].type;
|
7658
|
-
|
7659
|
-
|
7660
|
-
|
7661
|
-
|
7662
|
-
|
7663
|
-
|
7664
|
-
|
7665
|
-
|
7666
|
-
|
7667
|
-
|
7668
|
-
|
7669
|
-
|
7670
|
-
|
7671
|
-
|
7672
|
-
|
7659
|
+
if ((0, types_1.isParamSpec)(paramType)) {
|
7660
|
+
if (!canSkipDiagnosticForNode(errorNode) && !isTypeIncomplete) {
|
7661
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.paramNameMissing().format({ name: paramName.value }), paramName);
|
7662
|
+
}
|
7663
|
+
reportedArgError = true;
|
7664
|
+
}
|
7665
|
+
else {
|
7666
|
+
validateArgTypeParams.push({
|
7667
|
+
paramCategory: 2 /* ParameterCategory.KwargsDict */,
|
7668
|
+
paramType,
|
7669
|
+
requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(paramType),
|
7670
|
+
argument: argList[argIndex],
|
7671
|
+
errorNode: (_j = argList[argIndex].valueExpression) !== null && _j !== void 0 ? _j : errorNode,
|
7672
|
+
paramName: paramNameValue,
|
7673
|
+
});
|
7674
|
+
// Remember that this parameter has already received a value.
|
7675
|
+
paramMap.set(paramNameValue, {
|
7676
|
+
argsNeeded: 1,
|
7677
|
+
argsReceived: 1,
|
7678
|
+
isPositionalOnly: false,
|
7679
|
+
});
|
7680
|
+
(0, debug_1.assert)(paramDetails.params[paramDetails.kwargsIndex], 'paramDetails.kwargsIndex params entry is undefined');
|
7681
|
+
}
|
7673
7682
|
trySetActive(argList[argIndex], paramDetails.params[paramDetails.kwargsIndex].param);
|
7674
7683
|
}
|
7675
7684
|
else {
|
@@ -7972,12 +7981,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7972
7981
|
}
|
7973
7982
|
if ((0, types_1.isClassInstance)(effectiveExpectedType) && !(0, types_1.isTypeSame)(effectiveReturnType, effectiveExpectedType)) {
|
7974
7983
|
const tempTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(effectiveReturnType));
|
7975
|
-
if ((0, constraintSolver_1.
|
7984
|
+
if ((0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, effectiveReturnType, effectiveExpectedType, tempTypeVarContext, liveTypeVarScopes, errorNode.start)) {
|
7976
7985
|
const genericReturnType = types_1.ClassType.cloneForSpecialization(effectiveReturnType,
|
7977
7986
|
/* typeArguments */ undefined,
|
7978
7987
|
/* isTypeArgumentExplicit */ false);
|
7979
7988
|
effectiveExpectedType = (0, typeUtils_1.applySolvedTypeVars)(genericReturnType, tempTypeVarContext, {
|
7980
7989
|
unknownIfNotFound: true,
|
7990
|
+
tupleClassType: getTupleClassType(),
|
7981
7991
|
});
|
7982
7992
|
effectiveFlags |= 4096 /* AssignTypeFlags.SkipPopulateUnknownExpectedType */;
|
7983
7993
|
}
|
@@ -8195,6 +8205,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8195
8205
|
const unknownIfNotFound = !ParseTreeUtils.getTypeVarScopesForNode(errorNode).some((typeVarScope) => typeVarContext.hasSolveForScope(typeVarScope));
|
8196
8206
|
let specializedReturnType = (0, typeUtils_1.applySolvedTypeVars)(returnType, typeVarContext, {
|
8197
8207
|
unknownIfNotFound,
|
8208
|
+
tupleClassType: getTupleClassType(),
|
8198
8209
|
unknownExemptTypeVars: getUnknownExemptTypeVarsForReturnType(type, returnType),
|
8199
8210
|
eliminateUnsolvedInUnions,
|
8200
8211
|
applyInScopePlaceholders: true,
|
@@ -8476,13 +8487,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8476
8487
|
}
|
8477
8488
|
else {
|
8478
8489
|
const flags = argParam.isinstanceParam
|
8479
|
-
? 512 /*
|
8480
|
-
8 /*
|
8481
|
-
32 /*
|
8482
|
-
64 /*
|
8483
|
-
16 /*
|
8484
|
-
2 /*
|
8485
|
-
|
8490
|
+
? 512 /* EvalFlags.AllowMissingTypeArgs */ |
|
8491
|
+
8 /* EvalFlags.StrLiteralAsType */ |
|
8492
|
+
32 /* EvalFlags.NoParamSpec */ |
|
8493
|
+
64 /* EvalFlags.NoTypeVarTuple */ |
|
8494
|
+
16 /* EvalFlags.NoFinal */ |
|
8495
|
+
2 /* EvalFlags.NoSpecialize */ |
|
8496
|
+
536870912 /* EvalFlags.IsinstanceParam */
|
8497
|
+
: 16 /* EvalFlags.NoFinal */ | 2 /* EvalFlags.NoSpecialize */;
|
8486
8498
|
const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType, !!(typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete)), signatureTracker);
|
8487
8499
|
argType = exprTypeResult.type;
|
8488
8500
|
// If the type includes multiple instances of a generic function
|
@@ -8509,7 +8521,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8509
8521
|
expectedTypeDiag = exprTypeResult.expectedTypeDiagAddendum;
|
8510
8522
|
}
|
8511
8523
|
if (argParam.argument && argParam.argument.name && !isSpeculativeModeInUse(argParam.errorNode)) {
|
8512
|
-
writeTypeCache(argParam.argument.name, { type: expectedType !== null && expectedType !== void 0 ? expectedType : argType, isIncomplete: isTypeIncomplete }, 0 /*
|
8524
|
+
writeTypeCache(argParam.argument.name, { type: expectedType !== null && expectedType !== void 0 ? expectedType : argType, isIncomplete: isTypeIncomplete }, 0 /* EvalFlags.None */);
|
8513
8525
|
}
|
8514
8526
|
}
|
8515
8527
|
else {
|
@@ -8827,6 +8839,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8827
8839
|
const typeVarContext = new typeVarContext_1.TypeVarContext(typeVar.scopeId);
|
8828
8840
|
const concreteDefaultType = makeTopLevelTypeVarsConcrete((0, typeUtils_1.applySolvedTypeVars)(typeVar.details.defaultType, typeVarContext, {
|
8829
8841
|
unknownIfNotFound: true,
|
8842
|
+
tupleClassType: getTupleClassType(),
|
8830
8843
|
}));
|
8831
8844
|
if (typeVar.details.boundType) {
|
8832
8845
|
if (!assignType(typeVar.details.boundType, concreteDefaultType)) {
|
@@ -9075,7 +9088,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9075
9088
|
typeParameters = [];
|
9076
9089
|
let isTypeParamListValid = true;
|
9077
9090
|
typeParamsExpr.expressions.map((expr) => {
|
9078
|
-
let entryType = getTypeOfExpression(expr, 128 /*
|
9091
|
+
let entryType = getTypeOfExpression(expr, 128 /* EvalFlags.InstantiableType */ | 4096 /* EvalFlags.AllowTypeVarWithoutScopeId */).type;
|
9079
9092
|
if ((0, types_1.isTypeVar)(entryType)) {
|
9080
9093
|
if (entryType.scopeId || entryType.isVariadicUnpacked) {
|
9081
9094
|
isTypeParamListValid = false;
|
@@ -9174,9 +9187,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9174
9187
|
else if (baseClass.literalValue !== undefined) {
|
9175
9188
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeLiteral(), argList[1].node || errorNode);
|
9176
9189
|
}
|
9177
|
-
|
9178
|
-
classFlags |= 256 /* ClassTypeFlags.Final */ | 2097152 /* ClassTypeFlags.NewTypeClass */ | 4194304 /* ClassTypeFlags.ValidTypeAliasClass */;
|
9179
|
-
const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri, classFlags, ParseTreeUtils.getTypeSourceId(errorNode),
|
9190
|
+
const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri, 256 /* ClassTypeFlags.Final */ | 2097152 /* ClassTypeFlags.NewTypeClass */ | 4194304 /* ClassTypeFlags.ValidTypeAliasClass */, ParseTreeUtils.getTypeSourceId(errorNode),
|
9180
9191
|
/* declaredMetaclass */ undefined, baseClass.details.effectiveMetaclass);
|
9181
9192
|
classType.details.baseClasses.push(isBaseClassAny ? types_1.AnyType.create() : baseClass);
|
9182
9193
|
(0, typeUtils_1.computeMroLinearization)(classType);
|
@@ -9248,10 +9259,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9248
9259
|
let type;
|
9249
9260
|
if (node.constType === 26 /* KeywordType.None */) {
|
9250
9261
|
if (noneTypeClass) {
|
9251
|
-
type =
|
9252
|
-
(flags & 128 /* EvaluatorFlags.ExpectingInstantiableType */) !== 0
|
9253
|
-
? noneTypeClass
|
9254
|
-
: (0, typeUtils_1.convertToInstance)(noneTypeClass);
|
9262
|
+
type = (flags & 128 /* EvalFlags.InstantiableType */) !== 0 ? noneTypeClass : (0, typeUtils_1.convertToInstance)(noneTypeClass);
|
9255
9263
|
}
|
9256
9264
|
}
|
9257
9265
|
else if (node.constType === 33 /* KeywordType.True */ ||
|
@@ -9344,8 +9352,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9344
9352
|
}
|
9345
9353
|
function getTypeOfDictionary(node, flags, inferenceContext) {
|
9346
9354
|
var _a;
|
9347
|
-
if ((flags & 256 /*
|
9348
|
-
((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== 1 /* ParseNodeType.Argument */) {
|
9355
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0 && ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== 1 /* ParseNodeType.Argument */) {
|
9349
9356
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
9350
9357
|
diag.addMessage(localize_1.LocAddendum.useDictInstead());
|
9351
9358
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.dictInAnnotation() + diag.getString(), node);
|
@@ -9384,7 +9391,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9384
9391
|
return result;
|
9385
9392
|
}
|
9386
9393
|
}
|
9387
|
-
const result = getTypeOfDictionaryInferred(node, flags, /* hasExpectedType */ !!inferenceContext);
|
9394
|
+
const result = getTypeOfDictionaryInferred(node, flags, /* hasExpectedType */ !!(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType));
|
9388
9395
|
return { ...result, expectedTypeDiagAddendum };
|
9389
9396
|
}
|
9390
9397
|
function getTypeOfDictionaryWithContext(node, flags, inferenceContext, expectedDiagAddendum) {
|
@@ -9439,7 +9446,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9439
9446
|
return undefined;
|
9440
9447
|
}
|
9441
9448
|
const dictTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(builtInDict));
|
9442
|
-
if (!(0, constraintSolver_1.
|
9449
|
+
if (!(0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, builtInDict, inferenceContext.expectedType, dictTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
|
9443
9450
|
return undefined;
|
9444
9451
|
}
|
9445
9452
|
const specializedDict = (0, typeUtils_1.applySolvedTypeVars)(types_1.ClassType.cloneAsInstantiable(builtInDict), dictTypeVarContext);
|
@@ -9540,16 +9547,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9540
9547
|
let typeErrors = false;
|
9541
9548
|
// Mask out some of the flags that are not applicable for a dictionary key
|
9542
9549
|
// even if it appears within an inlined TypedDict annotation.
|
9543
|
-
const keyFlags = flags &
|
9544
|
-
~(256 /* EvaluatorFlags.ExpectingTypeAnnotation */ |
|
9545
|
-
8 /* EvaluatorFlags.EvaluateStringLiteralAsType */ |
|
9546
|
-
128 /* EvaluatorFlags.ExpectingInstantiableType */);
|
9550
|
+
const keyFlags = flags & ~(256 /* EvalFlags.TypeExpression */ | 8 /* EvalFlags.StrLiteralAsType */ | 128 /* EvalFlags.InstantiableType */);
|
9547
9551
|
// Infer the key and value types if possible.
|
9548
9552
|
node.entries.forEach((entryNode, index) => {
|
9549
9553
|
var _a, _b, _c;
|
9550
9554
|
let addUnknown = true;
|
9551
9555
|
if (entryNode.nodeType === 20 /* ParseNodeType.DictionaryKeyEntry */) {
|
9552
|
-
const keyTypeResult = getTypeOfExpression(entryNode.keyExpression, keyFlags | 268435456 /*
|
9556
|
+
const keyTypeResult = getTypeOfExpression(entryNode.keyExpression, keyFlags | 268435456 /* EvalFlags.StripTupleLiterals */, (0, typeUtils_1.makeInferenceContext)(expectedKeyType !== null && expectedKeyType !== void 0 ? expectedKeyType : (forceStrictInference ? types_1.NeverType.createNever() : undefined)));
|
9553
9557
|
if (keyTypeResult.isIncomplete) {
|
9554
9558
|
isIncomplete = true;
|
9555
9559
|
}
|
@@ -9572,12 +9576,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9572
9576
|
expectedTypedDictEntries.knownItems.has(keyType.literalValue)) {
|
9573
9577
|
const effectiveValueType = expectedTypedDictEntries.knownItems.get(keyType.literalValue).valueType;
|
9574
9578
|
entryInferenceContext = (0, typeUtils_1.makeInferenceContext)(effectiveValueType);
|
9575
|
-
valueTypeResult = getTypeOfExpression(entryNode.valueExpression, flags | 268435456 /*
|
9579
|
+
valueTypeResult = getTypeOfExpression(entryNode.valueExpression, flags | 268435456 /* EvalFlags.StripTupleLiterals */, entryInferenceContext);
|
9576
9580
|
}
|
9577
9581
|
else {
|
9578
9582
|
const effectiveValueType = expectedValueType !== null && expectedValueType !== void 0 ? expectedValueType : (forceStrictInference ? types_1.NeverType.createNever() : undefined);
|
9579
9583
|
entryInferenceContext = (0, typeUtils_1.makeInferenceContext)(effectiveValueType);
|
9580
|
-
valueTypeResult = getTypeOfExpression(entryNode.valueExpression, flags | 268435456 /*
|
9584
|
+
valueTypeResult = getTypeOfExpression(entryNode.valueExpression, flags | 268435456 /* EvalFlags.StripTupleLiterals */, entryInferenceContext);
|
9581
9585
|
}
|
9582
9586
|
if (entryInferenceContext && !valueTypeResult.typeErrors) {
|
9583
9587
|
const fromExpectedType = inferTypeArgFromExpectedEntryType(entryInferenceContext, [valueTypeResult.type], !isValueTypeInvariant);
|
@@ -9619,7 +9623,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9619
9623
|
}
|
9620
9624
|
}
|
9621
9625
|
const entryInferenceContext = (0, typeUtils_1.makeInferenceContext)(expectedType);
|
9622
|
-
let unexpandedTypeResult = getTypeOfExpression(entryNode.expandExpression, flags | 268435456 /*
|
9626
|
+
let unexpandedTypeResult = getTypeOfExpression(entryNode.expandExpression, flags | 268435456 /* EvalFlags.StripTupleLiterals */, entryInferenceContext);
|
9623
9627
|
if (entryInferenceContext && !unexpandedTypeResult.typeErrors) {
|
9624
9628
|
const fromExpectedType = inferTypeArgFromExpectedEntryType(entryInferenceContext, [unexpandedTypeResult.type], !isValueTypeInvariant);
|
9625
9629
|
if (fromExpectedType) {
|
@@ -9683,7 +9687,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9683
9687
|
}
|
9684
9688
|
}
|
9685
9689
|
else if (entryNode.nodeType === 11 /* ParseNodeType.Comprehension */) {
|
9686
|
-
const dictEntryTypeResult = getElementTypeFromComprehension(entryNode, flags | 268435456 /*
|
9690
|
+
const dictEntryTypeResult = getElementTypeFromComprehension(entryNode, flags | 268435456 /* EvalFlags.StripTupleLiterals */, expectedValueType, expectedKeyType);
|
9687
9691
|
const dictEntryType = dictEntryTypeResult.type;
|
9688
9692
|
if (dictEntryTypeResult.isIncomplete) {
|
9689
9693
|
isIncomplete = true;
|
@@ -9714,16 +9718,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9714
9718
|
}
|
9715
9719
|
function getTypeOfListOrSet(node, flags, inferenceContext) {
|
9716
9720
|
var _a;
|
9717
|
-
if ((flags & 256 /*
|
9721
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0 &&
|
9718
9722
|
node.nodeType === 34 /* ParseNodeType.List */ &&
|
9719
9723
|
((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== 1 /* ParseNodeType.Argument */) {
|
9720
9724
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
9721
9725
|
diag.addMessage(localize_1.LocAddendum.useListInstead());
|
9722
9726
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.listInAnnotation() + diag.getString(), node);
|
9723
9727
|
}
|
9724
|
-
flags &= ~(256 /*
|
9725
|
-
8 /* EvaluatorFlags.EvaluateStringLiteralAsType */ |
|
9726
|
-
128 /* EvaluatorFlags.ExpectingInstantiableType */);
|
9728
|
+
flags &= ~(256 /* EvalFlags.TypeExpression */ | 8 /* EvalFlags.StrLiteralAsType */ | 128 /* EvalFlags.InstantiableType */);
|
9727
9729
|
// If the expected type is a union, recursively call for each of the subtypes
|
9728
9730
|
// to find one that matches.
|
9729
9731
|
let effectiveExpectedType = inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType;
|
@@ -9759,7 +9761,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9759
9761
|
expectedTypeDiagAddendum = result === null || result === void 0 ? void 0 : result.expectedTypeDiagAddendum;
|
9760
9762
|
}
|
9761
9763
|
const typeResult = getTypeOfListOrSetInferred(node, flags,
|
9762
|
-
/* hasExpectedType */ inferenceContext
|
9764
|
+
/* hasExpectedType */ !!(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType));
|
9763
9765
|
return { ...typeResult, expectedTypeDiagAddendum };
|
9764
9766
|
}
|
9765
9767
|
// Attempts to determine the type of a list or set statement based on an expected type.
|
@@ -9779,10 +9781,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9779
9781
|
node.entries.forEach((entry) => {
|
9780
9782
|
let entryTypeResult;
|
9781
9783
|
if (entry.nodeType === 11 /* ParseNodeType.Comprehension */) {
|
9782
|
-
entryTypeResult = getElementTypeFromComprehension(entry, flags | 268435456 /*
|
9784
|
+
entryTypeResult = getElementTypeFromComprehension(entry, flags | 268435456 /* EvalFlags.StripTupleLiterals */, expectedEntryType);
|
9783
9785
|
}
|
9784
9786
|
else {
|
9785
|
-
entryTypeResult = getTypeOfExpression(entry, flags | 268435456 /*
|
9787
|
+
entryTypeResult = getTypeOfExpression(entry, flags | 268435456 /* EvalFlags.StripTupleLiterals */, (0, typeUtils_1.makeInferenceContext)(expectedEntryType));
|
9786
9788
|
}
|
9787
9789
|
entryTypes.push(entryTypeResult.type);
|
9788
9790
|
if (entryTypeResult.isIncomplete) {
|
@@ -9826,7 +9828,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9826
9828
|
return undefined;
|
9827
9829
|
}
|
9828
9830
|
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(expectedClassType));
|
9829
|
-
if (!(0, constraintSolver_1.
|
9831
|
+
if (!(0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(expectedClassType), inferenceContext.expectedType, typeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
|
9830
9832
|
return undefined;
|
9831
9833
|
}
|
9832
9834
|
const specializedListOrSet = (0, typeUtils_1.applySolvedTypeVars)(expectedClassType, typeVarContext);
|
@@ -9846,10 +9848,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9846
9848
|
node.entries.forEach((entry, index) => {
|
9847
9849
|
let entryTypeResult;
|
9848
9850
|
if (entry.nodeType === 11 /* ParseNodeType.Comprehension */ && !entry.isGenerator) {
|
9849
|
-
entryTypeResult = getElementTypeFromComprehension(entry, flags | 268435456 /*
|
9851
|
+
entryTypeResult = getElementTypeFromComprehension(entry, flags | 268435456 /* EvalFlags.StripTupleLiterals */);
|
9850
9852
|
}
|
9851
9853
|
else {
|
9852
|
-
entryTypeResult = getTypeOfExpression(entry, flags | 268435456 /*
|
9854
|
+
entryTypeResult = getTypeOfExpression(entry, flags | 268435456 /* EvalFlags.StripTupleLiterals */);
|
9853
9855
|
}
|
9854
9856
|
if (entryTypeResult.isIncomplete) {
|
9855
9857
|
isIncomplete = true;
|
@@ -9857,7 +9859,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9857
9859
|
if (entryTypeResult.typeErrors) {
|
9858
9860
|
typeErrors = true;
|
9859
9861
|
}
|
9860
|
-
if (index < maxEntriesToUseForInference) {
|
9862
|
+
if (hasExpectedType || index < maxEntriesToUseForInference) {
|
9861
9863
|
entryTypes.push(entryTypeResult.type);
|
9862
9864
|
}
|
9863
9865
|
if (verifyHashable && !entryTypeResult.isIncomplete && !entryTypeResult.typeErrors) {
|
@@ -10045,7 +10047,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10045
10047
|
return (0, cancellationUtils_1.invalidateTypeCacheIfCanceled)(() => {
|
10046
10048
|
// Pre-cache the incomplete function type in case the evaluation of the
|
10047
10049
|
// lambda depends on itself.
|
10048
|
-
writeTypeCache(node, { type: functionType, isIncomplete: true }, 0 /*
|
10050
|
+
writeTypeCache(node, { type: functionType, isIncomplete: true }, 0 /* EvalFlags.None */);
|
10049
10051
|
// We assume for simplicity that the parameter signature of the lambda is
|
10050
10052
|
// the same as the expected type. If this isn't the case, we'll use
|
10051
10053
|
// object for any lambda parameters that don't match. We could make this
|
@@ -10082,11 +10084,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10082
10084
|
paramType = inferParameterTypeFromDefaultValue(param.defaultValue);
|
10083
10085
|
}
|
10084
10086
|
if (param.name) {
|
10085
|
-
writeTypeCache(param.name, { type: transformVariadicParamType(node, param.category, paramType !== null && paramType !== void 0 ? paramType : types_1.UnknownType.create()) }, 0 /*
|
10087
|
+
writeTypeCache(param.name, { type: transformVariadicParamType(node, param.category, paramType !== null && paramType !== void 0 ? paramType : types_1.UnknownType.create()) }, 0 /* EvalFlags.None */);
|
10086
10088
|
}
|
10087
10089
|
if (param.defaultValue) {
|
10088
10090
|
// Evaluate the default value if it's present.
|
10089
|
-
getTypeOfExpression(param.defaultValue, 1 /*
|
10091
|
+
getTypeOfExpression(param.defaultValue, 1 /* EvalFlags.ConvertEllipsisToAny */);
|
10090
10092
|
}
|
10091
10093
|
// Determine whether we need to insert an implied position-only parameter.
|
10092
10094
|
// This is needed when a function's parameters are named using the old-style
|
@@ -10187,7 +10189,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10187
10189
|
}
|
10188
10190
|
const builtInIteratorType = getTypingType(node, isAsync ? 'AsyncGenerator' : 'Generator');
|
10189
10191
|
const expectedEntryType = getExpectedEntryTypeForIterable(node, builtInIteratorType, inferenceContext);
|
10190
|
-
const elementTypeResult = getElementTypeFromComprehension(node, flags | 268435456 /*
|
10192
|
+
const elementTypeResult = getElementTypeFromComprehension(node, flags | 268435456 /* EvalFlags.StripTupleLiterals */, expectedEntryType);
|
10191
10193
|
if (elementTypeResult.isIncomplete) {
|
10192
10194
|
isIncomplete = true;
|
10193
10195
|
}
|
@@ -10504,7 +10506,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10504
10506
|
// If no type arguments are provided, the resulting type
|
10505
10507
|
// depends on whether we're evaluating a type annotation or
|
10506
10508
|
// we're in some other context.
|
10507
|
-
if ((flags & 256 /*
|
10509
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
10508
10510
|
addError(localize_1.LocMessage.optionalExtraArgs(), errorNode);
|
10509
10511
|
return types_1.UnknownType.create();
|
10510
10512
|
}
|
@@ -10518,10 +10520,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10518
10520
|
if (!validateTypeArg(typeArgs[0])) {
|
10519
10521
|
typeArg0Type = types_1.UnknownType.create();
|
10520
10522
|
}
|
10521
|
-
else if (!(0, typeUtils_1.isEffectivelyInstantiable)(typeArg0Type)) {
|
10522
|
-
addExpectedClassDiagnostic(typeArg0Type, typeArgs[0].node);
|
10523
|
-
typeArg0Type = types_1.UnknownType.create();
|
10524
|
-
}
|
10525
10523
|
let optionalType = (0, types_1.combineTypes)([typeArg0Type, noneTypeClass !== null && noneTypeClass !== void 0 ? noneTypeClass : types_1.UnknownType.create()]);
|
10526
10524
|
if (unionTypeClass && (0, types_1.isInstantiableClass)(unionTypeClass)) {
|
10527
10525
|
optionalType = types_1.TypeBase.cloneAsSpecialForm(optionalType, types_1.ClassType.cloneAsInstance(unionTypeClass));
|
@@ -10607,7 +10605,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10607
10605
|
}
|
10608
10606
|
}
|
10609
10607
|
if (!type) {
|
10610
|
-
const exprType = getTypeOfExpression(itemExpr, flags & 4 /*
|
10608
|
+
const exprType = getTypeOfExpression(itemExpr, (flags & 4 /* EvalFlags.ForwardRefs */) | 33554432 /* EvalFlags.NoConvertSpecialForm */ | 256 /* EvalFlags.TypeExpression */);
|
10611
10609
|
// Is this an enum type?
|
10612
10610
|
if ((0, types_1.isClassInstance)(exprType.type) &&
|
10613
10611
|
types_1.ClassType.isEnumClass(exprType.type) &&
|
@@ -10644,7 +10642,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10644
10642
|
// Creates a ClassVar type.
|
10645
10643
|
function createClassVarType(classType, errorNode, typeArgs, flags) {
|
10646
10644
|
var _a;
|
10647
|
-
if (flags & 131072 /*
|
10645
|
+
if (flags & 131072 /* EvalFlags.NoClassVar */) {
|
10648
10646
|
addError(localize_1.LocMessage.classVarNotAllowed(), errorNode);
|
10649
10647
|
return types_1.AnyType.create();
|
10650
10648
|
}
|
@@ -10676,7 +10674,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10676
10674
|
// depends on whether we're evaluating a type annotation or
|
10677
10675
|
// we're in some other context.
|
10678
10676
|
if (!typeArgs) {
|
10679
|
-
if ((flags & 256 /*
|
10677
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
10680
10678
|
addError(localize_1.LocMessage.typeGuardArgCount(), errorNode);
|
10681
10679
|
}
|
10682
10680
|
return classType;
|
@@ -10707,7 +10705,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10707
10705
|
}
|
10708
10706
|
const enclosingClassTypeResult = enclosingClass ? getTypeOfClass(enclosingClass) : undefined;
|
10709
10707
|
if (!enclosingClassTypeResult) {
|
10710
|
-
if ((flags & (256 /*
|
10708
|
+
if ((flags & (256 /* EvalFlags.TypeExpression */ | 128 /* EvalFlags.InstantiableType */)) !== 0) {
|
10711
10709
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.selfTypeContext(), errorNode);
|
10712
10710
|
}
|
10713
10711
|
return types_1.UnknownType.create();
|
@@ -10748,7 +10746,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10748
10746
|
// If no type arguments are provided, the resulting type
|
10749
10747
|
// depends on whether we're evaluating a type annotation or
|
10750
10748
|
// we're in some other context.
|
10751
|
-
if (!typeArgs && (flags & 256 /*
|
10749
|
+
if (!typeArgs && (flags & 256 /* EvalFlags.TypeExpression */) === 0) {
|
10752
10750
|
return { type: classType };
|
10753
10751
|
}
|
10754
10752
|
if (!typeArgs || typeArgs.length !== 1) {
|
@@ -10772,7 +10770,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10772
10770
|
isUsageLegal = true;
|
10773
10771
|
}
|
10774
10772
|
}
|
10775
|
-
if ((flags & 1048576 /*
|
10773
|
+
if ((flags & 1048576 /* EvalFlags.AllowRequired */) !== 0) {
|
10776
10774
|
isUsageLegal = true;
|
10777
10775
|
}
|
10778
10776
|
let isReadOnly = typeArgs[0].isReadOnly;
|
@@ -10807,7 +10805,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10807
10805
|
// If no type arguments are provided, the resulting type
|
10808
10806
|
// depends on whether we're evaluating a type annotation or
|
10809
10807
|
// we're in some other context.
|
10810
|
-
if (!typeArgs && (flags & 256 /*
|
10808
|
+
if (!typeArgs && (flags & 256 /* EvalFlags.TypeExpression */) === 0) {
|
10811
10809
|
return classType;
|
10812
10810
|
}
|
10813
10811
|
if (!typeArgs || typeArgs.length !== 1) {
|
@@ -10818,7 +10816,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10818
10816
|
if ((0, types_1.isUnion)(typeArgType) && typeArgType.subtypes.length === 1) {
|
10819
10817
|
typeArgType = typeArgType.subtypes[0];
|
10820
10818
|
}
|
10821
|
-
if ((flags & 2097152 /*
|
10819
|
+
if ((flags & 2097152 /* EvalFlags.AllowUnpackedTuple */) !== 0) {
|
10822
10820
|
if ((0, types_1.isInstantiableClass)(typeArgType) && !typeArgType.includeSubclasses && (0, typeUtils_1.isTupleClass)(typeArgType)) {
|
10823
10821
|
return types_1.ClassType.cloneForUnpacked(typeArgType);
|
10824
10822
|
}
|
@@ -10828,7 +10826,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10828
10826
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.unpackExpectedTypeVarTuple(), errorNode);
|
10829
10827
|
return types_1.UnknownType.create();
|
10830
10828
|
}
|
10831
|
-
if ((flags &
|
10829
|
+
if ((flags & 4194304 /* EvalFlags.AllowUnpackedTypedDict */) !== 0) {
|
10832
10830
|
if ((0, types_1.isInstantiableClass)(typeArgType) && types_1.ClassType.isTypedDictClass(typeArgType)) {
|
10833
10831
|
return types_1.ClassType.cloneForUnpacked(typeArgType);
|
10834
10832
|
}
|
@@ -10840,7 +10838,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10840
10838
|
}
|
10841
10839
|
// Creates a "Final" type.
|
10842
10840
|
function createFinalType(classType, errorNode, typeArgs, flags) {
|
10843
|
-
if (flags & 16 /*
|
10841
|
+
if (flags & 16 /* EvalFlags.NoFinal */) {
|
10844
10842
|
addError(localize_1.LocMessage.finalContext(), errorNode);
|
10845
10843
|
return classType;
|
10846
10844
|
}
|
@@ -10853,7 +10851,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10853
10851
|
return types_1.TypeBase.cloneAsSpecialForm(typeArgs[0].type, classType);
|
10854
10852
|
}
|
10855
10853
|
function createConcatenateType(classType, errorNode, typeArgs, flags) {
|
10856
|
-
if ((flags & 134217728 /*
|
10854
|
+
if ((flags & 134217728 /* EvalFlags.AllowConcatenate */) === 0) {
|
10857
10855
|
addError(localize_1.LocMessage.concatenateContext(), errorNode);
|
10858
10856
|
return types_1.AnyType.create();
|
10859
10857
|
}
|
@@ -10882,7 +10880,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10882
10880
|
}
|
10883
10881
|
return createSpecialType(classType, typeArgs, /* paramLimit */ undefined, /* allowParamSpec */ true);
|
10884
10882
|
}
|
10885
|
-
function createAnnotatedType(classType, errorNode, typeArgs) {
|
10883
|
+
function createAnnotatedType(classType, errorNode, typeArgs, flags) {
|
10884
|
+
const typeExprFlags = 256 /* EvalFlags.TypeExpression */ | 33554432 /* EvalFlags.NoConvertSpecialForm */;
|
10885
|
+
if ((flags & typeExprFlags) === 0) {
|
10886
|
+
return { type: classType };
|
10887
|
+
}
|
10886
10888
|
if (typeArgs) {
|
10887
10889
|
if (typeArgs.length < 2) {
|
10888
10890
|
addError(localize_1.LocMessage.annotatedTypeArgMissing(), errorNode);
|
@@ -11068,7 +11070,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11068
11070
|
// If no type arguments are provided, the resulting type
|
11069
11071
|
// depends on whether we're evaluating a type annotation or
|
11070
11072
|
// we're in some other context.
|
11071
|
-
if ((flags & 256 /*
|
11073
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
11072
11074
|
addError(localize_1.LocMessage.unionTypeArgCount(), errorNode);
|
11073
11075
|
return types_1.NeverType.createNever();
|
11074
11076
|
}
|
@@ -11082,10 +11084,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11082
11084
|
})) {
|
11083
11085
|
typeArgType = types_1.UnknownType.create();
|
11084
11086
|
}
|
11085
|
-
else if (!(0, typeUtils_1.isEffectivelyInstantiable)(typeArgType)) {
|
11086
|
-
addExpectedClassDiagnostic(typeArgType, typeArg.node);
|
11087
|
-
typeArgType = types_1.UnknownType.create();
|
11088
|
-
}
|
11089
11087
|
// If this is an unpacked tuple, explode out the individual items.
|
11090
11088
|
if ((0, types_1.isUnpackedClass)(typeArg.type) && typeArg.type.tupleTypeArguments) {
|
11091
11089
|
// This is an experimental feature because Unions of unpacked TypeVarTuples are not officially supported.
|
@@ -11136,7 +11134,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11136
11134
|
// If no type arguments are provided, the resulting type
|
11137
11135
|
// depends on whether we're evaluating a type annotation or
|
11138
11136
|
// we're in some other context.
|
11139
|
-
if ((flags & (256 /*
|
11137
|
+
if ((flags & (256 /* EvalFlags.TypeExpression */ | 262144 /* EvalFlags.NoNakedGeneric */)) !== 0) {
|
11140
11138
|
addError(localize_1.LocMessage.genericTypeArgMissing(), errorNode);
|
11141
11139
|
}
|
11142
11140
|
return classType;
|
@@ -11246,6 +11244,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11246
11244
|
if (aliasMapEntry.isSpecialForm) {
|
11247
11245
|
specialClassType.details.flags |= 8388608 /* ClassTypeFlags.SpecialFormClass */;
|
11248
11246
|
}
|
11247
|
+
if (aliasMapEntry.isIllegalInIsinstance) {
|
11248
|
+
specialClassType.details.flags |= 16777216 /* ClassTypeFlags.IllegalIsinstanceClass */;
|
11249
|
+
}
|
11249
11250
|
// Synthesize a single type parameter with the specified variance if
|
11250
11251
|
// specified in the alias map entry.
|
11251
11252
|
if (aliasMapEntry.typeParamVariance !== undefined) {
|
@@ -11321,7 +11322,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11321
11322
|
['TypedDict', { alias: '_TypedDict', module: 'self' }],
|
11322
11323
|
['Union', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11323
11324
|
['Optional', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11324
|
-
['Annotated', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11325
|
+
['Annotated', { alias: '', module: 'builtins', isSpecialForm: true, isIllegalInIsinstance: true }],
|
11325
11326
|
['TypeAlias', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11326
11327
|
['Concatenate', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11327
11328
|
[
|
@@ -11340,7 +11341,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11340
11341
|
]);
|
11341
11342
|
const aliasMapEntry = specialTypes.get(assignedName);
|
11342
11343
|
if (aliasMapEntry) {
|
11343
|
-
const cachedType = readTypeCache(node, 0 /*
|
11344
|
+
const cachedType = readTypeCache(node, 0 /* EvalFlags.None */);
|
11344
11345
|
if (cachedType) {
|
11345
11346
|
(0, debug_1.assert)((0, types_1.isInstantiableClass)(cachedType));
|
11346
11347
|
return cachedType;
|
@@ -11352,7 +11353,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11352
11353
|
specialType.details.baseClasses.push(strClass !== null && strClass !== void 0 ? strClass : types_1.AnyType.create());
|
11353
11354
|
(0, typeUtils_1.computeMroLinearization)(specialType);
|
11354
11355
|
}
|
11355
|
-
writeTypeCache(node, { type: specialType }, 0 /*
|
11356
|
+
writeTypeCache(node, { type: specialType }, 0 /* EvalFlags.None */);
|
11356
11357
|
return specialType;
|
11357
11358
|
}
|
11358
11359
|
return undefined;
|
@@ -11401,30 +11402,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11401
11402
|
if (isTypeCached(node)) {
|
11402
11403
|
return;
|
11403
11404
|
}
|
11404
|
-
let flags = 0 /*
|
11405
|
+
let flags = 0 /* EvalFlags.None */;
|
11405
11406
|
if (fileInfo.isStubFile) {
|
11406
11407
|
// An assignment of ellipsis means "Any" within a type stub file.
|
11407
|
-
flags |= 1 /*
|
11408
|
+
flags |= 1 /* EvalFlags.ConvertEllipsisToAny */;
|
11408
11409
|
}
|
11409
11410
|
if (node.rightExpression.nodeType === 38 /* ParseNodeType.Name */ ||
|
11410
11411
|
node.rightExpression.nodeType === 35 /* ParseNodeType.MemberAccess */) {
|
11411
11412
|
// Don't specialize a generic class on assignment (e.g. "x = list"
|
11412
11413
|
// or "x = collections.OrderedDict") because we may want to later
|
11413
11414
|
// specialize it (e.g. "x[int]").
|
11414
|
-
flags |= 2 /*
|
11415
|
-
}
|
11416
|
-
if (isDeclaredTypeAlias(node.leftExpression)) {
|
11417
|
-
flags |=
|
11418
|
-
128 /* EvaluatorFlags.ExpectingInstantiableType */ |
|
11419
|
-
256 /* EvaluatorFlags.ExpectingTypeAnnotation */ |
|
11420
|
-
8 /* EvaluatorFlags.EvaluateStringLiteralAsType */ |
|
11421
|
-
32 /* EvaluatorFlags.DisallowParamSpec */ |
|
11422
|
-
64 /* EvaluatorFlags.DisallowTypeVarTuple */ |
|
11423
|
-
131072 /* EvaluatorFlags.DisallowClassVar */;
|
11424
|
-
flags &= ~2 /* EvaluatorFlags.DoNotSpecialize */;
|
11415
|
+
flags |= 2 /* EvalFlags.NoSpecialize */;
|
11425
11416
|
}
|
11426
11417
|
// Is this type already cached?
|
11427
|
-
let rightHandType = readTypeCache(node.rightExpression, flags);
|
11418
|
+
let rightHandType = readTypeCache(node.rightExpression, /* flags */ undefined);
|
11428
11419
|
let isIncomplete = false;
|
11429
11420
|
let expectedTypeDiagAddendum;
|
11430
11421
|
if (!rightHandType) {
|
@@ -11433,18 +11424,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11433
11424
|
if (fileInfo.isTypingStubFile || fileInfo.isTypingExtensionsStubFile) {
|
11434
11425
|
rightHandType = handleTypingStubAssignment(node);
|
11435
11426
|
if (rightHandType) {
|
11436
|
-
writeTypeCache(node.rightExpression, { type: rightHandType }, 0 /*
|
11427
|
+
writeTypeCache(node.rightExpression, { type: rightHandType }, 0 /* EvalFlags.None */);
|
11437
11428
|
}
|
11438
11429
|
}
|
11439
11430
|
}
|
11440
11431
|
if (!rightHandType) {
|
11441
11432
|
// Determine whether there is a declared type.
|
11442
|
-
const declaredType = getDeclaredTypeForExpression(node.leftExpression, {
|
11443
|
-
method: 'set',
|
11444
|
-
});
|
11433
|
+
const declaredType = getDeclaredTypeForExpression(node.leftExpression, { method: 'set' });
|
11445
11434
|
let typeAliasNameNode;
|
11435
|
+
let typeAliasPlaceholder;
|
11446
11436
|
let isSpeculativeTypeAlias = false;
|
11447
11437
|
if (isDeclaredTypeAlias(node.leftExpression)) {
|
11438
|
+
flags =
|
11439
|
+
128 /* EvalFlags.InstantiableType */ |
|
11440
|
+
256 /* EvalFlags.TypeExpression */ |
|
11441
|
+
8 /* EvalFlags.StrLiteralAsType */ |
|
11442
|
+
32 /* EvalFlags.NoParamSpec */ |
|
11443
|
+
64 /* EvalFlags.NoTypeVarTuple */ |
|
11444
|
+
131072 /* EvalFlags.NoClassVar */;
|
11448
11445
|
typeAliasNameNode = node.leftExpression.valueExpression;
|
11449
11446
|
if (!isLegalTypeAliasExpressionForm(node.rightExpression)) {
|
11450
11447
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeAliasIllegalExpressionForm(), node.rightExpression);
|
@@ -11455,102 +11452,86 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11455
11452
|
/* honorCodeFlow */ false);
|
11456
11453
|
if (symbolWithScope) {
|
11457
11454
|
const decls = symbolWithScope.symbol.getDeclarations();
|
11458
|
-
if (decls.length === 1
|
11459
|
-
|
11460
|
-
|
11455
|
+
if (decls.length === 1) {
|
11456
|
+
if (isPossibleTypeAliasDeclaration(decls[0])) {
|
11457
|
+
typeAliasNameNode = node.leftExpression;
|
11458
|
+
isSpeculativeTypeAlias = true;
|
11459
|
+
flags |= 33554432 /* EvalFlags.NoConvertSpecialForm */;
|
11460
|
+
}
|
11461
|
+
else if (isPossibleTypeDictFactoryCall(decls[0])) {
|
11462
|
+
// Handle calls to TypedDict factory functions like type
|
11463
|
+
// aliases to support recursive field type definitions.
|
11464
|
+
typeAliasNameNode = node.leftExpression;
|
11465
|
+
}
|
11461
11466
|
}
|
11462
11467
|
}
|
11463
11468
|
}
|
11464
|
-
// Synthesize a type variable that represents the type alias while we're
|
11465
|
-
// evaluating it. This allows us to handle recursive definitions.
|
11466
|
-
let typeAliasTypeVar;
|
11467
11469
|
if (typeAliasNameNode) {
|
11468
|
-
|
11469
|
-
|
11470
|
-
|
11471
|
-
const scopeId = ParseTreeUtils.getScopeIdForNode(typeAliasNameNode);
|
11472
|
-
typeAliasTypeVar.details.recursiveTypeAliasScopeId = scopeId;
|
11473
|
-
typeAliasTypeVar.details.recursiveTypeAliasIsPep695Syntax = false;
|
11474
|
-
typeAliasTypeVar.scopeId = scopeId;
|
11475
|
-
// Write the type back to the type cache. It will be replaced below.
|
11476
|
-
writeTypeCache(node, { type: typeAliasTypeVar }, /* flags */ undefined);
|
11477
|
-
writeTypeCache(node.leftExpression, { type: typeAliasTypeVar }, /* flags */ undefined);
|
11470
|
+
typeAliasPlaceholder = synthesizeTypeAliasPlaceholder(typeAliasNameNode);
|
11471
|
+
writeTypeCache(node, { type: typeAliasPlaceholder }, /* flags */ undefined);
|
11472
|
+
writeTypeCache(node.leftExpression, { type: typeAliasPlaceholder }, /* flags */ undefined);
|
11478
11473
|
if (node.leftExpression.nodeType === 54 /* ParseNodeType.TypeAnnotation */) {
|
11479
|
-
writeTypeCache(node.leftExpression.valueExpression, { type:
|
11474
|
+
writeTypeCache(node.leftExpression.valueExpression, { type: typeAliasPlaceholder },
|
11480
11475
|
/* flags */ undefined);
|
11481
11476
|
}
|
11482
11477
|
}
|
11483
11478
|
const srcTypeResult = getTypeOfExpression(node.rightExpression, flags, (0, typeUtils_1.makeInferenceContext)(declaredType));
|
11484
|
-
|
11479
|
+
rightHandType = srcTypeResult.type;
|
11485
11480
|
expectedTypeDiagAddendum = srcTypeResult.expectedTypeDiagAddendum;
|
11486
11481
|
if (srcTypeResult.isIncomplete) {
|
11487
11482
|
isIncomplete = true;
|
11488
11483
|
}
|
11489
|
-
// If
|
11490
|
-
|
11491
|
-
if (
|
11492
|
-
|
11493
|
-
if ((0, types_1.isClassInstance)(boolType)) {
|
11494
|
-
srcType = types_1.ClassType.cloneWithLiteral(boolType, constExprValue);
|
11495
|
-
}
|
11484
|
+
// If this was a speculative type alias, it becomes a real type alias
|
11485
|
+
// only if the evaluated type is an instantiable type.
|
11486
|
+
if (isSpeculativeTypeAlias && !isLegalImplicitTypeAliasType(rightHandType)) {
|
11487
|
+
typeAliasNameNode = undefined;
|
11496
11488
|
}
|
11497
|
-
// If this is an enum, transform the type as required.
|
11498
|
-
rightHandType = srcType;
|
11499
11489
|
if (typeAliasNameNode) {
|
11500
|
-
|
11501
|
-
//
|
11502
|
-
|
11503
|
-
|
11504
|
-
|
11505
|
-
|
11506
|
-
|
11507
|
-
|
11508
|
-
|
11509
|
-
|
11510
|
-
|
11511
|
-
|
11512
|
-
|
11490
|
+
(0, debug_1.assert)(typeAliasPlaceholder !== undefined);
|
11491
|
+
// If this is a type alias, record its name based on the assignment target.
|
11492
|
+
rightHandType = transformTypeForTypeAlias(rightHandType, typeAliasNameNode, typeAliasNameNode,
|
11493
|
+
/* isPep695Syntax */ false,
|
11494
|
+
/* isPep695TypeVarType */ false);
|
11495
|
+
if ((0, typeUtils_1.isTypeAliasRecursive)(typeAliasPlaceholder, rightHandType)) {
|
11496
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasIsRecursiveDirect().format({
|
11497
|
+
name: typeAliasNameNode.value,
|
11498
|
+
}), node.rightExpression);
|
11499
|
+
rightHandType = types_1.UnknownType.create();
|
11500
|
+
}
|
11501
|
+
// Set the resulting type to the boundType of the original type alias
|
11502
|
+
// to support recursive type aliases.
|
11503
|
+
typeAliasPlaceholder.details.boundType = rightHandType;
|
11504
|
+
// Record the type parameters within the recursive type alias so it
|
11505
|
+
// can be specialized.
|
11506
|
+
typeAliasPlaceholder.details.recursiveTypeParameters = (_a = rightHandType.typeAliasInfo) === null || _a === void 0 ? void 0 : _a.typeParameters;
|
11507
|
+
}
|
11508
|
+
else {
|
11509
|
+
// If the RHS is a constant boolean expression, assign it a literal type.
|
11510
|
+
const constExprValue = (0, staticExpressions_1.evaluateStaticBoolExpression)(node.rightExpression, fileInfo.executionEnvironment, fileInfo.definedConstants);
|
11511
|
+
if (constExprValue !== undefined) {
|
11512
|
+
const boolType = getBuiltInObject(node, 'bool');
|
11513
|
+
if ((0, types_1.isClassInstance)(boolType)) {
|
11514
|
+
rightHandType = types_1.ClassType.cloneWithLiteral(boolType, constExprValue);
|
11513
11515
|
}
|
11514
|
-
// Set the resulting type to the boundType of the original type alias
|
11515
|
-
// to support recursive type aliases.
|
11516
|
-
typeAliasTypeVar.details.boundType = rightHandType;
|
11517
|
-
// Record the type parameters within the recursive type alias so it
|
11518
|
-
// can be specialized.
|
11519
|
-
typeAliasTypeVar.details.recursiveTypeParameters = (_a = rightHandType.typeAliasInfo) === null || _a === void 0 ? void 0 : _a.typeParameters;
|
11520
11516
|
}
|
11521
11517
|
}
|
11522
11518
|
}
|
11523
11519
|
assignTypeToExpression(node.leftExpression, { type: rightHandType, isIncomplete }, node.rightExpression,
|
11524
11520
|
/* ignoreEmptyContainers */ true,
|
11525
11521
|
/* allowAssignmentToFinalVar */ true, expectedTypeDiagAddendum);
|
11526
|
-
writeTypeCache(node, { type: rightHandType, isIncomplete }, 0 /*
|
11527
|
-
}
|
11528
|
-
|
11529
|
-
|
11530
|
-
|
11531
|
-
|
11532
|
-
|
11533
|
-
|
11534
|
-
|
11535
|
-
|
11536
|
-
|
11537
|
-
|
11538
|
-
|
11539
|
-
// a call to the TypedDict call. This avoids the expensive (and potentially
|
11540
|
-
// recursive) call to getTypeOfExpression in cases where it's not needed.
|
11541
|
-
if ((callLeftNode.nodeType === 38 /* ParseNodeType.Name */ && callLeftNode.value) === 'TypedDict' ||
|
11542
|
-
(callLeftNode.nodeType === 35 /* ParseNodeType.MemberAccess */ &&
|
11543
|
-
callLeftNode.memberName.value === 'TypedDict' &&
|
11544
|
-
callLeftNode.leftExpression.nodeType === 38 /* ParseNodeType.Name */)) {
|
11545
|
-
// See if this is a call to TypedDict. We want to support
|
11546
|
-
// recursive type references in a TypedDict call.
|
11547
|
-
const callType = getTypeOfExpression(callLeftNode, 2 /* EvaluatorFlags.CallBaseDefaults */).type;
|
11548
|
-
if ((0, types_1.isInstantiableClass)(callType) && types_1.ClassType.isBuiltIn(callType, 'TypedDict')) {
|
11549
|
-
return true;
|
11550
|
-
}
|
11551
|
-
}
|
11552
|
-
}
|
11553
|
-
return false;
|
11522
|
+
writeTypeCache(node, { type: rightHandType, isIncomplete }, 0 /* EvalFlags.None */);
|
11523
|
+
}
|
11524
|
+
// Synthesize a TypeVar that acts as a placeholder for a type alias. This allows
|
11525
|
+
// the type alias definition to refer to itself.
|
11526
|
+
function synthesizeTypeAliasPlaceholder(nameNode) {
|
11527
|
+
const placeholder = types_1.TypeVarType.createInstantiable(`__type_alias_${nameNode.value}`);
|
11528
|
+
placeholder.details.isSynthesized = true;
|
11529
|
+
placeholder.details.recursiveTypeAliasName = nameNode.value;
|
11530
|
+
const scopeId = ParseTreeUtils.getScopeIdForNode(nameNode);
|
11531
|
+
placeholder.details.recursiveTypeAliasScopeId = scopeId;
|
11532
|
+
placeholder.details.recursiveTypeAliasIsPep695Syntax = false;
|
11533
|
+
placeholder.scopeId = scopeId;
|
11534
|
+
return placeholder;
|
11554
11535
|
}
|
11555
11536
|
// Evaluates the type of a type alias (i.e. "type") statement. This code
|
11556
11537
|
// path does not handle traditional type aliases, which are treated as
|
@@ -11568,20 +11549,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11568
11549
|
// This function is common to the handling of "type" statements and explicit
|
11569
11550
|
// calls to the TypeAliasType constructor.
|
11570
11551
|
function getTypeOfTypeAliasCommon(declNode, nameNode, valueNode, isPep695Syntax, typeParamNodes, getTypeParamCallback) {
|
11571
|
-
const cachedType = readTypeCache(nameNode, 0 /*
|
11552
|
+
const cachedType = readTypeCache(nameNode, 0 /* EvalFlags.None */);
|
11572
11553
|
if (cachedType) {
|
11573
11554
|
return cachedType;
|
11574
11555
|
}
|
11575
11556
|
// Synthesize a type variable that represents the type alias while we're
|
11576
11557
|
// evaluating it. This allows us to handle recursive definitions.
|
11577
|
-
const typeAliasTypeVar =
|
11578
|
-
|
11579
|
-
typeAliasTypeVar.details.recursiveTypeAliasName = nameNode.value;
|
11580
|
-
const scopeId = ParseTreeUtils.getScopeIdForNode(nameNode);
|
11581
|
-
typeAliasTypeVar.details.recursiveTypeAliasScopeId = scopeId;
|
11582
|
-
typeAliasTypeVar.details.recursiveTypeAliasIsPep695Syntax = isPep695Syntax;
|
11583
|
-
typeAliasTypeVar.scopeId = scopeId;
|
11584
|
-
// Write the type to the type cache. It will be replaced below.
|
11558
|
+
const typeAliasTypeVar = synthesizeTypeAliasPlaceholder(nameNode);
|
11559
|
+
// Write the type to the type cache to support recursive type alias definitions.
|
11585
11560
|
writeTypeCache(nameNode, { type: typeAliasTypeVar }, /* flags */ undefined);
|
11586
11561
|
// Set a partial type to handle recursive (self-referential) type aliases.
|
11587
11562
|
const scope = ScopeUtils.getScopeForNode(declNode);
|
@@ -11613,7 +11588,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11613
11588
|
// Set the resulting type to the boundType of the original type alias
|
11614
11589
|
// to support recursive type aliases.
|
11615
11590
|
typeAliasTypeVar.details.boundType = aliasType;
|
11616
|
-
writeTypeCache(nameNode, { type: aliasType, isIncomplete }, 0 /*
|
11591
|
+
writeTypeCache(nameNode, { type: aliasType, isIncomplete }, 0 /* EvalFlags.None */);
|
11617
11592
|
return aliasType;
|
11618
11593
|
}
|
11619
11594
|
function evaluateTypesForAugmentedAssignment(node) {
|
@@ -11621,7 +11596,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11621
11596
|
return;
|
11622
11597
|
}
|
11623
11598
|
const destTypeResult = (0, operations_1.getTypeOfAugmentedAssignment)(evaluatorInterface, node, /* inferenceContext */ undefined);
|
11624
|
-
writeTypeCache(node, destTypeResult, 0 /*
|
11599
|
+
writeTypeCache(node, destTypeResult, 0 /* EvalFlags.None */);
|
11625
11600
|
}
|
11626
11601
|
function getPseudoGenericTypeVarName(paramName) {
|
11627
11602
|
return `__type_of_${paramName}`;
|
@@ -11629,7 +11604,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11629
11604
|
function getTypeOfClass(node) {
|
11630
11605
|
initializePrefetchedTypes(node);
|
11631
11606
|
// Is this type already cached?
|
11632
|
-
const cachedClassType = readTypeCache(node.name, 0 /*
|
11607
|
+
const cachedClassType = readTypeCache(node.name, 0 /* EvalFlags.None */);
|
11633
11608
|
if (cachedClassType) {
|
11634
11609
|
if (!(0, types_1.isInstantiableClass)(cachedClassType)) {
|
11635
11610
|
// This can happen in rare circumstances where the class declaration
|
@@ -11638,7 +11613,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11638
11613
|
}
|
11639
11614
|
return {
|
11640
11615
|
classType: cachedClassType,
|
11641
|
-
decoratedType: readTypeCache(node, 0 /*
|
11616
|
+
decoratedType: readTypeCache(node, 0 /* EvalFlags.None */) || types_1.UnknownType.create(),
|
11642
11617
|
};
|
11643
11618
|
}
|
11644
11619
|
// The type wasn't cached, so we need to create a new one.
|
@@ -11703,14 +11678,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11703
11678
|
let isNamedTupleSubclass = false;
|
11704
11679
|
const initSubclassArgs = [];
|
11705
11680
|
let metaclassNode;
|
11706
|
-
let exprFlags = 128 /*
|
11707
|
-
1024 /*
|
11708
|
-
262144 /*
|
11709
|
-
2048 /*
|
11710
|
-
8192 /*
|
11711
|
-
16384 /*
|
11681
|
+
let exprFlags = 128 /* EvalFlags.InstantiableType */ |
|
11682
|
+
1024 /* EvalFlags.AllowGeneric */ |
|
11683
|
+
262144 /* EvalFlags.NoNakedGeneric */ |
|
11684
|
+
2048 /* EvalFlags.NoTypeVarWithScopeId */ |
|
11685
|
+
8192 /* EvalFlags.TypeVarGetsCurScope */ |
|
11686
|
+
16384 /* EvalFlags.EnforceVarianceConsistency */;
|
11712
11687
|
if (fileInfo.isStubFile) {
|
11713
|
-
exprFlags |= 4 /*
|
11688
|
+
exprFlags |= 4 /* EvalFlags.ForwardRefs */;
|
11714
11689
|
}
|
11715
11690
|
node.arguments.forEach((arg) => {
|
11716
11691
|
// Ignore unpacked arguments.
|
@@ -12193,9 +12168,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12193
12168
|
}
|
12194
12169
|
};
|
12195
12170
|
// Update the undecorated class type.
|
12196
|
-
writeTypeCache(node.name, { type: classType }, 0 /*
|
12171
|
+
writeTypeCache(node.name, { type: classType }, 0 /* EvalFlags.None */);
|
12197
12172
|
// Update the decorated class type.
|
12198
|
-
writeTypeCache(node, { type: decoratedType }, 0 /*
|
12173
|
+
writeTypeCache(node, { type: decoratedType }, 0 /* EvalFlags.None */);
|
12199
12174
|
return { classType, decoratedType };
|
12200
12175
|
});
|
12201
12176
|
}
|
@@ -12305,7 +12280,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12305
12280
|
if (!typeOfParam || !(0, types_1.isTypeVar)(typeOfParam)) {
|
12306
12281
|
return;
|
12307
12282
|
}
|
12308
|
-
writeTypeCache(param.name, { type: typeOfParam }, 0 /*
|
12283
|
+
writeTypeCache(param.name, { type: typeOfParam }, 0 /* EvalFlags.None */);
|
12309
12284
|
paramTypes.push(typeOfParam);
|
12310
12285
|
});
|
12311
12286
|
return paramTypes;
|
@@ -12405,7 +12380,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12405
12380
|
deferredClassCompletions.forEach((e) => {
|
12406
12381
|
if (types_1.ClassType.isSameGenericClass(e.dependsUpon, type)) {
|
12407
12382
|
e.classesToComplete.forEach((classNode) => {
|
12408
|
-
const classType = readTypeCache(classNode.name, 0 /*
|
12383
|
+
const classType = readTypeCache(classNode.name, 0 /* EvalFlags.None */);
|
12409
12384
|
if (classType) {
|
12410
12385
|
completeClassTypeDeferred(classType, classNode.name);
|
12411
12386
|
}
|
@@ -12551,7 +12526,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12551
12526
|
function getTypeOfFunction(node) {
|
12552
12527
|
initializePrefetchedTypes(node);
|
12553
12528
|
// Is this predecorated function type cached?
|
12554
|
-
let functionType = readTypeCache(node.name, 0 /*
|
12529
|
+
let functionType = readTypeCache(node.name, 0 /* EvalFlags.None */);
|
12555
12530
|
if (functionType) {
|
12556
12531
|
if (!(0, types_1.isFunction)(functionType)) {
|
12557
12532
|
// This can happen in certain rare circumstances where the
|
@@ -12566,7 +12541,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12566
12541
|
functionType = getTypeOfFunctionPredecorated(node);
|
12567
12542
|
}
|
12568
12543
|
// Is the decorated function type cached?
|
12569
|
-
let decoratedType = readTypeCache(node, 0 /*
|
12544
|
+
let decoratedType = readTypeCache(node, 0 /* EvalFlags.None */);
|
12570
12545
|
if (decoratedType) {
|
12571
12546
|
return { functionType, decoratedType };
|
12572
12547
|
}
|
@@ -12607,7 +12582,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12607
12582
|
}
|
12608
12583
|
decoratedType = (0, decorators_1.addOverloadsToFunctionType)(evaluatorInterface, node, decoratedType);
|
12609
12584
|
}
|
12610
|
-
writeTypeCache(node, { type: decoratedType }, 0 /*
|
12585
|
+
writeTypeCache(node, { type: decoratedType }, 0 /* EvalFlags.None */);
|
12611
12586
|
return { functionType, decoratedType };
|
12612
12587
|
}
|
12613
12588
|
// Evaluates the type of a "def" statement without applying an async
|
@@ -12616,7 +12591,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12616
12591
|
var _a;
|
12617
12592
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
12618
12593
|
// Is this type already cached?
|
12619
|
-
const cachedFunctionType = readTypeCache(node.name, 0 /*
|
12594
|
+
const cachedFunctionType = readTypeCache(node.name, 0 /* EvalFlags.None */);
|
12620
12595
|
if (cachedFunctionType && (0, types_1.isFunction)(cachedFunctionType)) {
|
12621
12596
|
return cachedFunctionType;
|
12622
12597
|
}
|
@@ -12788,7 +12763,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12788
12763
|
if (types_1.FunctionType.isOverloaded(functionType) || types_1.FunctionType.isAbstractMethod(functionType)) {
|
12789
12764
|
treatEllipsisAsAny = true;
|
12790
12765
|
}
|
12791
|
-
defaultValueType = getTypeOfExpression(param.defaultValue, treatEllipsisAsAny ? 1 /*
|
12766
|
+
defaultValueType = getTypeOfExpression(param.defaultValue, treatEllipsisAsAny ? 1 /* EvalFlags.ConvertEllipsisToAny */ : 0 /* EvalFlags.None */, (0, typeUtils_1.makeInferenceContext)(annotatedType)).type;
|
12792
12767
|
}
|
12793
12768
|
if (annotatedType) {
|
12794
12769
|
// If there was both a type annotation and a default value, verify
|
@@ -12881,7 +12856,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12881
12856
|
if ((0, types_1.isUnknown)(paramType)) {
|
12882
12857
|
functionType.details.flags |= 16384 /* FunctionTypeFlags.UnannotatedParams */;
|
12883
12858
|
}
|
12884
|
-
writeTypeCache(paramNameNode, { type: paramType }, 0 /*
|
12859
|
+
writeTypeCache(paramNameNode, { type: paramType }, 0 /* EvalFlags.None */);
|
12885
12860
|
}
|
12886
12861
|
});
|
12887
12862
|
// If the function ends in P.args and P.kwargs parameters, make it exempt from
|
@@ -12962,7 +12937,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12962
12937
|
// Clear the "partially evaluated" flag to indicate that the functionType
|
12963
12938
|
// is fully evaluated.
|
12964
12939
|
functionType.details.flags &= ~131072 /* FunctionTypeFlags.PartiallyEvaluated */;
|
12965
|
-
writeTypeCache(node.name, { type: functionType }, 0 /*
|
12940
|
+
writeTypeCache(node.name, { type: functionType }, 0 /* EvalFlags.None */);
|
12966
12941
|
return functionType;
|
12967
12942
|
});
|
12968
12943
|
}
|
@@ -13027,6 +13002,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13027
13002
|
// Replace any unsolved TypeVars with Unknown (including all function-scoped TypeVars).
|
13028
13003
|
inferredParamType = (0, typeUtils_1.applySolvedTypeVars)(inferredParamType, typeVarContext, {
|
13029
13004
|
unknownIfNotFound: true,
|
13005
|
+
tupleClassType: getTupleClassType(),
|
13030
13006
|
});
|
13031
13007
|
}
|
13032
13008
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(functionNode);
|
@@ -13048,7 +13024,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13048
13024
|
return undefined;
|
13049
13025
|
}
|
13050
13026
|
function inferParameterTypeFromDefaultValue(paramValueExpr) {
|
13051
|
-
const defaultValueType = getTypeOfExpression(paramValueExpr, 1 /*
|
13027
|
+
const defaultValueType = getTypeOfExpression(paramValueExpr, 1 /* EvalFlags.ConvertEllipsisToAny */).type;
|
13052
13028
|
let inferredParamType;
|
13053
13029
|
// Is the default value a "None" or an instance of some private class (one
|
13054
13030
|
// whose name starts with an underscore)? If so, we will assume that the
|
@@ -13184,7 +13160,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13184
13160
|
return undefined;
|
13185
13161
|
}
|
13186
13162
|
// Is this type already cached?
|
13187
|
-
let inferredReturnType = readTypeCache(node.suite, 0 /*
|
13163
|
+
let inferredReturnType = readTypeCache(node.suite, 0 /* EvalFlags.None */);
|
13188
13164
|
let isIncomplete = false;
|
13189
13165
|
if (inferredReturnType) {
|
13190
13166
|
return { type: inferredReturnType, isIncomplete };
|
@@ -13332,7 +13308,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13332
13308
|
}
|
13333
13309
|
}
|
13334
13310
|
}
|
13335
|
-
writeTypeCache(node.suite, { type: inferredReturnType, isIncomplete }, 0 /*
|
13311
|
+
writeTypeCache(node.suite, { type: inferredReturnType, isIncomplete }, 0 /* EvalFlags.None */);
|
13336
13312
|
}
|
13337
13313
|
finally {
|
13338
13314
|
functionRecursionMap.delete(node.id);
|
@@ -13379,7 +13355,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13379
13355
|
const iteratorTypeResult = getTypeOfExpression(node.iterableExpression);
|
13380
13356
|
const iteratedType = (_b = (_a = getTypeOfIterator(iteratorTypeResult, !!node.isAsync, node.iterableExpression)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
|
13381
13357
|
assignTypeToExpression(node.targetExpression, { type: iteratedType, isIncomplete: iteratorTypeResult.isIncomplete }, node.targetExpression);
|
13382
|
-
writeTypeCache(node, { type: iteratedType, isIncomplete: !!iteratorTypeResult.isIncomplete }, 0 /*
|
13358
|
+
writeTypeCache(node, { type: iteratedType, isIncomplete: !!iteratorTypeResult.isIncomplete }, 0 /* EvalFlags.None */);
|
13383
13359
|
}
|
13384
13360
|
function evaluateTypesForExceptStatement(node) {
|
13385
13361
|
// This should be called only if the except node has a target exception.
|
@@ -13429,7 +13405,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13429
13405
|
if (node.name) {
|
13430
13406
|
assignTypeToExpression(node.name, { type: targetType }, node.name);
|
13431
13407
|
}
|
13432
|
-
writeTypeCache(node, { type: targetType }, 0 /*
|
13408
|
+
writeTypeCache(node, { type: targetType }, 0 /* EvalFlags.None */);
|
13433
13409
|
}
|
13434
13410
|
function evaluateTypesForWithStatement(node) {
|
13435
13411
|
if (isTypeCached(node)) {
|
@@ -13491,7 +13467,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13491
13467
|
if (node.target) {
|
13492
13468
|
assignTypeToExpression(node.target, { type: scopedType, isIncomplete: exprTypeResult.isIncomplete }, node.target);
|
13493
13469
|
}
|
13494
|
-
writeTypeCache(node, { type: scopedType, isIncomplete: !!exprTypeResult.isIncomplete }, 0 /*
|
13470
|
+
writeTypeCache(node, { type: scopedType, isIncomplete: !!exprTypeResult.isIncomplete }, 0 /* EvalFlags.None */);
|
13495
13471
|
}
|
13496
13472
|
function evaluateTypesForImportAs(node) {
|
13497
13473
|
var _a;
|
@@ -13516,14 +13492,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13516
13492
|
let symbolType = (_a = getAliasedSymbolTypeForName(node, symbolNameNode.value)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
|
13517
13493
|
// Is there a cached module type associated with this node? If so, use
|
13518
13494
|
// it instead of the type we just created.
|
13519
|
-
const cachedModuleType = readTypeCache(node, 0 /*
|
13495
|
+
const cachedModuleType = readTypeCache(node, 0 /* EvalFlags.None */);
|
13520
13496
|
if (cachedModuleType && (0, types_1.isModule)(cachedModuleType) && symbolType) {
|
13521
13497
|
if ((0, types_1.isTypeSame)(symbolType, cachedModuleType)) {
|
13522
13498
|
symbolType = cachedModuleType;
|
13523
13499
|
}
|
13524
13500
|
}
|
13525
13501
|
assignTypeToNameNode(symbolNameNode, { type: symbolType }, /* ignoreEmptyContainers */ false);
|
13526
|
-
writeTypeCache(node, { type: symbolType }, 0 /*
|
13502
|
+
writeTypeCache(node, { type: symbolType }, 0 /* EvalFlags.None */);
|
13527
13503
|
}
|
13528
13504
|
function evaluateTypesForImportFromAs(node) {
|
13529
13505
|
var _a;
|
@@ -13589,7 +13565,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13589
13565
|
}
|
13590
13566
|
}
|
13591
13567
|
assignTypeToNameNode(aliasNode, { type: symbolType }, /* ignoreEmptyContainers */ false);
|
13592
|
-
writeTypeCache(node, { type: symbolType }, 0 /*
|
13568
|
+
writeTypeCache(node, { type: symbolType }, 0 /* EvalFlags.None */);
|
13593
13569
|
}
|
13594
13570
|
function evaluateTypesForMatchStatement(node) {
|
13595
13571
|
if (isTypeCached(node)) {
|
@@ -13604,7 +13580,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13604
13580
|
/* isPositiveTest */ false);
|
13605
13581
|
}
|
13606
13582
|
}
|
13607
|
-
writeTypeCache(node, { type: subjectType, isIncomplete: !!subjectTypeResult.isIncomplete }, 0 /*
|
13583
|
+
writeTypeCache(node, { type: subjectType, isIncomplete: !!subjectTypeResult.isIncomplete }, 0 /* EvalFlags.None */);
|
13608
13584
|
}
|
13609
13585
|
function evaluateTypesForCaseStatement(node) {
|
13610
13586
|
if (isTypeCached(node)) {
|
@@ -13634,7 +13610,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13634
13610
|
}
|
13635
13611
|
}
|
13636
13612
|
const narrowedSubjectType = (0, patternMatching_1.assignTypeToPatternTargets)(evaluatorInterface, subjectType, !!subjectTypeResult.isIncomplete, node.pattern);
|
13637
|
-
writeTypeCache(node, { type: narrowedSubjectType, isIncomplete: !!subjectTypeResult.isIncomplete }, 0 /*
|
13613
|
+
writeTypeCache(node, { type: narrowedSubjectType, isIncomplete: !!subjectTypeResult.isIncomplete }, 0 /* EvalFlags.None */);
|
13638
13614
|
}
|
13639
13615
|
function evaluateTypesForImportFrom(node) {
|
13640
13616
|
if (isTypeCached(node)) {
|
@@ -13642,7 +13618,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13642
13618
|
}
|
13643
13619
|
if (node.isWildcardImport) {
|
13644
13620
|
// Write back a dummy type so we don't evaluate this node again.
|
13645
|
-
writeTypeCache(node, { type: types_1.AnyType.create() }, 0 /*
|
13621
|
+
writeTypeCache(node, { type: types_1.AnyType.create() }, 0 /* EvalFlags.None */);
|
13646
13622
|
const flowNode = AnalyzerNodeInfo.getFlowNode(node);
|
13647
13623
|
if (flowNode && (flowNode.flags & codeFlowTypes_1.FlowFlags.WildcardImport) !== 0) {
|
13648
13624
|
const wildcardFlowNode = flowNode;
|
@@ -13680,14 +13656,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13680
13656
|
}
|
13681
13657
|
// Is there a cached module type associated with this node? If so, use
|
13682
13658
|
// it instead of the type we just created.
|
13683
|
-
const cachedModuleType = readTypeCache(node, 0 /*
|
13659
|
+
const cachedModuleType = readTypeCache(node, 0 /* EvalFlags.None */);
|
13684
13660
|
if (cachedModuleType && (0, types_1.isModule)(cachedModuleType) && symbolType) {
|
13685
13661
|
if ((0, types_1.isTypeSame)(symbolType, cachedModuleType)) {
|
13686
13662
|
symbolType = cachedModuleType;
|
13687
13663
|
}
|
13688
13664
|
}
|
13689
13665
|
assignTypeToNameNode(symbolNameNode, { type: symbolType }, /* ignoreEmptyContainers */ false);
|
13690
|
-
writeTypeCache(node, { type: symbolType }, 0 /*
|
13666
|
+
writeTypeCache(node, { type: symbolType }, 0 /* EvalFlags.None */);
|
13691
13667
|
}
|
13692
13668
|
}
|
13693
13669
|
function evaluateTypesForTypeAnnotationNode(node) {
|
@@ -13704,7 +13680,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13704
13680
|
allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(node.valueExpression),
|
13705
13681
|
allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(node.valueExpression),
|
13706
13682
|
});
|
13707
|
-
writeTypeCache(node.valueExpression, { type: annotationType }, 0 /*
|
13683
|
+
writeTypeCache(node.valueExpression, { type: annotationType }, 0 /* EvalFlags.None */);
|
13708
13684
|
}
|
13709
13685
|
}
|
13710
13686
|
function getAliasedSymbolTypeForName(node, name) {
|
@@ -13794,7 +13770,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13794
13770
|
if (node.parent.nodeType === 32 /* ParseNodeType.Global */ || node.parent.nodeType === 39 /* ParseNodeType.Nonlocal */) {
|
13795
13771
|
// For global and nonlocal statements, allow forward references so
|
13796
13772
|
// we don't use code flow during symbol lookups.
|
13797
|
-
getTypeOfExpression(node, 4 /*
|
13773
|
+
getTypeOfExpression(node, 4 /* EvalFlags.ForwardRefs */);
|
13798
13774
|
return;
|
13799
13775
|
}
|
13800
13776
|
if (node.parent.nodeType === 37 /* ParseNodeType.ModuleName */) {
|
@@ -13854,7 +13830,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13854
13830
|
// Scan up the parse tree until we find a node that doesn't
|
13855
13831
|
// require any context to be evaluated.
|
13856
13832
|
let nodeToEvaluate = node;
|
13857
|
-
let flags = 0 /*
|
13833
|
+
let flags = 0 /* EvalFlags.None */;
|
13858
13834
|
while (true) {
|
13859
13835
|
// If we're within an argument node in a call or index expression, skip
|
13860
13836
|
// all of the nodes between because the entire argument expression
|
@@ -13908,14 +13884,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13908
13884
|
nodeToEvaluate = parent;
|
13909
13885
|
continue;
|
13910
13886
|
}
|
13911
|
-
flags = 2 /*
|
13887
|
+
flags = 2 /* EvalFlags.CallBaseDefaults */;
|
13912
13888
|
break;
|
13913
13889
|
}
|
13914
13890
|
}
|
13915
13891
|
else if (parent.nodeType === 27 /* ParseNodeType.Index */) {
|
13916
13892
|
// The base expression of an index expression is not contextual.
|
13917
13893
|
if (nodeToEvaluate === parent.baseExpression) {
|
13918
|
-
flags = 2 /*
|
13894
|
+
flags = 2 /* EvalFlags.IndexBaseDefaults */;
|
13919
13895
|
}
|
13920
13896
|
}
|
13921
13897
|
if (!(0, parseNodes_1.isExpressionNode)(parent)) {
|
@@ -14013,7 +13989,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14013
13989
|
const declaredReturnType = enclosingFunctionNode
|
14014
13990
|
? getFunctionDeclaredReturnType(enclosingFunctionNode)
|
14015
13991
|
: undefined;
|
14016
|
-
getTypeOfExpression(parent.returnExpression, 0 /*
|
13992
|
+
getTypeOfExpression(parent.returnExpression, 0 /* EvalFlags.None */, (0, typeUtils_1.makeInferenceContext)(declaredReturnType));
|
14017
13993
|
return;
|
14018
13994
|
}
|
14019
13995
|
break;
|
@@ -14055,7 +14031,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14055
14031
|
const param = functionNode.parameters[paramIndex];
|
14056
14032
|
const annotatedType = getTypeOfParameterAnnotation(typeAnnotation, functionNode.parameters[paramIndex].category);
|
14057
14033
|
const adjType = transformVariadicParamType(node, node.category, adjustParameterAnnotatedType(param, annotatedType));
|
14058
|
-
writeTypeCache(node.name, { type: adjType }, 0 /*
|
14034
|
+
writeTypeCache(node.name, { type: adjType }, 0 /* EvalFlags.None */);
|
14059
14035
|
return;
|
14060
14036
|
}
|
14061
14037
|
const containingClassNode = ParseTreeUtils.getEnclosingClass(functionNode, /* stopAtFunction */ true);
|
@@ -14066,7 +14042,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14066
14042
|
const typeParamName = getPseudoGenericTypeVarName(node.name.value);
|
14067
14043
|
const paramType = classInfo.classType.details.typeParameters.find((param) => param.details.name === typeParamName);
|
14068
14044
|
if (paramType) {
|
14069
|
-
writeTypeCache(node.name, { type: paramType }, 0 /*
|
14045
|
+
writeTypeCache(node.name, { type: paramType }, 0 /* EvalFlags.None */);
|
14070
14046
|
return;
|
14071
14047
|
}
|
14072
14048
|
}
|
@@ -14076,7 +14052,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14076
14052
|
const functionFlags = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, functionNode,
|
14077
14053
|
/* isInClass */ true).flags;
|
14078
14054
|
const inferredParamType = inferParameterType(functionNode, functionFlags, paramIndex, classInfo === null || classInfo === void 0 ? void 0 : classInfo.classType);
|
14079
|
-
writeTypeCache(node.name, { type: transformVariadicParamType(node, node.category, inferredParamType !== null && inferredParamType !== void 0 ? inferredParamType : types_1.UnknownType.create()) }, 0 /*
|
14055
|
+
writeTypeCache(node.name, { type: transformVariadicParamType(node, node.category, inferredParamType !== null && inferredParamType !== void 0 ? inferredParamType : types_1.UnknownType.create()) }, 0 /* EvalFlags.None */);
|
14080
14056
|
}
|
14081
14057
|
// Evaluates the types that are assigned within the statement that contains
|
14082
14058
|
// the specified parse node. In some cases, a broader statement may need to
|
@@ -14313,9 +14289,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14313
14289
|
return { type: createClassVarType(classType, errorNode, typeArgs, flags) };
|
14314
14290
|
}
|
14315
14291
|
case 'Protocol': {
|
14316
|
-
if ((flags &
|
14317
|
-
(67108864 /* EvaluatorFlags.DisallowNonTypeSpecialForms */ | 256 /* EvaluatorFlags.ExpectingTypeAnnotation */)) !==
|
14318
|
-
0) {
|
14292
|
+
if ((flags & (67108864 /* EvalFlags.NoNonTypeSpecialForms */ | 256 /* EvalFlags.TypeExpression */)) !== 0) {
|
14319
14293
|
addError(localize_1.LocMessage.protocolNotAllowed(), errorNode);
|
14320
14294
|
}
|
14321
14295
|
typeArgs === null || typeArgs === void 0 ? void 0 : typeArgs.forEach((typeArg) => {
|
@@ -14330,17 +14304,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14330
14304
|
};
|
14331
14305
|
}
|
14332
14306
|
case 'TypedDict': {
|
14333
|
-
if ((flags &
|
14334
|
-
(67108864 /* EvaluatorFlags.DisallowNonTypeSpecialForms */ | 256 /* EvaluatorFlags.ExpectingTypeAnnotation */)) !==
|
14335
|
-
0) {
|
14307
|
+
if ((flags & (67108864 /* EvalFlags.NoNonTypeSpecialForms */ | 256 /* EvalFlags.TypeExpression */)) !== 0) {
|
14336
14308
|
addError(localize_1.LocMessage.typedDictNotAllowed(), errorNode);
|
14337
14309
|
}
|
14338
14310
|
break;
|
14339
14311
|
}
|
14340
14312
|
case 'Literal': {
|
14341
|
-
if ((flags &
|
14342
|
-
(67108864 /* EvaluatorFlags.DisallowNonTypeSpecialForms */ | 256 /* EvaluatorFlags.ExpectingTypeAnnotation */)) !==
|
14343
|
-
0) {
|
14313
|
+
if ((flags & (67108864 /* EvalFlags.NoNonTypeSpecialForms */ | 256 /* EvalFlags.TypeExpression */)) !== 0) {
|
14344
14314
|
addError(localize_1.LocMessage.literalNotAllowed(), errorNode);
|
14345
14315
|
}
|
14346
14316
|
break;
|
@@ -14363,7 +14333,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14363
14333
|
return { type: createFinalType(classType, errorNode, typeArgs, flags) };
|
14364
14334
|
}
|
14365
14335
|
case 'Annotated': {
|
14366
|
-
return createAnnotatedType(classType, errorNode, typeArgs);
|
14336
|
+
return createAnnotatedType(classType, errorNode, typeArgs, flags);
|
14367
14337
|
}
|
14368
14338
|
case 'Concatenate': {
|
14369
14339
|
return { type: createConcatenateType(classType, errorNode, typeArgs, flags) };
|
@@ -14394,7 +14364,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14394
14364
|
if (fileInfo.isStubFile ||
|
14395
14365
|
fileInfo.executionEnvironment.pythonVersion.isGreaterOrEqualTo(pythonVersion_1.pythonVersion3_9) ||
|
14396
14366
|
(0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(AnalyzerNodeInfo.getFileInfo(errorNode)) ||
|
14397
|
-
(flags & 4 /*
|
14367
|
+
(flags & 4 /* EvalFlags.ForwardRefs */) !== 0) {
|
14398
14368
|
// Handle "type" specially, since it needs to act like "Type"
|
14399
14369
|
// in Python 3.9 and newer.
|
14400
14370
|
if (types_1.ClassType.isBuiltIn(classType, 'type') && typeArgs) {
|
@@ -14581,7 +14551,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14581
14551
|
typeVarContext.setTypeVarType(typeParam, typeArgType);
|
14582
14552
|
return;
|
14583
14553
|
}
|
14584
|
-
const solvedDefaultType = (0, typeUtils_1.applySolvedTypeVars)(typeParam, typeVarContext, {
|
14554
|
+
const solvedDefaultType = (0, typeUtils_1.applySolvedTypeVars)(typeParam, typeVarContext, {
|
14555
|
+
unknownIfNotFound: true,
|
14556
|
+
tupleClassType: getTupleClassType(),
|
14557
|
+
});
|
14585
14558
|
typeArgTypes.push(solvedDefaultType);
|
14586
14559
|
if ((0, types_1.isParamSpec)(typeParam)) {
|
14587
14560
|
typeVarContext.setTypeVarType(typeParam, (0, typeUtils_1.convertTypeToParamSpecValue)(solvedDefaultType));
|
@@ -14595,7 +14568,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14595
14568
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
14596
14569
|
let adjustedTypeArgType = applyTypeArgToTypeVar(typeParameters[index], typeArgType, diag);
|
14597
14570
|
// Determine if the variance must match.
|
14598
|
-
if (adjustedTypeArgType && (flags & 16384 /*
|
14571
|
+
if (adjustedTypeArgType && (flags & 16384 /* EvalFlags.EnforceVarianceConsistency */) !== 0) {
|
14599
14572
|
const destType = typeParameters[index];
|
14600
14573
|
const declaredVariance = destType.details.declaredVariance;
|
14601
14574
|
if (!(0, typeUtils_1.isVarianceOfTypeArgumentCompatible)(adjustedTypeArgType, declaredVariance)) {
|
@@ -14664,39 +14637,37 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14664
14637
|
return getTypeOfExpressionExpectingType(arg.valueExpression, options);
|
14665
14638
|
}
|
14666
14639
|
function getTypeOfExpressionExpectingType(node, options) {
|
14667
|
-
let flags = 128 /*
|
14668
|
-
8 /* EvaluatorFlags.EvaluateStringLiteralAsType */ |
|
14669
|
-
131072 /* EvaluatorFlags.DisallowClassVar */;
|
14640
|
+
let flags = 128 /* EvalFlags.InstantiableType */ | 8 /* EvalFlags.StrLiteralAsType */ | 131072 /* EvalFlags.NoClassVar */;
|
14670
14641
|
if (options === null || options === void 0 ? void 0 : options.allowTypeVarsWithoutScopeId) {
|
14671
|
-
flags |= 4096 /*
|
14642
|
+
flags |= 4096 /* EvalFlags.AllowTypeVarWithoutScopeId */;
|
14672
14643
|
}
|
14673
14644
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
14674
14645
|
if (fileInfo.isStubFile || (options === null || options === void 0 ? void 0 : options.allowForwardReference)) {
|
14675
|
-
flags |= 4 /*
|
14646
|
+
flags |= 4 /* EvalFlags.ForwardRefs */;
|
14676
14647
|
}
|
14677
14648
|
else {
|
14678
|
-
flags |=
|
14649
|
+
flags |= 8388608 /* EvalFlags.ParsesStringLiteral */;
|
14679
14650
|
}
|
14680
14651
|
if (!options || !options.allowFinal) {
|
14681
|
-
flags |= 16 /*
|
14652
|
+
flags |= 16 /* EvalFlags.NoFinal */;
|
14682
14653
|
}
|
14683
14654
|
if (options === null || options === void 0 ? void 0 : options.allowRequired) {
|
14684
|
-
flags |= 1048576 /*
|
14655
|
+
flags |= 1048576 /* EvalFlags.AllowRequired */ | 256 /* EvalFlags.TypeExpression */;
|
14685
14656
|
}
|
14686
14657
|
if (options === null || options === void 0 ? void 0 : options.allowUnpackedTuple) {
|
14687
|
-
flags |= 2097152 /*
|
14658
|
+
flags |= 2097152 /* EvalFlags.AllowUnpackedTuple */;
|
14688
14659
|
}
|
14689
14660
|
else {
|
14690
|
-
flags |= 64 /*
|
14661
|
+
flags |= 64 /* EvalFlags.NoTypeVarTuple */;
|
14691
14662
|
}
|
14692
14663
|
if (!options || !options.allowParamSpec) {
|
14693
|
-
flags |= 32 /*
|
14664
|
+
flags |= 32 /* EvalFlags.NoParamSpec */;
|
14694
14665
|
}
|
14695
14666
|
if (options === null || options === void 0 ? void 0 : options.enforceTypeAnnotationRules) {
|
14696
|
-
flags |= 256 /*
|
14667
|
+
flags |= 256 /* EvalFlags.TypeExpression */;
|
14697
14668
|
}
|
14698
14669
|
if (options === null || options === void 0 ? void 0 : options.disallowProtocolAndTypedDict) {
|
14699
|
-
flags |= 67108864 /*
|
14670
|
+
flags |= 67108864 /* EvalFlags.NoNonTypeSpecialForms */;
|
14700
14671
|
}
|
14701
14672
|
return getTypeOfExpression(node, flags);
|
14702
14673
|
}
|
@@ -15112,10 +15083,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15112
15083
|
if (declaration.intrinsicType === 'Any') {
|
15113
15084
|
return { type: types_1.AnyType.create() };
|
15114
15085
|
}
|
15115
|
-
if (declaration.intrinsicType === '
|
15086
|
+
if (declaration.intrinsicType === 'type[self]') {
|
15116
15087
|
const classNode = ParseTreeUtils.getEnclosingClass(declaration.node);
|
15117
15088
|
const classTypeInfo = getTypeOfClass(classNode);
|
15118
|
-
return {
|
15089
|
+
return {
|
15090
|
+
type: classTypeInfo
|
15091
|
+
? (0, typeUtils_1.synthesizeTypeVarForSelfCls)(classTypeInfo.classType, /* isClsParam */ true)
|
15092
|
+
: types_1.UnknownType.create(),
|
15093
|
+
};
|
15119
15094
|
}
|
15120
15095
|
const strType = getBuiltInObject(declaration.node, 'str');
|
15121
15096
|
const intType = getBuiltInObject(declaration.node, 'int');
|
@@ -15228,7 +15203,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15228
15203
|
}
|
15229
15204
|
function getTypeOfTypeParameter(node) {
|
15230
15205
|
// Is this type already cached?
|
15231
|
-
const cachedTypeVarType = readTypeCache(node.name, 0 /*
|
15206
|
+
const cachedTypeVarType = readTypeCache(node.name, 0 /* EvalFlags.None */);
|
15232
15207
|
if (cachedTypeVarType && (0, types_1.isTypeVar)(cachedTypeVarType)) {
|
15233
15208
|
return cachedTypeVarType;
|
15234
15209
|
}
|
@@ -15437,7 +15412,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15437
15412
|
}
|
15438
15413
|
// Special-case calls to certain built-in type functions.
|
15439
15414
|
if (((_a = resolvedDecl.inferredTypeSource) === null || _a === void 0 ? void 0 : _a.nodeType) === 9 /* ParseNodeType.Call */) {
|
15440
|
-
const baseTypeResult = getTypeOfExpression(resolvedDecl.inferredTypeSource.leftExpression, 2 /*
|
15415
|
+
const baseTypeResult = getTypeOfExpression(resolvedDecl.inferredTypeSource.leftExpression, 2 /* EvalFlags.CallBaseDefaults */);
|
15441
15416
|
const callType = baseTypeResult.type;
|
15442
15417
|
const exemptBuiltins = [
|
15443
15418
|
'TypeVar',
|
@@ -16118,7 +16093,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16118
16093
|
paramType = stripLiteralValue(paramType);
|
16119
16094
|
}
|
16120
16095
|
paramTypes.push(paramType);
|
16121
|
-
writeTypeCache(param.name, { type: paramType }, 0 /*
|
16096
|
+
writeTypeCache(param.name, { type: paramType }, 0 /* EvalFlags.None */);
|
16122
16097
|
}
|
16123
16098
|
});
|
16124
16099
|
// Don't bother trying to determine the contextual return
|
@@ -16183,46 +16158,51 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16183
16158
|
function getTypeOfMember(member) {
|
16184
16159
|
if ((0, types_1.isInstantiableClass)(member.classType)) {
|
16185
16160
|
return (0, typeUtils_1.partiallySpecializeType)(getEffectiveTypeOfSymbol(member.symbol), member.classType,
|
16186
|
-
/* selfClass */ undefined, typeClass
|
16161
|
+
/* selfClass */ undefined, typeClass && (0, types_1.isInstantiableClass)(typeClass) ? typeClass : undefined);
|
16187
16162
|
}
|
16188
16163
|
return types_1.UnknownType.create();
|
16189
16164
|
}
|
16190
16165
|
function getTypeOfMemberInternal(errorNode, member, selfClass, flags) {
|
16191
|
-
if ((0, types_1.
|
16192
|
-
const typeResult = getEffectiveTypeOfSymbolForUsage(member.symbol);
|
16193
|
-
if (typeResult) {
|
16194
|
-
// If the type is a function or overloaded function, infer
|
16195
|
-
// and cache the return type if necessary. This needs to be done
|
16196
|
-
// prior to specializing.
|
16197
|
-
inferReturnTypeIfNecessary(typeResult.type);
|
16198
|
-
// Check for ambiguous accesses to attributes with generic types?
|
16199
|
-
if (errorNode &&
|
16200
|
-
selfClass &&
|
16201
|
-
(0, types_1.isClass)(selfClass) &&
|
16202
|
-
member.isInstanceMember &&
|
16203
|
-
(0, types_1.isClass)(member.unspecializedClassType) &&
|
16204
|
-
(flags & 1024 /* MemberAccessFlags.DisallowGenericInstanceVariableAccess */) !== 0 &&
|
16205
|
-
(0, typeUtils_1.requiresSpecialization)(typeResult.type, { ignoreSelf: true, ignoreImplicitTypeArgs: true })) {
|
16206
|
-
const specializedType = (0, typeUtils_1.partiallySpecializeType)(typeResult.type, member.unspecializedClassType, (0, typeUtils_1.selfSpecializeClass)(selfClass, /* overrideTypeArgs */ true));
|
16207
|
-
if ((0, types_1.findSubtype)(specializedType, (subtype) => !(0, types_1.isFunction)(subtype) &&
|
16208
|
-
!(0, types_1.isOverloadedFunction)(subtype) &&
|
16209
|
-
(0, typeUtils_1.requiresSpecialization)(subtype, { ignoreSelf: true, ignoreImplicitTypeArgs: true }))) {
|
16210
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.genericInstanceVariableAccess(), errorNode);
|
16211
|
-
}
|
16212
|
-
}
|
16213
|
-
return {
|
16214
|
-
type: (0, typeUtils_1.partiallySpecializeType)(typeResult.type, member.classType, selfClass),
|
16215
|
-
isIncomplete: !!typeResult.isIncomplete,
|
16216
|
-
};
|
16217
|
-
}
|
16218
|
-
}
|
16219
|
-
else if ((0, types_1.isAnyOrUnknown)(member.classType)) {
|
16166
|
+
if ((0, types_1.isAnyOrUnknown)(member.classType)) {
|
16220
16167
|
return {
|
16221
16168
|
type: member.classType,
|
16222
16169
|
isIncomplete: false,
|
16223
16170
|
};
|
16224
16171
|
}
|
16225
|
-
|
16172
|
+
if (!(0, types_1.isInstantiableClass)(member.classType)) {
|
16173
|
+
return undefined;
|
16174
|
+
}
|
16175
|
+
const typeResult = getEffectiveTypeOfSymbolForUsage(member.symbol);
|
16176
|
+
if (!typeResult) {
|
16177
|
+
return undefined;
|
16178
|
+
}
|
16179
|
+
// Report inappropriate use of variables in type expressions.
|
16180
|
+
if ((flags & 2048 /* MemberAccessFlags.TypeExpression */) !== 0 && errorNode) {
|
16181
|
+
typeResult.type = validateSymbolIsTypeExpression(errorNode, typeResult.type, !!typeResult.includesVariableDecl);
|
16182
|
+
}
|
16183
|
+
// If the type is a function or overloaded function, infer
|
16184
|
+
// and cache the return type if necessary. This needs to be done
|
16185
|
+
// prior to specializing.
|
16186
|
+
inferReturnTypeIfNecessary(typeResult.type);
|
16187
|
+
// Check for ambiguous accesses to attributes with generic types?
|
16188
|
+
if (errorNode &&
|
16189
|
+
selfClass &&
|
16190
|
+
(0, types_1.isClass)(selfClass) &&
|
16191
|
+
member.isInstanceMember &&
|
16192
|
+
(0, types_1.isClass)(member.unspecializedClassType) &&
|
16193
|
+
(flags & 1024 /* MemberAccessFlags.DisallowGenericInstanceVariableAccess */) !== 0 &&
|
16194
|
+
(0, typeUtils_1.requiresSpecialization)(typeResult.type, { ignoreSelf: true, ignoreImplicitTypeArgs: true })) {
|
16195
|
+
const specializedType = (0, typeUtils_1.partiallySpecializeType)(typeResult.type, member.unspecializedClassType, (0, typeUtils_1.selfSpecializeClass)(selfClass, /* overrideTypeArgs */ true));
|
16196
|
+
if ((0, types_1.findSubtype)(specializedType, (subtype) => !(0, types_1.isFunction)(subtype) &&
|
16197
|
+
!(0, types_1.isOverloadedFunction)(subtype) &&
|
16198
|
+
(0, typeUtils_1.requiresSpecialization)(subtype, { ignoreSelf: true, ignoreImplicitTypeArgs: true }))) {
|
16199
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.genericInstanceVariableAccess(), errorNode);
|
16200
|
+
}
|
16201
|
+
}
|
16202
|
+
return {
|
16203
|
+
type: (0, typeUtils_1.partiallySpecializeType)(typeResult.type, member.classType, selfClass),
|
16204
|
+
isIncomplete: !!typeResult.isIncomplete,
|
16205
|
+
};
|
16226
16206
|
}
|
16227
16207
|
function assignClass(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount, reportErrorsUsingObjType) {
|
16228
16208
|
// If the source or dest types are partially evaluated (i.e. they are in the
|
@@ -18479,7 +18459,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18479
18459
|
assignedType.typeArguments.length <= assignedType.details.typeParameters.length &&
|
18480
18460
|
!assignedType.tupleTypeArguments) {
|
18481
18461
|
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(assignedType));
|
18482
|
-
(0, constraintSolver_1.
|
18462
|
+
(0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, types_1.ClassType.cloneForSpecialization(assignedType,
|
18483
18463
|
/* typeArguments */ undefined,
|
18484
18464
|
/* isTypeArgumentExplicit */ false), declaredType, typeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start);
|
18485
18465
|
let replacedTypeArg = false;
|
@@ -19282,8 +19262,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19282
19262
|
return true;
|
19283
19263
|
}
|
19284
19264
|
function isLegalImplicitTypeAliasType(type) {
|
19285
|
-
// We explicitly exclude "
|
19286
|
-
if ((0,
|
19265
|
+
// We explicitly exclude "..." and "Unknown".
|
19266
|
+
if ((0, typeUtils_1.isEllipsisType)(type)) {
|
19267
|
+
return false;
|
19268
|
+
}
|
19269
|
+
if ((0, types_1.isUnknown)(type)) {
|
19270
|
+
// If this is a union type, we'll assume that it was meant as a type
|
19271
|
+
// alias even though all of the union subtypes are Unknown.
|
19272
|
+
if (type.specialForm && types_1.ClassType.isBuiltIn(type.specialForm, 'UnionType')) {
|
19273
|
+
return true;
|
19274
|
+
}
|
19287
19275
|
return false;
|
19288
19276
|
}
|
19289
19277
|
// Look at the subtypes within the union. If any of them are not
|
@@ -19297,6 +19285,34 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19297
19285
|
});
|
19298
19286
|
return isLegal;
|
19299
19287
|
}
|
19288
|
+
function isPossibleTypeAliasOrTypedDict(decl) {
|
19289
|
+
return isPossibleTypeAliasDeclaration(decl) || isPossibleTypeDictFactoryCall(decl);
|
19290
|
+
}
|
19291
|
+
function isPossibleTypeDictFactoryCall(decl) {
|
19292
|
+
var _a;
|
19293
|
+
if (decl.type !== 1 /* DeclarationType.Variable */ ||
|
19294
|
+
!decl.node.parent ||
|
19295
|
+
decl.node.parent.nodeType !== 3 /* ParseNodeType.Assignment */ ||
|
19296
|
+
((_a = decl.node.parent.rightExpression) === null || _a === void 0 ? void 0 : _a.nodeType) !== 9 /* ParseNodeType.Call */) {
|
19297
|
+
return false;
|
19298
|
+
}
|
19299
|
+
const callLeftNode = decl.node.parent.rightExpression.leftExpression;
|
19300
|
+
// Use a simple heuristic to determine whether this is potentially
|
19301
|
+
// a call to the TypedDict call. This avoids the expensive (and potentially
|
19302
|
+
// recursive) call to getTypeOfExpression in cases where it's not needed.
|
19303
|
+
if ((callLeftNode.nodeType === 38 /* ParseNodeType.Name */ && callLeftNode.value) === 'TypedDict' ||
|
19304
|
+
(callLeftNode.nodeType === 35 /* ParseNodeType.MemberAccess */ &&
|
19305
|
+
callLeftNode.memberName.value === 'TypedDict' &&
|
19306
|
+
callLeftNode.leftExpression.nodeType === 38 /* ParseNodeType.Name */)) {
|
19307
|
+
// See if this is a call to TypedDict. We want to support
|
19308
|
+
// recursive type references in a TypedDict call.
|
19309
|
+
const callType = getTypeOfExpression(callLeftNode, 2 /* EvalFlags.CallBaseDefaults */).type;
|
19310
|
+
if ((0, types_1.isInstantiableClass)(callType) && types_1.ClassType.isBuiltIn(callType, 'TypedDict')) {
|
19311
|
+
return true;
|
19312
|
+
}
|
19313
|
+
}
|
19314
|
+
return false;
|
19315
|
+
}
|
19300
19316
|
function printObjectTypeForClass(type) {
|
19301
19317
|
return TypePrinter.printObjectTypeForClass(type, evaluatorOptions.printTypeFlags, getFunctionEffectiveReturnType);
|
19302
19318
|
}
|