@zzzen/pyright-internal 1.2.0-dev.20240623 → 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 +85 -71
- 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 +61 -31
- 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/importResolver.d.ts +4 -8
- package/dist/analyzer/importResolver.js +87 -85
- package/dist/analyzer/importResolver.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 +34 -11
- 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/service.js +1 -1
- package/dist/analyzer/service.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 +600 -563
- 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 +64 -32
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +12 -6
- package/dist/analyzer/typeUtils.js +52 -18
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +3 -1
- package/dist/analyzer/types.js +9 -1
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysis.js +3 -1
- package/dist/backgroundAnalysis.js.map +1 -1
- package/dist/backgroundAnalysisBase.js +1 -1
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.d.ts +2 -2
- package/dist/common/collectionUtils.d.ts +2 -2
- package/dist/common/collectionUtils.js.map +1 -1
- package/dist/common/core.d.ts +8 -3
- package/dist/common/core.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/common/envVarUtils.js.map +1 -1
- package/dist/languageServerBase.js +20 -16
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +7 -4
- package/dist/languageService/autoImporter.js +13 -10
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +2 -1
- package/dist/languageService/completionProvider.js +24 -19
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +4 -1
- package/dist/localization/localize.js +3 -2
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +4 -3
- package/dist/localization/package.nls.de.json +3 -2
- package/dist/localization/package.nls.en-us.json +2 -1
- package/dist/localization/package.nls.es.json +3 -2
- package/dist/localization/package.nls.fr.json +3 -2
- package/dist/localization/package.nls.it.json +3 -2
- package/dist/localization/package.nls.ja.json +3 -2
- package/dist/localization/package.nls.ko.json +3 -2
- package/dist/localization/package.nls.pl.json +3 -2
- package/dist/localization/package.nls.pt-br.json +4 -3
- package/dist/localization/package.nls.qps-ploc.json +1 -0
- package/dist/localization/package.nls.ru.json +3 -2
- package/dist/localization/package.nls.tr.json +3 -2
- package/dist/localization/package.nls.zh-cn.json +3 -2
- package/dist/localization/package.nls.zh-tw.json +3 -2
- package/dist/parser/parseNodes.d.ts +3 -1
- package/dist/parser/parseNodes.js +3 -1
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.js +20 -9
- package/dist/parser/parser.js.map +1 -1
- package/dist/pyright.js +265 -5
- package/dist/pyright.js.map +1 -1
- package/dist/tests/completions.test.js +80 -0
- package/dist/tests/completions.test.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/languageServer.test.js +39 -4
- package/dist/tests/languageServer.test.js.map +1 -1
- package/dist/tests/lsp/languageServer.js +19 -3
- package/dist/tests/lsp/languageServer.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +6 -2
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +6 -2
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +1 -1
- package/dist/tests/typeEvaluator6.test.js +4 -0
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +2 -2
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typeEvaluator8.test.js +1 -1
- package/package.json +4 -4
@@ -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
|
-
addExpectedClassDiagnostic(typeResult.type, node);
|
791
|
-
typeResult.type = types_1.UnknownType.create();
|
792
|
-
typeResult.typeErrors = true;
|
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;
|
794
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
|
+
});
|
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
|
-
|
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) {
|
3114
|
+
return type;
|
3115
|
+
}
|
3116
|
+
if ((0, types_1.isTypeVar)(type) || (0, typeUtils_1.isTypeAliasPlaceholder)(type)) {
|
3117
|
+
return type;
|
3118
|
+
}
|
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)) {
|
3138
3122
|
return type;
|
3139
3123
|
}
|
3140
|
-
|
3124
|
+
// Disable for assignments in the typings.pyi file, since it defines special forms.
|
3125
|
+
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
3126
|
+
if (fileInfo.isTypingStubFile) {
|
3141
3127
|
return type;
|
3142
3128
|
}
|
3143
|
-
|
3144
|
-
|
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;
|
3145
3140
|
}
|
3146
|
-
//
|
3147
|
-
//
|
3148
|
-
|
3149
|
-
|
3150
|
-
|
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
|
+
}
|
3151
3147
|
}
|
3152
|
-
return
|
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)) {
|
@@ -7480,7 +7481,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7480
7481
|
while (argIndex < argList.length) {
|
7481
7482
|
if (argList[argIndex].argumentCategory === 2 /* ArgumentCategory.UnpackedDictionary */) {
|
7482
7483
|
// Verify that the type used in this expression is a SupportsKeysAndGetItem[str, T].
|
7483
|
-
const
|
7484
|
+
const argTypeResult = getTypeOfArgument(argList[argIndex], (0, typeUtils_1.makeInferenceContext)(paramDetails.unpackedKwargsTypedDictType), signatureTracker);
|
7485
|
+
const argType = argTypeResult.type;
|
7486
|
+
if (argTypeResult.isIncomplete) {
|
7487
|
+
isTypeIncomplete = true;
|
7488
|
+
}
|
7484
7489
|
if ((0, types_1.isAnyOrUnknown)(argType)) {
|
7485
7490
|
unpackedDictionaryArgType = argType;
|
7486
7491
|
}
|
@@ -7651,21 +7656,29 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7651
7656
|
}
|
7652
7657
|
else if (paramDetails.kwargsIndex !== undefined) {
|
7653
7658
|
const paramType = paramDetails.params[paramDetails.kwargsIndex].type;
|
7654
|
-
|
7655
|
-
|
7656
|
-
|
7657
|
-
|
7658
|
-
|
7659
|
-
|
7660
|
-
|
7661
|
-
|
7662
|
-
|
7663
|
-
|
7664
|
-
|
7665
|
-
|
7666
|
-
|
7667
|
-
|
7668
|
-
|
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
|
+
}
|
7669
7682
|
trySetActive(argList[argIndex], paramDetails.params[paramDetails.kwargsIndex].param);
|
7670
7683
|
}
|
7671
7684
|
else {
|
@@ -7968,12 +7981,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7968
7981
|
}
|
7969
7982
|
if ((0, types_1.isClassInstance)(effectiveExpectedType) && !(0, types_1.isTypeSame)(effectiveReturnType, effectiveExpectedType)) {
|
7970
7983
|
const tempTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(effectiveReturnType));
|
7971
|
-
if ((0, constraintSolver_1.
|
7984
|
+
if ((0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, effectiveReturnType, effectiveExpectedType, tempTypeVarContext, liveTypeVarScopes, errorNode.start)) {
|
7972
7985
|
const genericReturnType = types_1.ClassType.cloneForSpecialization(effectiveReturnType,
|
7973
7986
|
/* typeArguments */ undefined,
|
7974
7987
|
/* isTypeArgumentExplicit */ false);
|
7975
7988
|
effectiveExpectedType = (0, typeUtils_1.applySolvedTypeVars)(genericReturnType, tempTypeVarContext, {
|
7976
7989
|
unknownIfNotFound: true,
|
7990
|
+
tupleClassType: getTupleClassType(),
|
7977
7991
|
});
|
7978
7992
|
effectiveFlags |= 4096 /* AssignTypeFlags.SkipPopulateUnknownExpectedType */;
|
7979
7993
|
}
|
@@ -8191,6 +8205,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8191
8205
|
const unknownIfNotFound = !ParseTreeUtils.getTypeVarScopesForNode(errorNode).some((typeVarScope) => typeVarContext.hasSolveForScope(typeVarScope));
|
8192
8206
|
let specializedReturnType = (0, typeUtils_1.applySolvedTypeVars)(returnType, typeVarContext, {
|
8193
8207
|
unknownIfNotFound,
|
8208
|
+
tupleClassType: getTupleClassType(),
|
8194
8209
|
unknownExemptTypeVars: getUnknownExemptTypeVarsForReturnType(type, returnType),
|
8195
8210
|
eliminateUnsolvedInUnions,
|
8196
8211
|
applyInScopePlaceholders: true,
|
@@ -8202,6 +8217,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8202
8217
|
paramSpecTypeVarContext.forEach((paramSpecTypeVarContext) => {
|
8203
8218
|
if (paramSpecTypeVarContext) {
|
8204
8219
|
specializedReturnType = (0, typeUtils_1.applySolvedTypeVars)(specializedReturnType, paramSpecTypeVarContext);
|
8220
|
+
// It's possible that one or more of the TypeVars or ParamSpecs
|
8221
|
+
// in the typeVarContext refer to TypeVars that were solved in
|
8222
|
+
// the paramSpecTypeVarContext. Apply these solved TypeVars accordingly.
|
8223
|
+
(0, typeUtils_1.applySourceContextTypeVars)(typeVarContext, paramSpecTypeVarContext);
|
8205
8224
|
}
|
8206
8225
|
});
|
8207
8226
|
}
|
@@ -8468,13 +8487,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8468
8487
|
}
|
8469
8488
|
else {
|
8470
8489
|
const flags = argParam.isinstanceParam
|
8471
|
-
? 512 /*
|
8472
|
-
8 /*
|
8473
|
-
32 /*
|
8474
|
-
64 /*
|
8475
|
-
16 /*
|
8476
|
-
2 /*
|
8477
|
-
|
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 */;
|
8478
8498
|
const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType, !!(typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete)), signatureTracker);
|
8479
8499
|
argType = exprTypeResult.type;
|
8480
8500
|
// If the type includes multiple instances of a generic function
|
@@ -8501,7 +8521,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8501
8521
|
expectedTypeDiag = exprTypeResult.expectedTypeDiagAddendum;
|
8502
8522
|
}
|
8503
8523
|
if (argParam.argument && argParam.argument.name && !isSpeculativeModeInUse(argParam.errorNode)) {
|
8504
|
-
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 */);
|
8505
8525
|
}
|
8506
8526
|
}
|
8507
8527
|
else {
|
@@ -8819,6 +8839,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8819
8839
|
const typeVarContext = new typeVarContext_1.TypeVarContext(typeVar.scopeId);
|
8820
8840
|
const concreteDefaultType = makeTopLevelTypeVarsConcrete((0, typeUtils_1.applySolvedTypeVars)(typeVar.details.defaultType, typeVarContext, {
|
8821
8841
|
unknownIfNotFound: true,
|
8842
|
+
tupleClassType: getTupleClassType(),
|
8822
8843
|
}));
|
8823
8844
|
if (typeVar.details.boundType) {
|
8824
8845
|
if (!assignType(typeVar.details.boundType, concreteDefaultType)) {
|
@@ -9067,7 +9088,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9067
9088
|
typeParameters = [];
|
9068
9089
|
let isTypeParamListValid = true;
|
9069
9090
|
typeParamsExpr.expressions.map((expr) => {
|
9070
|
-
let entryType = getTypeOfExpression(expr, 128 /*
|
9091
|
+
let entryType = getTypeOfExpression(expr, 128 /* EvalFlags.InstantiableType */ | 4096 /* EvalFlags.AllowTypeVarWithoutScopeId */).type;
|
9071
9092
|
if ((0, types_1.isTypeVar)(entryType)) {
|
9072
9093
|
if (entryType.scopeId || entryType.isVariadicUnpacked) {
|
9073
9094
|
isTypeParamListValid = false;
|
@@ -9166,9 +9187,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9166
9187
|
else if (baseClass.literalValue !== undefined) {
|
9167
9188
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeLiteral(), argList[1].node || errorNode);
|
9168
9189
|
}
|
9169
|
-
|
9170
|
-
classFlags |= 256 /* ClassTypeFlags.Final */ | 2097152 /* ClassTypeFlags.NewTypeClass */ | 4194304 /* ClassTypeFlags.ValidTypeAliasClass */;
|
9171
|
-
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),
|
9172
9191
|
/* declaredMetaclass */ undefined, baseClass.details.effectiveMetaclass);
|
9173
9192
|
classType.details.baseClasses.push(isBaseClassAny ? types_1.AnyType.create() : baseClass);
|
9174
9193
|
(0, typeUtils_1.computeMroLinearization)(classType);
|
@@ -9240,10 +9259,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9240
9259
|
let type;
|
9241
9260
|
if (node.constType === 26 /* KeywordType.None */) {
|
9242
9261
|
if (noneTypeClass) {
|
9243
|
-
type =
|
9244
|
-
(flags & 128 /* EvaluatorFlags.ExpectingInstantiableType */) !== 0
|
9245
|
-
? noneTypeClass
|
9246
|
-
: (0, typeUtils_1.convertToInstance)(noneTypeClass);
|
9262
|
+
type = (flags & 128 /* EvalFlags.InstantiableType */) !== 0 ? noneTypeClass : (0, typeUtils_1.convertToInstance)(noneTypeClass);
|
9247
9263
|
}
|
9248
9264
|
}
|
9249
9265
|
else if (node.constType === 33 /* KeywordType.True */ ||
|
@@ -9336,8 +9352,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9336
9352
|
}
|
9337
9353
|
function getTypeOfDictionary(node, flags, inferenceContext) {
|
9338
9354
|
var _a;
|
9339
|
-
if ((flags & 256 /*
|
9340
|
-
((_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 */) {
|
9341
9356
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
9342
9357
|
diag.addMessage(localize_1.LocAddendum.useDictInstead());
|
9343
9358
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.dictInAnnotation() + diag.getString(), node);
|
@@ -9376,7 +9391,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9376
9391
|
return result;
|
9377
9392
|
}
|
9378
9393
|
}
|
9379
|
-
const result = getTypeOfDictionaryInferred(node, flags, /* hasExpectedType */ !!inferenceContext);
|
9394
|
+
const result = getTypeOfDictionaryInferred(node, flags, /* hasExpectedType */ !!(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType));
|
9380
9395
|
return { ...result, expectedTypeDiagAddendum };
|
9381
9396
|
}
|
9382
9397
|
function getTypeOfDictionaryWithContext(node, flags, inferenceContext, expectedDiagAddendum) {
|
@@ -9431,7 +9446,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9431
9446
|
return undefined;
|
9432
9447
|
}
|
9433
9448
|
const dictTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(builtInDict));
|
9434
|
-
if (!(0, constraintSolver_1.
|
9449
|
+
if (!(0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, builtInDict, inferenceContext.expectedType, dictTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
|
9435
9450
|
return undefined;
|
9436
9451
|
}
|
9437
9452
|
const specializedDict = (0, typeUtils_1.applySolvedTypeVars)(types_1.ClassType.cloneAsInstantiable(builtInDict), dictTypeVarContext);
|
@@ -9532,16 +9547,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9532
9547
|
let typeErrors = false;
|
9533
9548
|
// Mask out some of the flags that are not applicable for a dictionary key
|
9534
9549
|
// even if it appears within an inlined TypedDict annotation.
|
9535
|
-
const keyFlags = flags &
|
9536
|
-
~(256 /* EvaluatorFlags.ExpectingTypeAnnotation */ |
|
9537
|
-
8 /* EvaluatorFlags.EvaluateStringLiteralAsType */ |
|
9538
|
-
128 /* EvaluatorFlags.ExpectingInstantiableType */);
|
9550
|
+
const keyFlags = flags & ~(256 /* EvalFlags.TypeExpression */ | 8 /* EvalFlags.StrLiteralAsType */ | 128 /* EvalFlags.InstantiableType */);
|
9539
9551
|
// Infer the key and value types if possible.
|
9540
9552
|
node.entries.forEach((entryNode, index) => {
|
9541
9553
|
var _a, _b, _c;
|
9542
9554
|
let addUnknown = true;
|
9543
9555
|
if (entryNode.nodeType === 20 /* ParseNodeType.DictionaryKeyEntry */) {
|
9544
|
-
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)));
|
9545
9557
|
if (keyTypeResult.isIncomplete) {
|
9546
9558
|
isIncomplete = true;
|
9547
9559
|
}
|
@@ -9564,12 +9576,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9564
9576
|
expectedTypedDictEntries.knownItems.has(keyType.literalValue)) {
|
9565
9577
|
const effectiveValueType = expectedTypedDictEntries.knownItems.get(keyType.literalValue).valueType;
|
9566
9578
|
entryInferenceContext = (0, typeUtils_1.makeInferenceContext)(effectiveValueType);
|
9567
|
-
valueTypeResult = getTypeOfExpression(entryNode.valueExpression, flags | 268435456 /*
|
9579
|
+
valueTypeResult = getTypeOfExpression(entryNode.valueExpression, flags | 268435456 /* EvalFlags.StripTupleLiterals */, entryInferenceContext);
|
9568
9580
|
}
|
9569
9581
|
else {
|
9570
9582
|
const effectiveValueType = expectedValueType !== null && expectedValueType !== void 0 ? expectedValueType : (forceStrictInference ? types_1.NeverType.createNever() : undefined);
|
9571
9583
|
entryInferenceContext = (0, typeUtils_1.makeInferenceContext)(effectiveValueType);
|
9572
|
-
valueTypeResult = getTypeOfExpression(entryNode.valueExpression, flags | 268435456 /*
|
9584
|
+
valueTypeResult = getTypeOfExpression(entryNode.valueExpression, flags | 268435456 /* EvalFlags.StripTupleLiterals */, entryInferenceContext);
|
9573
9585
|
}
|
9574
9586
|
if (entryInferenceContext && !valueTypeResult.typeErrors) {
|
9575
9587
|
const fromExpectedType = inferTypeArgFromExpectedEntryType(entryInferenceContext, [valueTypeResult.type], !isValueTypeInvariant);
|
@@ -9611,7 +9623,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9611
9623
|
}
|
9612
9624
|
}
|
9613
9625
|
const entryInferenceContext = (0, typeUtils_1.makeInferenceContext)(expectedType);
|
9614
|
-
let unexpandedTypeResult = getTypeOfExpression(entryNode.expandExpression, flags | 268435456 /*
|
9626
|
+
let unexpandedTypeResult = getTypeOfExpression(entryNode.expandExpression, flags | 268435456 /* EvalFlags.StripTupleLiterals */, entryInferenceContext);
|
9615
9627
|
if (entryInferenceContext && !unexpandedTypeResult.typeErrors) {
|
9616
9628
|
const fromExpectedType = inferTypeArgFromExpectedEntryType(entryInferenceContext, [unexpandedTypeResult.type], !isValueTypeInvariant);
|
9617
9629
|
if (fromExpectedType) {
|
@@ -9675,7 +9687,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9675
9687
|
}
|
9676
9688
|
}
|
9677
9689
|
else if (entryNode.nodeType === 11 /* ParseNodeType.Comprehension */) {
|
9678
|
-
const dictEntryTypeResult = getElementTypeFromComprehension(entryNode, flags | 268435456 /*
|
9690
|
+
const dictEntryTypeResult = getElementTypeFromComprehension(entryNode, flags | 268435456 /* EvalFlags.StripTupleLiterals */, expectedValueType, expectedKeyType);
|
9679
9691
|
const dictEntryType = dictEntryTypeResult.type;
|
9680
9692
|
if (dictEntryTypeResult.isIncomplete) {
|
9681
9693
|
isIncomplete = true;
|
@@ -9706,16 +9718,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9706
9718
|
}
|
9707
9719
|
function getTypeOfListOrSet(node, flags, inferenceContext) {
|
9708
9720
|
var _a;
|
9709
|
-
if ((flags & 256 /*
|
9721
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0 &&
|
9710
9722
|
node.nodeType === 34 /* ParseNodeType.List */ &&
|
9711
9723
|
((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== 1 /* ParseNodeType.Argument */) {
|
9712
9724
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
9713
9725
|
diag.addMessage(localize_1.LocAddendum.useListInstead());
|
9714
9726
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.listInAnnotation() + diag.getString(), node);
|
9715
9727
|
}
|
9716
|
-
flags &= ~(256 /*
|
9717
|
-
8 /* EvaluatorFlags.EvaluateStringLiteralAsType */ |
|
9718
|
-
128 /* EvaluatorFlags.ExpectingInstantiableType */);
|
9728
|
+
flags &= ~(256 /* EvalFlags.TypeExpression */ | 8 /* EvalFlags.StrLiteralAsType */ | 128 /* EvalFlags.InstantiableType */);
|
9719
9729
|
// If the expected type is a union, recursively call for each of the subtypes
|
9720
9730
|
// to find one that matches.
|
9721
9731
|
let effectiveExpectedType = inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType;
|
@@ -9751,7 +9761,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9751
9761
|
expectedTypeDiagAddendum = result === null || result === void 0 ? void 0 : result.expectedTypeDiagAddendum;
|
9752
9762
|
}
|
9753
9763
|
const typeResult = getTypeOfListOrSetInferred(node, flags,
|
9754
|
-
/* hasExpectedType */ inferenceContext
|
9764
|
+
/* hasExpectedType */ !!(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType));
|
9755
9765
|
return { ...typeResult, expectedTypeDiagAddendum };
|
9756
9766
|
}
|
9757
9767
|
// Attempts to determine the type of a list or set statement based on an expected type.
|
@@ -9771,10 +9781,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9771
9781
|
node.entries.forEach((entry) => {
|
9772
9782
|
let entryTypeResult;
|
9773
9783
|
if (entry.nodeType === 11 /* ParseNodeType.Comprehension */) {
|
9774
|
-
entryTypeResult = getElementTypeFromComprehension(entry, flags | 268435456 /*
|
9784
|
+
entryTypeResult = getElementTypeFromComprehension(entry, flags | 268435456 /* EvalFlags.StripTupleLiterals */, expectedEntryType);
|
9775
9785
|
}
|
9776
9786
|
else {
|
9777
|
-
entryTypeResult = getTypeOfExpression(entry, flags | 268435456 /*
|
9787
|
+
entryTypeResult = getTypeOfExpression(entry, flags | 268435456 /* EvalFlags.StripTupleLiterals */, (0, typeUtils_1.makeInferenceContext)(expectedEntryType));
|
9778
9788
|
}
|
9779
9789
|
entryTypes.push(entryTypeResult.type);
|
9780
9790
|
if (entryTypeResult.isIncomplete) {
|
@@ -9818,7 +9828,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9818
9828
|
return undefined;
|
9819
9829
|
}
|
9820
9830
|
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(expectedClassType));
|
9821
|
-
if (!(0, constraintSolver_1.
|
9831
|
+
if (!(0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(expectedClassType), inferenceContext.expectedType, typeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
|
9822
9832
|
return undefined;
|
9823
9833
|
}
|
9824
9834
|
const specializedListOrSet = (0, typeUtils_1.applySolvedTypeVars)(expectedClassType, typeVarContext);
|
@@ -9838,10 +9848,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9838
9848
|
node.entries.forEach((entry, index) => {
|
9839
9849
|
let entryTypeResult;
|
9840
9850
|
if (entry.nodeType === 11 /* ParseNodeType.Comprehension */ && !entry.isGenerator) {
|
9841
|
-
entryTypeResult = getElementTypeFromComprehension(entry, flags | 268435456 /*
|
9851
|
+
entryTypeResult = getElementTypeFromComprehension(entry, flags | 268435456 /* EvalFlags.StripTupleLiterals */);
|
9842
9852
|
}
|
9843
9853
|
else {
|
9844
|
-
entryTypeResult = getTypeOfExpression(entry, flags | 268435456 /*
|
9854
|
+
entryTypeResult = getTypeOfExpression(entry, flags | 268435456 /* EvalFlags.StripTupleLiterals */);
|
9845
9855
|
}
|
9846
9856
|
if (entryTypeResult.isIncomplete) {
|
9847
9857
|
isIncomplete = true;
|
@@ -9849,7 +9859,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9849
9859
|
if (entryTypeResult.typeErrors) {
|
9850
9860
|
typeErrors = true;
|
9851
9861
|
}
|
9852
|
-
if (index < maxEntriesToUseForInference) {
|
9862
|
+
if (hasExpectedType || index < maxEntriesToUseForInference) {
|
9853
9863
|
entryTypes.push(entryTypeResult.type);
|
9854
9864
|
}
|
9855
9865
|
if (verifyHashable && !entryTypeResult.isIncomplete && !entryTypeResult.typeErrors) {
|
@@ -10037,7 +10047,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10037
10047
|
return (0, cancellationUtils_1.invalidateTypeCacheIfCanceled)(() => {
|
10038
10048
|
// Pre-cache the incomplete function type in case the evaluation of the
|
10039
10049
|
// lambda depends on itself.
|
10040
|
-
writeTypeCache(node, { type: functionType, isIncomplete: true }, 0 /*
|
10050
|
+
writeTypeCache(node, { type: functionType, isIncomplete: true }, 0 /* EvalFlags.None */);
|
10041
10051
|
// We assume for simplicity that the parameter signature of the lambda is
|
10042
10052
|
// the same as the expected type. If this isn't the case, we'll use
|
10043
10053
|
// object for any lambda parameters that don't match. We could make this
|
@@ -10074,11 +10084,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10074
10084
|
paramType = inferParameterTypeFromDefaultValue(param.defaultValue);
|
10075
10085
|
}
|
10076
10086
|
if (param.name) {
|
10077
|
-
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 */);
|
10078
10088
|
}
|
10079
10089
|
if (param.defaultValue) {
|
10080
10090
|
// Evaluate the default value if it's present.
|
10081
|
-
getTypeOfExpression(param.defaultValue, 1 /*
|
10091
|
+
getTypeOfExpression(param.defaultValue, 1 /* EvalFlags.ConvertEllipsisToAny */);
|
10082
10092
|
}
|
10083
10093
|
// Determine whether we need to insert an implied position-only parameter.
|
10084
10094
|
// This is needed when a function's parameters are named using the old-style
|
@@ -10179,7 +10189,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10179
10189
|
}
|
10180
10190
|
const builtInIteratorType = getTypingType(node, isAsync ? 'AsyncGenerator' : 'Generator');
|
10181
10191
|
const expectedEntryType = getExpectedEntryTypeForIterable(node, builtInIteratorType, inferenceContext);
|
10182
|
-
const elementTypeResult = getElementTypeFromComprehension(node, flags | 268435456 /*
|
10192
|
+
const elementTypeResult = getElementTypeFromComprehension(node, flags | 268435456 /* EvalFlags.StripTupleLiterals */, expectedEntryType);
|
10183
10193
|
if (elementTypeResult.isIncomplete) {
|
10184
10194
|
isIncomplete = true;
|
10185
10195
|
}
|
@@ -10496,7 +10506,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10496
10506
|
// If no type arguments are provided, the resulting type
|
10497
10507
|
// depends on whether we're evaluating a type annotation or
|
10498
10508
|
// we're in some other context.
|
10499
|
-
if ((flags & 256 /*
|
10509
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
10500
10510
|
addError(localize_1.LocMessage.optionalExtraArgs(), errorNode);
|
10501
10511
|
return types_1.UnknownType.create();
|
10502
10512
|
}
|
@@ -10510,10 +10520,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10510
10520
|
if (!validateTypeArg(typeArgs[0])) {
|
10511
10521
|
typeArg0Type = types_1.UnknownType.create();
|
10512
10522
|
}
|
10513
|
-
else if (!(0, typeUtils_1.isEffectivelyInstantiable)(typeArg0Type)) {
|
10514
|
-
addExpectedClassDiagnostic(typeArg0Type, typeArgs[0].node);
|
10515
|
-
typeArg0Type = types_1.UnknownType.create();
|
10516
|
-
}
|
10517
10523
|
let optionalType = (0, types_1.combineTypes)([typeArg0Type, noneTypeClass !== null && noneTypeClass !== void 0 ? noneTypeClass : types_1.UnknownType.create()]);
|
10518
10524
|
if (unionTypeClass && (0, types_1.isInstantiableClass)(unionTypeClass)) {
|
10519
10525
|
optionalType = types_1.TypeBase.cloneAsSpecialForm(optionalType, types_1.ClassType.cloneAsInstance(unionTypeClass));
|
@@ -10599,7 +10605,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10599
10605
|
}
|
10600
10606
|
}
|
10601
10607
|
if (!type) {
|
10602
|
-
const exprType = getTypeOfExpression(itemExpr, flags & 4 /*
|
10608
|
+
const exprType = getTypeOfExpression(itemExpr, (flags & 4 /* EvalFlags.ForwardRefs */) | 33554432 /* EvalFlags.NoConvertSpecialForm */ | 256 /* EvalFlags.TypeExpression */);
|
10603
10609
|
// Is this an enum type?
|
10604
10610
|
if ((0, types_1.isClassInstance)(exprType.type) &&
|
10605
10611
|
types_1.ClassType.isEnumClass(exprType.type) &&
|
@@ -10636,7 +10642,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10636
10642
|
// Creates a ClassVar type.
|
10637
10643
|
function createClassVarType(classType, errorNode, typeArgs, flags) {
|
10638
10644
|
var _a;
|
10639
|
-
if (flags & 131072 /*
|
10645
|
+
if (flags & 131072 /* EvalFlags.NoClassVar */) {
|
10640
10646
|
addError(localize_1.LocMessage.classVarNotAllowed(), errorNode);
|
10641
10647
|
return types_1.AnyType.create();
|
10642
10648
|
}
|
@@ -10668,7 +10674,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10668
10674
|
// depends on whether we're evaluating a type annotation or
|
10669
10675
|
// we're in some other context.
|
10670
10676
|
if (!typeArgs) {
|
10671
|
-
if ((flags & 256 /*
|
10677
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
10672
10678
|
addError(localize_1.LocMessage.typeGuardArgCount(), errorNode);
|
10673
10679
|
}
|
10674
10680
|
return classType;
|
@@ -10699,7 +10705,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10699
10705
|
}
|
10700
10706
|
const enclosingClassTypeResult = enclosingClass ? getTypeOfClass(enclosingClass) : undefined;
|
10701
10707
|
if (!enclosingClassTypeResult) {
|
10702
|
-
if ((flags & (256 /*
|
10708
|
+
if ((flags & (256 /* EvalFlags.TypeExpression */ | 128 /* EvalFlags.InstantiableType */)) !== 0) {
|
10703
10709
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.selfTypeContext(), errorNode);
|
10704
10710
|
}
|
10705
10711
|
return types_1.UnknownType.create();
|
@@ -10740,7 +10746,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10740
10746
|
// If no type arguments are provided, the resulting type
|
10741
10747
|
// depends on whether we're evaluating a type annotation or
|
10742
10748
|
// we're in some other context.
|
10743
|
-
if (!typeArgs && (flags & 256 /*
|
10749
|
+
if (!typeArgs && (flags & 256 /* EvalFlags.TypeExpression */) === 0) {
|
10744
10750
|
return { type: classType };
|
10745
10751
|
}
|
10746
10752
|
if (!typeArgs || typeArgs.length !== 1) {
|
@@ -10764,7 +10770,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10764
10770
|
isUsageLegal = true;
|
10765
10771
|
}
|
10766
10772
|
}
|
10767
|
-
if ((flags & 1048576 /*
|
10773
|
+
if ((flags & 1048576 /* EvalFlags.AllowRequired */) !== 0) {
|
10768
10774
|
isUsageLegal = true;
|
10769
10775
|
}
|
10770
10776
|
let isReadOnly = typeArgs[0].isReadOnly;
|
@@ -10799,7 +10805,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10799
10805
|
// If no type arguments are provided, the resulting type
|
10800
10806
|
// depends on whether we're evaluating a type annotation or
|
10801
10807
|
// we're in some other context.
|
10802
|
-
if (!typeArgs && (flags & 256 /*
|
10808
|
+
if (!typeArgs && (flags & 256 /* EvalFlags.TypeExpression */) === 0) {
|
10803
10809
|
return classType;
|
10804
10810
|
}
|
10805
10811
|
if (!typeArgs || typeArgs.length !== 1) {
|
@@ -10810,7 +10816,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10810
10816
|
if ((0, types_1.isUnion)(typeArgType) && typeArgType.subtypes.length === 1) {
|
10811
10817
|
typeArgType = typeArgType.subtypes[0];
|
10812
10818
|
}
|
10813
|
-
if ((flags & 2097152 /*
|
10819
|
+
if ((flags & 2097152 /* EvalFlags.AllowUnpackedTuple */) !== 0) {
|
10814
10820
|
if ((0, types_1.isInstantiableClass)(typeArgType) && !typeArgType.includeSubclasses && (0, typeUtils_1.isTupleClass)(typeArgType)) {
|
10815
10821
|
return types_1.ClassType.cloneForUnpacked(typeArgType);
|
10816
10822
|
}
|
@@ -10820,7 +10826,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10820
10826
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.unpackExpectedTypeVarTuple(), errorNode);
|
10821
10827
|
return types_1.UnknownType.create();
|
10822
10828
|
}
|
10823
|
-
if ((flags &
|
10829
|
+
if ((flags & 4194304 /* EvalFlags.AllowUnpackedTypedDict */) !== 0) {
|
10824
10830
|
if ((0, types_1.isInstantiableClass)(typeArgType) && types_1.ClassType.isTypedDictClass(typeArgType)) {
|
10825
10831
|
return types_1.ClassType.cloneForUnpacked(typeArgType);
|
10826
10832
|
}
|
@@ -10832,7 +10838,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10832
10838
|
}
|
10833
10839
|
// Creates a "Final" type.
|
10834
10840
|
function createFinalType(classType, errorNode, typeArgs, flags) {
|
10835
|
-
if (flags & 16 /*
|
10841
|
+
if (flags & 16 /* EvalFlags.NoFinal */) {
|
10836
10842
|
addError(localize_1.LocMessage.finalContext(), errorNode);
|
10837
10843
|
return classType;
|
10838
10844
|
}
|
@@ -10845,7 +10851,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10845
10851
|
return types_1.TypeBase.cloneAsSpecialForm(typeArgs[0].type, classType);
|
10846
10852
|
}
|
10847
10853
|
function createConcatenateType(classType, errorNode, typeArgs, flags) {
|
10848
|
-
if ((flags & 134217728 /*
|
10854
|
+
if ((flags & 134217728 /* EvalFlags.AllowConcatenate */) === 0) {
|
10849
10855
|
addError(localize_1.LocMessage.concatenateContext(), errorNode);
|
10850
10856
|
return types_1.AnyType.create();
|
10851
10857
|
}
|
@@ -10874,7 +10880,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10874
10880
|
}
|
10875
10881
|
return createSpecialType(classType, typeArgs, /* paramLimit */ undefined, /* allowParamSpec */ true);
|
10876
10882
|
}
|
10877
|
-
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
|
+
}
|
10878
10888
|
if (typeArgs) {
|
10879
10889
|
if (typeArgs.length < 2) {
|
10880
10890
|
addError(localize_1.LocMessage.annotatedTypeArgMissing(), errorNode);
|
@@ -11060,7 +11070,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11060
11070
|
// If no type arguments are provided, the resulting type
|
11061
11071
|
// depends on whether we're evaluating a type annotation or
|
11062
11072
|
// we're in some other context.
|
11063
|
-
if ((flags & 256 /*
|
11073
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
11064
11074
|
addError(localize_1.LocMessage.unionTypeArgCount(), errorNode);
|
11065
11075
|
return types_1.NeverType.createNever();
|
11066
11076
|
}
|
@@ -11074,10 +11084,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11074
11084
|
})) {
|
11075
11085
|
typeArgType = types_1.UnknownType.create();
|
11076
11086
|
}
|
11077
|
-
else if (!(0, typeUtils_1.isEffectivelyInstantiable)(typeArgType)) {
|
11078
|
-
addExpectedClassDiagnostic(typeArgType, typeArg.node);
|
11079
|
-
typeArgType = types_1.UnknownType.create();
|
11080
|
-
}
|
11081
11087
|
// If this is an unpacked tuple, explode out the individual items.
|
11082
11088
|
if ((0, types_1.isUnpackedClass)(typeArg.type) && typeArg.type.tupleTypeArguments) {
|
11083
11089
|
// This is an experimental feature because Unions of unpacked TypeVarTuples are not officially supported.
|
@@ -11128,7 +11134,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11128
11134
|
// If no type arguments are provided, the resulting type
|
11129
11135
|
// depends on whether we're evaluating a type annotation or
|
11130
11136
|
// we're in some other context.
|
11131
|
-
if ((flags & (256 /*
|
11137
|
+
if ((flags & (256 /* EvalFlags.TypeExpression */ | 262144 /* EvalFlags.NoNakedGeneric */)) !== 0) {
|
11132
11138
|
addError(localize_1.LocMessage.genericTypeArgMissing(), errorNode);
|
11133
11139
|
}
|
11134
11140
|
return classType;
|
@@ -11238,6 +11244,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11238
11244
|
if (aliasMapEntry.isSpecialForm) {
|
11239
11245
|
specialClassType.details.flags |= 8388608 /* ClassTypeFlags.SpecialFormClass */;
|
11240
11246
|
}
|
11247
|
+
if (aliasMapEntry.isIllegalInIsinstance) {
|
11248
|
+
specialClassType.details.flags |= 16777216 /* ClassTypeFlags.IllegalIsinstanceClass */;
|
11249
|
+
}
|
11241
11250
|
// Synthesize a single type parameter with the specified variance if
|
11242
11251
|
// specified in the alias map entry.
|
11243
11252
|
if (aliasMapEntry.typeParamVariance !== undefined) {
|
@@ -11313,7 +11322,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11313
11322
|
['TypedDict', { alias: '_TypedDict', module: 'self' }],
|
11314
11323
|
['Union', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11315
11324
|
['Optional', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11316
|
-
['Annotated', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11325
|
+
['Annotated', { alias: '', module: 'builtins', isSpecialForm: true, isIllegalInIsinstance: true }],
|
11317
11326
|
['TypeAlias', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11318
11327
|
['Concatenate', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11319
11328
|
[
|
@@ -11332,7 +11341,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11332
11341
|
]);
|
11333
11342
|
const aliasMapEntry = specialTypes.get(assignedName);
|
11334
11343
|
if (aliasMapEntry) {
|
11335
|
-
const cachedType = readTypeCache(node, 0 /*
|
11344
|
+
const cachedType = readTypeCache(node, 0 /* EvalFlags.None */);
|
11336
11345
|
if (cachedType) {
|
11337
11346
|
(0, debug_1.assert)((0, types_1.isInstantiableClass)(cachedType));
|
11338
11347
|
return cachedType;
|
@@ -11344,7 +11353,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11344
11353
|
specialType.details.baseClasses.push(strClass !== null && strClass !== void 0 ? strClass : types_1.AnyType.create());
|
11345
11354
|
(0, typeUtils_1.computeMroLinearization)(specialType);
|
11346
11355
|
}
|
11347
|
-
writeTypeCache(node, { type: specialType }, 0 /*
|
11356
|
+
writeTypeCache(node, { type: specialType }, 0 /* EvalFlags.None */);
|
11348
11357
|
return specialType;
|
11349
11358
|
}
|
11350
11359
|
return undefined;
|
@@ -11393,30 +11402,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11393
11402
|
if (isTypeCached(node)) {
|
11394
11403
|
return;
|
11395
11404
|
}
|
11396
|
-
let flags = 0 /*
|
11405
|
+
let flags = 0 /* EvalFlags.None */;
|
11397
11406
|
if (fileInfo.isStubFile) {
|
11398
11407
|
// An assignment of ellipsis means "Any" within a type stub file.
|
11399
|
-
flags |= 1 /*
|
11408
|
+
flags |= 1 /* EvalFlags.ConvertEllipsisToAny */;
|
11400
11409
|
}
|
11401
11410
|
if (node.rightExpression.nodeType === 38 /* ParseNodeType.Name */ ||
|
11402
11411
|
node.rightExpression.nodeType === 35 /* ParseNodeType.MemberAccess */) {
|
11403
11412
|
// Don't specialize a generic class on assignment (e.g. "x = list"
|
11404
11413
|
// or "x = collections.OrderedDict") because we may want to later
|
11405
11414
|
// specialize it (e.g. "x[int]").
|
11406
|
-
flags |= 2 /*
|
11407
|
-
}
|
11408
|
-
if (isDeclaredTypeAlias(node.leftExpression)) {
|
11409
|
-
flags |=
|
11410
|
-
128 /* EvaluatorFlags.ExpectingInstantiableType */ |
|
11411
|
-
256 /* EvaluatorFlags.ExpectingTypeAnnotation */ |
|
11412
|
-
8 /* EvaluatorFlags.EvaluateStringLiteralAsType */ |
|
11413
|
-
32 /* EvaluatorFlags.DisallowParamSpec */ |
|
11414
|
-
64 /* EvaluatorFlags.DisallowTypeVarTuple */ |
|
11415
|
-
131072 /* EvaluatorFlags.DisallowClassVar */;
|
11416
|
-
flags &= ~2 /* EvaluatorFlags.DoNotSpecialize */;
|
11415
|
+
flags |= 2 /* EvalFlags.NoSpecialize */;
|
11417
11416
|
}
|
11418
11417
|
// Is this type already cached?
|
11419
|
-
let rightHandType = readTypeCache(node.rightExpression, flags);
|
11418
|
+
let rightHandType = readTypeCache(node.rightExpression, /* flags */ undefined);
|
11420
11419
|
let isIncomplete = false;
|
11421
11420
|
let expectedTypeDiagAddendum;
|
11422
11421
|
if (!rightHandType) {
|
@@ -11425,89 +11424,94 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11425
11424
|
if (fileInfo.isTypingStubFile || fileInfo.isTypingExtensionsStubFile) {
|
11426
11425
|
rightHandType = handleTypingStubAssignment(node);
|
11427
11426
|
if (rightHandType) {
|
11428
|
-
writeTypeCache(node.rightExpression, { type: rightHandType }, 0 /*
|
11427
|
+
writeTypeCache(node.rightExpression, { type: rightHandType }, 0 /* EvalFlags.None */);
|
11429
11428
|
}
|
11430
11429
|
}
|
11431
|
-
|
11432
|
-
|
11433
|
-
|
11434
|
-
|
11435
|
-
|
11436
|
-
|
11437
|
-
|
11438
|
-
|
11439
|
-
|
11440
|
-
|
11441
|
-
|
11442
|
-
|
11443
|
-
|
11444
|
-
|
11445
|
-
|
11446
|
-
|
11447
|
-
|
11448
|
-
|
11449
|
-
|
11430
|
+
}
|
11431
|
+
if (!rightHandType) {
|
11432
|
+
// Determine whether there is a declared type.
|
11433
|
+
const declaredType = getDeclaredTypeForExpression(node.leftExpression, { method: 'set' });
|
11434
|
+
let typeAliasNameNode;
|
11435
|
+
let typeAliasPlaceholder;
|
11436
|
+
let isSpeculativeTypeAlias = false;
|
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 */;
|
11445
|
+
typeAliasNameNode = node.leftExpression.valueExpression;
|
11446
|
+
if (!isLegalTypeAliasExpressionForm(node.rightExpression)) {
|
11447
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeAliasIllegalExpressionForm(), node.rightExpression);
|
11448
|
+
}
|
11449
|
+
}
|
11450
|
+
else if (node.leftExpression.nodeType === 38 /* ParseNodeType.Name */) {
|
11451
|
+
const symbolWithScope = lookUpSymbolRecursive(node.leftExpression, node.leftExpression.value,
|
11452
|
+
/* honorCodeFlow */ false);
|
11453
|
+
if (symbolWithScope) {
|
11454
|
+
const decls = symbolWithScope.symbol.getDeclarations();
|
11455
|
+
if (decls.length === 1) {
|
11456
|
+
if (isPossibleTypeAliasDeclaration(decls[0])) {
|
11450
11457
|
typeAliasNameNode = node.leftExpression;
|
11451
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;
|
11452
11465
|
}
|
11453
11466
|
}
|
11454
11467
|
}
|
11455
|
-
|
11456
|
-
|
11457
|
-
|
11458
|
-
|
11459
|
-
|
11460
|
-
|
11461
|
-
|
11462
|
-
|
11463
|
-
typeAliasTypeVar.details.recursiveTypeAliasScopeId = scopeId;
|
11464
|
-
typeAliasTypeVar.details.recursiveTypeAliasIsPep695Syntax = false;
|
11465
|
-
typeAliasTypeVar.scopeId = scopeId;
|
11466
|
-
// Write the type back to the type cache. It will be replaced below.
|
11467
|
-
writeTypeCache(node, { type: typeAliasTypeVar }, /* flags */ undefined);
|
11468
|
-
writeTypeCache(node.leftExpression, { type: typeAliasTypeVar }, /* flags */ undefined);
|
11469
|
-
if (node.leftExpression.nodeType === 54 /* ParseNodeType.TypeAnnotation */) {
|
11470
|
-
writeTypeCache(node.leftExpression.valueExpression, { type: typeAliasTypeVar },
|
11471
|
-
/* flags */ undefined);
|
11472
|
-
}
|
11473
|
-
}
|
11474
|
-
const srcTypeResult = getTypeOfExpression(node.rightExpression, flags, (0, typeUtils_1.makeInferenceContext)(declaredType));
|
11475
|
-
let srcType = srcTypeResult.type;
|
11476
|
-
expectedTypeDiagAddendum = srcTypeResult.expectedTypeDiagAddendum;
|
11477
|
-
if (srcTypeResult.isIncomplete) {
|
11478
|
-
isIncomplete = true;
|
11468
|
+
}
|
11469
|
+
if (typeAliasNameNode) {
|
11470
|
+
typeAliasPlaceholder = synthesizeTypeAliasPlaceholder(typeAliasNameNode);
|
11471
|
+
writeTypeCache(node, { type: typeAliasPlaceholder }, /* flags */ undefined);
|
11472
|
+
writeTypeCache(node.leftExpression, { type: typeAliasPlaceholder }, /* flags */ undefined);
|
11473
|
+
if (node.leftExpression.nodeType === 54 /* ParseNodeType.TypeAnnotation */) {
|
11474
|
+
writeTypeCache(node.leftExpression.valueExpression, { type: typeAliasPlaceholder },
|
11475
|
+
/* flags */ undefined);
|
11479
11476
|
}
|
11477
|
+
}
|
11478
|
+
const srcTypeResult = getTypeOfExpression(node.rightExpression, flags, (0, typeUtils_1.makeInferenceContext)(declaredType));
|
11479
|
+
rightHandType = srcTypeResult.type;
|
11480
|
+
expectedTypeDiagAddendum = srcTypeResult.expectedTypeDiagAddendum;
|
11481
|
+
if (srcTypeResult.isIncomplete) {
|
11482
|
+
isIncomplete = true;
|
11483
|
+
}
|
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;
|
11488
|
+
}
|
11489
|
+
if (typeAliasNameNode) {
|
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 {
|
11480
11509
|
// If the RHS is a constant boolean expression, assign it a literal type.
|
11481
11510
|
const constExprValue = (0, staticExpressions_1.evaluateStaticBoolExpression)(node.rightExpression, fileInfo.executionEnvironment, fileInfo.definedConstants);
|
11482
11511
|
if (constExprValue !== undefined) {
|
11483
11512
|
const boolType = getBuiltInObject(node, 'bool');
|
11484
11513
|
if ((0, types_1.isClassInstance)(boolType)) {
|
11485
|
-
|
11486
|
-
}
|
11487
|
-
}
|
11488
|
-
// If this is an enum, transform the type as required.
|
11489
|
-
rightHandType = srcType;
|
11490
|
-
if (typeAliasNameNode) {
|
11491
|
-
// If this was a speculative type alias, it becomes a real type alias
|
11492
|
-
// only if the evaluated type is an instantiable type.
|
11493
|
-
if (!isSpeculativeTypeAlias || isLegalImplicitTypeAliasType(rightHandType)) {
|
11494
|
-
// If this is a type alias, record its name based on the assignment target.
|
11495
|
-
rightHandType = transformTypeForTypeAlias(rightHandType, typeAliasNameNode, typeAliasNameNode,
|
11496
|
-
/* isPep695Syntax */ false,
|
11497
|
-
/* isPep695TypeVarType */ false);
|
11498
|
-
(0, debug_1.assert)(typeAliasTypeVar !== undefined);
|
11499
|
-
if ((0, typeUtils_1.isTypeAliasRecursive)(typeAliasTypeVar, rightHandType)) {
|
11500
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasIsRecursiveDirect().format({
|
11501
|
-
name: typeAliasNameNode.value,
|
11502
|
-
}), node.rightExpression);
|
11503
|
-
rightHandType = types_1.UnknownType.create();
|
11504
|
-
}
|
11505
|
-
// Set the resulting type to the boundType of the original type alias
|
11506
|
-
// to support recursive type aliases.
|
11507
|
-
typeAliasTypeVar.details.boundType = rightHandType;
|
11508
|
-
// Record the type parameters within the recursive type alias so it
|
11509
|
-
// can be specialized.
|
11510
|
-
typeAliasTypeVar.details.recursiveTypeParameters = (_a = rightHandType.typeAliasInfo) === null || _a === void 0 ? void 0 : _a.typeParameters;
|
11514
|
+
rightHandType = types_1.ClassType.cloneWithLiteral(boolType, constExprValue);
|
11511
11515
|
}
|
11512
11516
|
}
|
11513
11517
|
}
|
@@ -11515,34 +11519,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11515
11519
|
assignTypeToExpression(node.leftExpression, { type: rightHandType, isIncomplete }, node.rightExpression,
|
11516
11520
|
/* ignoreEmptyContainers */ true,
|
11517
11521
|
/* allowAssignmentToFinalVar */ true, expectedTypeDiagAddendum);
|
11518
|
-
writeTypeCache(node, { type: rightHandType, isIncomplete }, 0 /*
|
11519
|
-
}
|
11520
|
-
|
11521
|
-
|
11522
|
-
|
11523
|
-
|
11524
|
-
|
11525
|
-
|
11526
|
-
|
11527
|
-
|
11528
|
-
|
11529
|
-
|
11530
|
-
|
11531
|
-
// a call to the TypedDict call. This avoids the expensive (and potentially
|
11532
|
-
// recursive) call to getTypeOfExpression in cases where it's not needed.
|
11533
|
-
if ((callLeftNode.nodeType === 38 /* ParseNodeType.Name */ && callLeftNode.value) === 'TypedDict' ||
|
11534
|
-
(callLeftNode.nodeType === 35 /* ParseNodeType.MemberAccess */ &&
|
11535
|
-
callLeftNode.memberName.value === 'TypedDict' &&
|
11536
|
-
callLeftNode.leftExpression.nodeType === 38 /* ParseNodeType.Name */)) {
|
11537
|
-
// See if this is a call to TypedDict. We want to support
|
11538
|
-
// recursive type references in a TypedDict call.
|
11539
|
-
const callType = getTypeOfExpression(callLeftNode, 2 /* EvaluatorFlags.CallBaseDefaults */).type;
|
11540
|
-
if ((0, types_1.isInstantiableClass)(callType) && types_1.ClassType.isBuiltIn(callType, 'TypedDict')) {
|
11541
|
-
return true;
|
11542
|
-
}
|
11543
|
-
}
|
11544
|
-
}
|
11545
|
-
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;
|
11546
11535
|
}
|
11547
11536
|
// Evaluates the type of a type alias (i.e. "type") statement. This code
|
11548
11537
|
// path does not handle traditional type aliases, which are treated as
|
@@ -11560,20 +11549,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11560
11549
|
// This function is common to the handling of "type" statements and explicit
|
11561
11550
|
// calls to the TypeAliasType constructor.
|
11562
11551
|
function getTypeOfTypeAliasCommon(declNode, nameNode, valueNode, isPep695Syntax, typeParamNodes, getTypeParamCallback) {
|
11563
|
-
const cachedType = readTypeCache(nameNode, 0 /*
|
11552
|
+
const cachedType = readTypeCache(nameNode, 0 /* EvalFlags.None */);
|
11564
11553
|
if (cachedType) {
|
11565
11554
|
return cachedType;
|
11566
11555
|
}
|
11567
11556
|
// Synthesize a type variable that represents the type alias while we're
|
11568
11557
|
// evaluating it. This allows us to handle recursive definitions.
|
11569
|
-
const typeAliasTypeVar =
|
11570
|
-
|
11571
|
-
typeAliasTypeVar.details.recursiveTypeAliasName = nameNode.value;
|
11572
|
-
const scopeId = ParseTreeUtils.getScopeIdForNode(nameNode);
|
11573
|
-
typeAliasTypeVar.details.recursiveTypeAliasScopeId = scopeId;
|
11574
|
-
typeAliasTypeVar.details.recursiveTypeAliasIsPep695Syntax = isPep695Syntax;
|
11575
|
-
typeAliasTypeVar.scopeId = scopeId;
|
11576
|
-
// 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.
|
11577
11560
|
writeTypeCache(nameNode, { type: typeAliasTypeVar }, /* flags */ undefined);
|
11578
11561
|
// Set a partial type to handle recursive (self-referential) type aliases.
|
11579
11562
|
const scope = ScopeUtils.getScopeForNode(declNode);
|
@@ -11605,7 +11588,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11605
11588
|
// Set the resulting type to the boundType of the original type alias
|
11606
11589
|
// to support recursive type aliases.
|
11607
11590
|
typeAliasTypeVar.details.boundType = aliasType;
|
11608
|
-
writeTypeCache(nameNode, { type: aliasType, isIncomplete }, 0 /*
|
11591
|
+
writeTypeCache(nameNode, { type: aliasType, isIncomplete }, 0 /* EvalFlags.None */);
|
11609
11592
|
return aliasType;
|
11610
11593
|
}
|
11611
11594
|
function evaluateTypesForAugmentedAssignment(node) {
|
@@ -11613,7 +11596,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11613
11596
|
return;
|
11614
11597
|
}
|
11615
11598
|
const destTypeResult = (0, operations_1.getTypeOfAugmentedAssignment)(evaluatorInterface, node, /* inferenceContext */ undefined);
|
11616
|
-
writeTypeCache(node, destTypeResult, 0 /*
|
11599
|
+
writeTypeCache(node, destTypeResult, 0 /* EvalFlags.None */);
|
11617
11600
|
}
|
11618
11601
|
function getPseudoGenericTypeVarName(paramName) {
|
11619
11602
|
return `__type_of_${paramName}`;
|
@@ -11621,7 +11604,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11621
11604
|
function getTypeOfClass(node) {
|
11622
11605
|
initializePrefetchedTypes(node);
|
11623
11606
|
// Is this type already cached?
|
11624
|
-
const cachedClassType = readTypeCache(node.name, 0 /*
|
11607
|
+
const cachedClassType = readTypeCache(node.name, 0 /* EvalFlags.None */);
|
11625
11608
|
if (cachedClassType) {
|
11626
11609
|
if (!(0, types_1.isInstantiableClass)(cachedClassType)) {
|
11627
11610
|
// This can happen in rare circumstances where the class declaration
|
@@ -11630,7 +11613,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11630
11613
|
}
|
11631
11614
|
return {
|
11632
11615
|
classType: cachedClassType,
|
11633
|
-
decoratedType: readTypeCache(node, 0 /*
|
11616
|
+
decoratedType: readTypeCache(node, 0 /* EvalFlags.None */) || types_1.UnknownType.create(),
|
11634
11617
|
};
|
11635
11618
|
}
|
11636
11619
|
// The type wasn't cached, so we need to create a new one.
|
@@ -11695,14 +11678,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11695
11678
|
let isNamedTupleSubclass = false;
|
11696
11679
|
const initSubclassArgs = [];
|
11697
11680
|
let metaclassNode;
|
11698
|
-
let exprFlags = 128 /*
|
11699
|
-
1024 /*
|
11700
|
-
262144 /*
|
11701
|
-
2048 /*
|
11702
|
-
8192 /*
|
11703
|
-
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 */;
|
11704
11687
|
if (fileInfo.isStubFile) {
|
11705
|
-
exprFlags |= 4 /*
|
11688
|
+
exprFlags |= 4 /* EvalFlags.ForwardRefs */;
|
11706
11689
|
}
|
11707
11690
|
node.arguments.forEach((arg) => {
|
11708
11691
|
// Ignore unpacked arguments.
|
@@ -12185,9 +12168,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12185
12168
|
}
|
12186
12169
|
};
|
12187
12170
|
// Update the undecorated class type.
|
12188
|
-
writeTypeCache(node.name, { type: classType }, 0 /*
|
12171
|
+
writeTypeCache(node.name, { type: classType }, 0 /* EvalFlags.None */);
|
12189
12172
|
// Update the decorated class type.
|
12190
|
-
writeTypeCache(node, { type: decoratedType }, 0 /*
|
12173
|
+
writeTypeCache(node, { type: decoratedType }, 0 /* EvalFlags.None */);
|
12191
12174
|
return { classType, decoratedType };
|
12192
12175
|
});
|
12193
12176
|
}
|
@@ -12297,7 +12280,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12297
12280
|
if (!typeOfParam || !(0, types_1.isTypeVar)(typeOfParam)) {
|
12298
12281
|
return;
|
12299
12282
|
}
|
12300
|
-
writeTypeCache(param.name, { type: typeOfParam }, 0 /*
|
12283
|
+
writeTypeCache(param.name, { type: typeOfParam }, 0 /* EvalFlags.None */);
|
12301
12284
|
paramTypes.push(typeOfParam);
|
12302
12285
|
});
|
12303
12286
|
return paramTypes;
|
@@ -12397,7 +12380,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12397
12380
|
deferredClassCompletions.forEach((e) => {
|
12398
12381
|
if (types_1.ClassType.isSameGenericClass(e.dependsUpon, type)) {
|
12399
12382
|
e.classesToComplete.forEach((classNode) => {
|
12400
|
-
const classType = readTypeCache(classNode.name, 0 /*
|
12383
|
+
const classType = readTypeCache(classNode.name, 0 /* EvalFlags.None */);
|
12401
12384
|
if (classType) {
|
12402
12385
|
completeClassTypeDeferred(classType, classNode.name);
|
12403
12386
|
}
|
@@ -12543,7 +12526,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12543
12526
|
function getTypeOfFunction(node) {
|
12544
12527
|
initializePrefetchedTypes(node);
|
12545
12528
|
// Is this predecorated function type cached?
|
12546
|
-
let functionType = readTypeCache(node.name, 0 /*
|
12529
|
+
let functionType = readTypeCache(node.name, 0 /* EvalFlags.None */);
|
12547
12530
|
if (functionType) {
|
12548
12531
|
if (!(0, types_1.isFunction)(functionType)) {
|
12549
12532
|
// This can happen in certain rare circumstances where the
|
@@ -12558,7 +12541,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12558
12541
|
functionType = getTypeOfFunctionPredecorated(node);
|
12559
12542
|
}
|
12560
12543
|
// Is the decorated function type cached?
|
12561
|
-
let decoratedType = readTypeCache(node, 0 /*
|
12544
|
+
let decoratedType = readTypeCache(node, 0 /* EvalFlags.None */);
|
12562
12545
|
if (decoratedType) {
|
12563
12546
|
return { functionType, decoratedType };
|
12564
12547
|
}
|
@@ -12599,7 +12582,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12599
12582
|
}
|
12600
12583
|
decoratedType = (0, decorators_1.addOverloadsToFunctionType)(evaluatorInterface, node, decoratedType);
|
12601
12584
|
}
|
12602
|
-
writeTypeCache(node, { type: decoratedType }, 0 /*
|
12585
|
+
writeTypeCache(node, { type: decoratedType }, 0 /* EvalFlags.None */);
|
12603
12586
|
return { functionType, decoratedType };
|
12604
12587
|
}
|
12605
12588
|
// Evaluates the type of a "def" statement without applying an async
|
@@ -12608,7 +12591,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12608
12591
|
var _a;
|
12609
12592
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
12610
12593
|
// Is this type already cached?
|
12611
|
-
const cachedFunctionType = readTypeCache(node.name, 0 /*
|
12594
|
+
const cachedFunctionType = readTypeCache(node.name, 0 /* EvalFlags.None */);
|
12612
12595
|
if (cachedFunctionType && (0, types_1.isFunction)(cachedFunctionType)) {
|
12613
12596
|
return cachedFunctionType;
|
12614
12597
|
}
|
@@ -12780,7 +12763,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12780
12763
|
if (types_1.FunctionType.isOverloaded(functionType) || types_1.FunctionType.isAbstractMethod(functionType)) {
|
12781
12764
|
treatEllipsisAsAny = true;
|
12782
12765
|
}
|
12783
|
-
defaultValueType = getTypeOfExpression(param.defaultValue, treatEllipsisAsAny ? 1 /*
|
12766
|
+
defaultValueType = getTypeOfExpression(param.defaultValue, treatEllipsisAsAny ? 1 /* EvalFlags.ConvertEllipsisToAny */ : 0 /* EvalFlags.None */, (0, typeUtils_1.makeInferenceContext)(annotatedType)).type;
|
12784
12767
|
}
|
12785
12768
|
if (annotatedType) {
|
12786
12769
|
// If there was both a type annotation and a default value, verify
|
@@ -12873,7 +12856,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12873
12856
|
if ((0, types_1.isUnknown)(paramType)) {
|
12874
12857
|
functionType.details.flags |= 16384 /* FunctionTypeFlags.UnannotatedParams */;
|
12875
12858
|
}
|
12876
|
-
writeTypeCache(paramNameNode, { type: paramType }, 0 /*
|
12859
|
+
writeTypeCache(paramNameNode, { type: paramType }, 0 /* EvalFlags.None */);
|
12877
12860
|
}
|
12878
12861
|
});
|
12879
12862
|
// If the function ends in P.args and P.kwargs parameters, make it exempt from
|
@@ -12954,7 +12937,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12954
12937
|
// Clear the "partially evaluated" flag to indicate that the functionType
|
12955
12938
|
// is fully evaluated.
|
12956
12939
|
functionType.details.flags &= ~131072 /* FunctionTypeFlags.PartiallyEvaluated */;
|
12957
|
-
writeTypeCache(node.name, { type: functionType }, 0 /*
|
12940
|
+
writeTypeCache(node.name, { type: functionType }, 0 /* EvalFlags.None */);
|
12958
12941
|
return functionType;
|
12959
12942
|
});
|
12960
12943
|
}
|
@@ -13019,6 +13002,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13019
13002
|
// Replace any unsolved TypeVars with Unknown (including all function-scoped TypeVars).
|
13020
13003
|
inferredParamType = (0, typeUtils_1.applySolvedTypeVars)(inferredParamType, typeVarContext, {
|
13021
13004
|
unknownIfNotFound: true,
|
13005
|
+
tupleClassType: getTupleClassType(),
|
13022
13006
|
});
|
13023
13007
|
}
|
13024
13008
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(functionNode);
|
@@ -13040,7 +13024,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13040
13024
|
return undefined;
|
13041
13025
|
}
|
13042
13026
|
function inferParameterTypeFromDefaultValue(paramValueExpr) {
|
13043
|
-
const defaultValueType = getTypeOfExpression(paramValueExpr, 1 /*
|
13027
|
+
const defaultValueType = getTypeOfExpression(paramValueExpr, 1 /* EvalFlags.ConvertEllipsisToAny */).type;
|
13044
13028
|
let inferredParamType;
|
13045
13029
|
// Is the default value a "None" or an instance of some private class (one
|
13046
13030
|
// whose name starts with an underscore)? If so, we will assume that the
|
@@ -13176,7 +13160,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13176
13160
|
return undefined;
|
13177
13161
|
}
|
13178
13162
|
// Is this type already cached?
|
13179
|
-
let inferredReturnType = readTypeCache(node.suite, 0 /*
|
13163
|
+
let inferredReturnType = readTypeCache(node.suite, 0 /* EvalFlags.None */);
|
13180
13164
|
let isIncomplete = false;
|
13181
13165
|
if (inferredReturnType) {
|
13182
13166
|
return { type: inferredReturnType, isIncomplete };
|
@@ -13324,7 +13308,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13324
13308
|
}
|
13325
13309
|
}
|
13326
13310
|
}
|
13327
|
-
writeTypeCache(node.suite, { type: inferredReturnType, isIncomplete }, 0 /*
|
13311
|
+
writeTypeCache(node.suite, { type: inferredReturnType, isIncomplete }, 0 /* EvalFlags.None */);
|
13328
13312
|
}
|
13329
13313
|
finally {
|
13330
13314
|
functionRecursionMap.delete(node.id);
|
@@ -13343,6 +13327,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13343
13327
|
!functionDecl.raiseStatements) {
|
13344
13328
|
return false;
|
13345
13329
|
}
|
13330
|
+
const statements = functionDecl.node.suite.statements;
|
13331
|
+
if (statements.some((statement) => statement.nodeType !== 47 /* ParseNodeType.StatementList */)) {
|
13332
|
+
return false;
|
13333
|
+
}
|
13346
13334
|
for (const raiseStatement of functionDecl.raiseStatements) {
|
13347
13335
|
if (!raiseStatement.typeExpression || raiseStatement.valueExpression) {
|
13348
13336
|
return false;
|
@@ -13367,7 +13355,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13367
13355
|
const iteratorTypeResult = getTypeOfExpression(node.iterableExpression);
|
13368
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();
|
13369
13357
|
assignTypeToExpression(node.targetExpression, { type: iteratedType, isIncomplete: iteratorTypeResult.isIncomplete }, node.targetExpression);
|
13370
|
-
writeTypeCache(node, { type: iteratedType, isIncomplete: !!iteratorTypeResult.isIncomplete }, 0 /*
|
13358
|
+
writeTypeCache(node, { type: iteratedType, isIncomplete: !!iteratorTypeResult.isIncomplete }, 0 /* EvalFlags.None */);
|
13371
13359
|
}
|
13372
13360
|
function evaluateTypesForExceptStatement(node) {
|
13373
13361
|
// This should be called only if the except node has a target exception.
|
@@ -13417,7 +13405,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13417
13405
|
if (node.name) {
|
13418
13406
|
assignTypeToExpression(node.name, { type: targetType }, node.name);
|
13419
13407
|
}
|
13420
|
-
writeTypeCache(node, { type: targetType }, 0 /*
|
13408
|
+
writeTypeCache(node, { type: targetType }, 0 /* EvalFlags.None */);
|
13421
13409
|
}
|
13422
13410
|
function evaluateTypesForWithStatement(node) {
|
13423
13411
|
if (isTypeCached(node)) {
|
@@ -13479,7 +13467,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13479
13467
|
if (node.target) {
|
13480
13468
|
assignTypeToExpression(node.target, { type: scopedType, isIncomplete: exprTypeResult.isIncomplete }, node.target);
|
13481
13469
|
}
|
13482
|
-
writeTypeCache(node, { type: scopedType, isIncomplete: !!exprTypeResult.isIncomplete }, 0 /*
|
13470
|
+
writeTypeCache(node, { type: scopedType, isIncomplete: !!exprTypeResult.isIncomplete }, 0 /* EvalFlags.None */);
|
13483
13471
|
}
|
13484
13472
|
function evaluateTypesForImportAs(node) {
|
13485
13473
|
var _a;
|
@@ -13504,14 +13492,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13504
13492
|
let symbolType = (_a = getAliasedSymbolTypeForName(node, symbolNameNode.value)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
|
13505
13493
|
// Is there a cached module type associated with this node? If so, use
|
13506
13494
|
// it instead of the type we just created.
|
13507
|
-
const cachedModuleType = readTypeCache(node, 0 /*
|
13495
|
+
const cachedModuleType = readTypeCache(node, 0 /* EvalFlags.None */);
|
13508
13496
|
if (cachedModuleType && (0, types_1.isModule)(cachedModuleType) && symbolType) {
|
13509
13497
|
if ((0, types_1.isTypeSame)(symbolType, cachedModuleType)) {
|
13510
13498
|
symbolType = cachedModuleType;
|
13511
13499
|
}
|
13512
13500
|
}
|
13513
13501
|
assignTypeToNameNode(symbolNameNode, { type: symbolType }, /* ignoreEmptyContainers */ false);
|
13514
|
-
writeTypeCache(node, { type: symbolType }, 0 /*
|
13502
|
+
writeTypeCache(node, { type: symbolType }, 0 /* EvalFlags.None */);
|
13515
13503
|
}
|
13516
13504
|
function evaluateTypesForImportFromAs(node) {
|
13517
13505
|
var _a;
|
@@ -13577,7 +13565,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13577
13565
|
}
|
13578
13566
|
}
|
13579
13567
|
assignTypeToNameNode(aliasNode, { type: symbolType }, /* ignoreEmptyContainers */ false);
|
13580
|
-
writeTypeCache(node, { type: symbolType }, 0 /*
|
13568
|
+
writeTypeCache(node, { type: symbolType }, 0 /* EvalFlags.None */);
|
13581
13569
|
}
|
13582
13570
|
function evaluateTypesForMatchStatement(node) {
|
13583
13571
|
if (isTypeCached(node)) {
|
@@ -13592,7 +13580,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13592
13580
|
/* isPositiveTest */ false);
|
13593
13581
|
}
|
13594
13582
|
}
|
13595
|
-
writeTypeCache(node, { type: subjectType, isIncomplete: !!subjectTypeResult.isIncomplete }, 0 /*
|
13583
|
+
writeTypeCache(node, { type: subjectType, isIncomplete: !!subjectTypeResult.isIncomplete }, 0 /* EvalFlags.None */);
|
13596
13584
|
}
|
13597
13585
|
function evaluateTypesForCaseStatement(node) {
|
13598
13586
|
if (isTypeCached(node)) {
|
@@ -13622,7 +13610,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13622
13610
|
}
|
13623
13611
|
}
|
13624
13612
|
const narrowedSubjectType = (0, patternMatching_1.assignTypeToPatternTargets)(evaluatorInterface, subjectType, !!subjectTypeResult.isIncomplete, node.pattern);
|
13625
|
-
writeTypeCache(node, { type: narrowedSubjectType, isIncomplete: !!subjectTypeResult.isIncomplete }, 0 /*
|
13613
|
+
writeTypeCache(node, { type: narrowedSubjectType, isIncomplete: !!subjectTypeResult.isIncomplete }, 0 /* EvalFlags.None */);
|
13626
13614
|
}
|
13627
13615
|
function evaluateTypesForImportFrom(node) {
|
13628
13616
|
if (isTypeCached(node)) {
|
@@ -13630,7 +13618,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13630
13618
|
}
|
13631
13619
|
if (node.isWildcardImport) {
|
13632
13620
|
// Write back a dummy type so we don't evaluate this node again.
|
13633
|
-
writeTypeCache(node, { type: types_1.AnyType.create() }, 0 /*
|
13621
|
+
writeTypeCache(node, { type: types_1.AnyType.create() }, 0 /* EvalFlags.None */);
|
13634
13622
|
const flowNode = AnalyzerNodeInfo.getFlowNode(node);
|
13635
13623
|
if (flowNode && (flowNode.flags & codeFlowTypes_1.FlowFlags.WildcardImport) !== 0) {
|
13636
13624
|
const wildcardFlowNode = flowNode;
|
@@ -13668,14 +13656,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13668
13656
|
}
|
13669
13657
|
// Is there a cached module type associated with this node? If so, use
|
13670
13658
|
// it instead of the type we just created.
|
13671
|
-
const cachedModuleType = readTypeCache(node, 0 /*
|
13659
|
+
const cachedModuleType = readTypeCache(node, 0 /* EvalFlags.None */);
|
13672
13660
|
if (cachedModuleType && (0, types_1.isModule)(cachedModuleType) && symbolType) {
|
13673
13661
|
if ((0, types_1.isTypeSame)(symbolType, cachedModuleType)) {
|
13674
13662
|
symbolType = cachedModuleType;
|
13675
13663
|
}
|
13676
13664
|
}
|
13677
13665
|
assignTypeToNameNode(symbolNameNode, { type: symbolType }, /* ignoreEmptyContainers */ false);
|
13678
|
-
writeTypeCache(node, { type: symbolType }, 0 /*
|
13666
|
+
writeTypeCache(node, { type: symbolType }, 0 /* EvalFlags.None */);
|
13679
13667
|
}
|
13680
13668
|
}
|
13681
13669
|
function evaluateTypesForTypeAnnotationNode(node) {
|
@@ -13692,7 +13680,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13692
13680
|
allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(node.valueExpression),
|
13693
13681
|
allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(node.valueExpression),
|
13694
13682
|
});
|
13695
|
-
writeTypeCache(node.valueExpression, { type: annotationType }, 0 /*
|
13683
|
+
writeTypeCache(node.valueExpression, { type: annotationType }, 0 /* EvalFlags.None */);
|
13696
13684
|
}
|
13697
13685
|
}
|
13698
13686
|
function getAliasedSymbolTypeForName(node, name) {
|
@@ -13782,7 +13770,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13782
13770
|
if (node.parent.nodeType === 32 /* ParseNodeType.Global */ || node.parent.nodeType === 39 /* ParseNodeType.Nonlocal */) {
|
13783
13771
|
// For global and nonlocal statements, allow forward references so
|
13784
13772
|
// we don't use code flow during symbol lookups.
|
13785
|
-
getTypeOfExpression(node, 4 /*
|
13773
|
+
getTypeOfExpression(node, 4 /* EvalFlags.ForwardRefs */);
|
13786
13774
|
return;
|
13787
13775
|
}
|
13788
13776
|
if (node.parent.nodeType === 37 /* ParseNodeType.ModuleName */) {
|
@@ -13842,7 +13830,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13842
13830
|
// Scan up the parse tree until we find a node that doesn't
|
13843
13831
|
// require any context to be evaluated.
|
13844
13832
|
let nodeToEvaluate = node;
|
13845
|
-
let flags = 0 /*
|
13833
|
+
let flags = 0 /* EvalFlags.None */;
|
13846
13834
|
while (true) {
|
13847
13835
|
// If we're within an argument node in a call or index expression, skip
|
13848
13836
|
// all of the nodes between because the entire argument expression
|
@@ -13872,6 +13860,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13872
13860
|
nodeToEvaluate = parent;
|
13873
13861
|
continue;
|
13874
13862
|
}
|
13863
|
+
// Forward-declared type annotation expressions need to be be evaluated
|
13864
|
+
// in context so they have the appropriate flags set. Most of these cases
|
13865
|
+
// will have been detected above when calling getParentAnnotationNode,
|
13866
|
+
// but TypeAlias expressions are not handled there.
|
13867
|
+
const stringEnclosure = ParseTreeUtils.getParentNodeOfType(parent, 48 /* ParseNodeType.StringList */);
|
13868
|
+
if (stringEnclosure) {
|
13869
|
+
nodeToEvaluate = stringEnclosure;
|
13870
|
+
continue;
|
13871
|
+
}
|
13875
13872
|
// The left expression of a call or member access expression is not generally contextual.
|
13876
13873
|
if (parent.nodeType === 9 /* ParseNodeType.Call */ || parent.nodeType === 35 /* ParseNodeType.MemberAccess */) {
|
13877
13874
|
if (nodeToEvaluate === parent.leftExpression) {
|
@@ -13887,25 +13884,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13887
13884
|
nodeToEvaluate = parent;
|
13888
13885
|
continue;
|
13889
13886
|
}
|
13890
|
-
flags = 2 /*
|
13887
|
+
flags = 2 /* EvalFlags.CallBaseDefaults */;
|
13891
13888
|
break;
|
13892
13889
|
}
|
13893
13890
|
}
|
13894
13891
|
else if (parent.nodeType === 27 /* ParseNodeType.Index */) {
|
13895
13892
|
// The base expression of an index expression is not contextual.
|
13896
13893
|
if (nodeToEvaluate === parent.baseExpression) {
|
13897
|
-
flags = 2 /*
|
13898
|
-
break;
|
13894
|
+
flags = 2 /* EvalFlags.IndexBaseDefaults */;
|
13899
13895
|
}
|
13900
13896
|
}
|
13901
|
-
else if (parent.nodeType === 48 /* ParseNodeType.StringList */ && nodeToEvaluate === parent.typeAnnotation) {
|
13902
|
-
// Forward-declared type annotation expressions need to be be evaluated
|
13903
|
-
// in context so they have the appropriate flags set. Most of these cases
|
13904
|
-
// will have been detected above when calling getParentAnnotationNode,
|
13905
|
-
// but TypeAlias expressions are not handled there.
|
13906
|
-
nodeToEvaluate = parent;
|
13907
|
-
continue;
|
13908
|
-
}
|
13909
13897
|
if (!(0, parseNodes_1.isExpressionNode)(parent)) {
|
13910
13898
|
// If we've hit a non-expression node, we generally want to
|
13911
13899
|
// stop. However, there are a few special "pass through"
|
@@ -14001,7 +13989,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14001
13989
|
const declaredReturnType = enclosingFunctionNode
|
14002
13990
|
? getFunctionDeclaredReturnType(enclosingFunctionNode)
|
14003
13991
|
: undefined;
|
14004
|
-
getTypeOfExpression(parent.returnExpression, 0 /*
|
13992
|
+
getTypeOfExpression(parent.returnExpression, 0 /* EvalFlags.None */, (0, typeUtils_1.makeInferenceContext)(declaredReturnType));
|
14005
13993
|
return;
|
14006
13994
|
}
|
14007
13995
|
break;
|
@@ -14043,7 +14031,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14043
14031
|
const param = functionNode.parameters[paramIndex];
|
14044
14032
|
const annotatedType = getTypeOfParameterAnnotation(typeAnnotation, functionNode.parameters[paramIndex].category);
|
14045
14033
|
const adjType = transformVariadicParamType(node, node.category, adjustParameterAnnotatedType(param, annotatedType));
|
14046
|
-
writeTypeCache(node.name, { type: adjType }, 0 /*
|
14034
|
+
writeTypeCache(node.name, { type: adjType }, 0 /* EvalFlags.None */);
|
14047
14035
|
return;
|
14048
14036
|
}
|
14049
14037
|
const containingClassNode = ParseTreeUtils.getEnclosingClass(functionNode, /* stopAtFunction */ true);
|
@@ -14054,7 +14042,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14054
14042
|
const typeParamName = getPseudoGenericTypeVarName(node.name.value);
|
14055
14043
|
const paramType = classInfo.classType.details.typeParameters.find((param) => param.details.name === typeParamName);
|
14056
14044
|
if (paramType) {
|
14057
|
-
writeTypeCache(node.name, { type: paramType }, 0 /*
|
14045
|
+
writeTypeCache(node.name, { type: paramType }, 0 /* EvalFlags.None */);
|
14058
14046
|
return;
|
14059
14047
|
}
|
14060
14048
|
}
|
@@ -14064,7 +14052,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14064
14052
|
const functionFlags = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, functionNode,
|
14065
14053
|
/* isInClass */ true).flags;
|
14066
14054
|
const inferredParamType = inferParameterType(functionNode, functionFlags, paramIndex, classInfo === null || classInfo === void 0 ? void 0 : classInfo.classType);
|
14067
|
-
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 */);
|
14068
14056
|
}
|
14069
14057
|
// Evaluates the types that are assigned within the statement that contains
|
14070
14058
|
// the specified parse node. In some cases, a broader statement may need to
|
@@ -14178,7 +14166,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14178
14166
|
// don't bother doing additional work.
|
14179
14167
|
let cacheEntry = readTypeCacheEntry(subnode);
|
14180
14168
|
if (cacheEntry && !cacheEntry.typeResult.isIncomplete) {
|
14181
|
-
|
14169
|
+
const typeResult = cacheEntry.typeResult;
|
14170
|
+
// Handle the special case where a function or class is partially evaluated.
|
14171
|
+
// Indicate that these are not complete types.
|
14172
|
+
if ((0, types_1.isFunction)(typeResult.type) && types_1.FunctionType.isPartiallyEvaluated(typeResult.type)) {
|
14173
|
+
return { ...typeResult, isIncomplete: true };
|
14174
|
+
}
|
14175
|
+
if ((0, types_1.isClass)(typeResult.type) && types_1.ClassType.isPartiallyEvaluated(typeResult.type)) {
|
14176
|
+
return { ...typeResult, isIncomplete: true };
|
14177
|
+
}
|
14178
|
+
return typeResult;
|
14182
14179
|
}
|
14183
14180
|
callback();
|
14184
14181
|
cacheEntry = readTypeCacheEntry(subnode);
|
@@ -14292,9 +14289,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14292
14289
|
return { type: createClassVarType(classType, errorNode, typeArgs, flags) };
|
14293
14290
|
}
|
14294
14291
|
case 'Protocol': {
|
14295
|
-
if ((flags &
|
14296
|
-
(67108864 /* EvaluatorFlags.DisallowNonTypeSpecialForms */ | 256 /* EvaluatorFlags.ExpectingTypeAnnotation */)) !==
|
14297
|
-
0) {
|
14292
|
+
if ((flags & (67108864 /* EvalFlags.NoNonTypeSpecialForms */ | 256 /* EvalFlags.TypeExpression */)) !== 0) {
|
14298
14293
|
addError(localize_1.LocMessage.protocolNotAllowed(), errorNode);
|
14299
14294
|
}
|
14300
14295
|
typeArgs === null || typeArgs === void 0 ? void 0 : typeArgs.forEach((typeArg) => {
|
@@ -14309,17 +14304,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14309
14304
|
};
|
14310
14305
|
}
|
14311
14306
|
case 'TypedDict': {
|
14312
|
-
if ((flags &
|
14313
|
-
(67108864 /* EvaluatorFlags.DisallowNonTypeSpecialForms */ | 256 /* EvaluatorFlags.ExpectingTypeAnnotation */)) !==
|
14314
|
-
0) {
|
14307
|
+
if ((flags & (67108864 /* EvalFlags.NoNonTypeSpecialForms */ | 256 /* EvalFlags.TypeExpression */)) !== 0) {
|
14315
14308
|
addError(localize_1.LocMessage.typedDictNotAllowed(), errorNode);
|
14316
14309
|
}
|
14317
14310
|
break;
|
14318
14311
|
}
|
14319
14312
|
case 'Literal': {
|
14320
|
-
if ((flags &
|
14321
|
-
(67108864 /* EvaluatorFlags.DisallowNonTypeSpecialForms */ | 256 /* EvaluatorFlags.ExpectingTypeAnnotation */)) !==
|
14322
|
-
0) {
|
14313
|
+
if ((flags & (67108864 /* EvalFlags.NoNonTypeSpecialForms */ | 256 /* EvalFlags.TypeExpression */)) !== 0) {
|
14323
14314
|
addError(localize_1.LocMessage.literalNotAllowed(), errorNode);
|
14324
14315
|
}
|
14325
14316
|
break;
|
@@ -14342,7 +14333,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14342
14333
|
return { type: createFinalType(classType, errorNode, typeArgs, flags) };
|
14343
14334
|
}
|
14344
14335
|
case 'Annotated': {
|
14345
|
-
return createAnnotatedType(classType, errorNode, typeArgs);
|
14336
|
+
return createAnnotatedType(classType, errorNode, typeArgs, flags);
|
14346
14337
|
}
|
14347
14338
|
case 'Concatenate': {
|
14348
14339
|
return { type: createConcatenateType(classType, errorNode, typeArgs, flags) };
|
@@ -14373,7 +14364,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14373
14364
|
if (fileInfo.isStubFile ||
|
14374
14365
|
fileInfo.executionEnvironment.pythonVersion.isGreaterOrEqualTo(pythonVersion_1.pythonVersion3_9) ||
|
14375
14366
|
(0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(AnalyzerNodeInfo.getFileInfo(errorNode)) ||
|
14376
|
-
(flags & 4 /*
|
14367
|
+
(flags & 4 /* EvalFlags.ForwardRefs */) !== 0) {
|
14377
14368
|
// Handle "type" specially, since it needs to act like "Type"
|
14378
14369
|
// in Python 3.9 and newer.
|
14379
14370
|
if (types_1.ClassType.isBuiltIn(classType, 'type') && typeArgs) {
|
@@ -14560,7 +14551,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14560
14551
|
typeVarContext.setTypeVarType(typeParam, typeArgType);
|
14561
14552
|
return;
|
14562
14553
|
}
|
14563
|
-
const solvedDefaultType = (0, typeUtils_1.applySolvedTypeVars)(typeParam, typeVarContext, {
|
14554
|
+
const solvedDefaultType = (0, typeUtils_1.applySolvedTypeVars)(typeParam, typeVarContext, {
|
14555
|
+
unknownIfNotFound: true,
|
14556
|
+
tupleClassType: getTupleClassType(),
|
14557
|
+
});
|
14564
14558
|
typeArgTypes.push(solvedDefaultType);
|
14565
14559
|
if ((0, types_1.isParamSpec)(typeParam)) {
|
14566
14560
|
typeVarContext.setTypeVarType(typeParam, (0, typeUtils_1.convertTypeToParamSpecValue)(solvedDefaultType));
|
@@ -14574,7 +14568,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14574
14568
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
14575
14569
|
let adjustedTypeArgType = applyTypeArgToTypeVar(typeParameters[index], typeArgType, diag);
|
14576
14570
|
// Determine if the variance must match.
|
14577
|
-
if (adjustedTypeArgType && (flags & 16384 /*
|
14571
|
+
if (adjustedTypeArgType && (flags & 16384 /* EvalFlags.EnforceVarianceConsistency */) !== 0) {
|
14578
14572
|
const destType = typeParameters[index];
|
14579
14573
|
const declaredVariance = destType.details.declaredVariance;
|
14580
14574
|
if (!(0, typeUtils_1.isVarianceOfTypeArgumentCompatible)(adjustedTypeArgType, declaredVariance)) {
|
@@ -14643,39 +14637,37 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14643
14637
|
return getTypeOfExpressionExpectingType(arg.valueExpression, options);
|
14644
14638
|
}
|
14645
14639
|
function getTypeOfExpressionExpectingType(node, options) {
|
14646
|
-
let flags = 128 /*
|
14647
|
-
8 /* EvaluatorFlags.EvaluateStringLiteralAsType */ |
|
14648
|
-
131072 /* EvaluatorFlags.DisallowClassVar */;
|
14640
|
+
let flags = 128 /* EvalFlags.InstantiableType */ | 8 /* EvalFlags.StrLiteralAsType */ | 131072 /* EvalFlags.NoClassVar */;
|
14649
14641
|
if (options === null || options === void 0 ? void 0 : options.allowTypeVarsWithoutScopeId) {
|
14650
|
-
flags |= 4096 /*
|
14642
|
+
flags |= 4096 /* EvalFlags.AllowTypeVarWithoutScopeId */;
|
14651
14643
|
}
|
14652
14644
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
14653
14645
|
if (fileInfo.isStubFile || (options === null || options === void 0 ? void 0 : options.allowForwardReference)) {
|
14654
|
-
flags |= 4 /*
|
14646
|
+
flags |= 4 /* EvalFlags.ForwardRefs */;
|
14655
14647
|
}
|
14656
14648
|
else {
|
14657
|
-
flags |=
|
14649
|
+
flags |= 8388608 /* EvalFlags.ParsesStringLiteral */;
|
14658
14650
|
}
|
14659
14651
|
if (!options || !options.allowFinal) {
|
14660
|
-
flags |= 16 /*
|
14652
|
+
flags |= 16 /* EvalFlags.NoFinal */;
|
14661
14653
|
}
|
14662
14654
|
if (options === null || options === void 0 ? void 0 : options.allowRequired) {
|
14663
|
-
flags |= 1048576 /*
|
14655
|
+
flags |= 1048576 /* EvalFlags.AllowRequired */ | 256 /* EvalFlags.TypeExpression */;
|
14664
14656
|
}
|
14665
14657
|
if (options === null || options === void 0 ? void 0 : options.allowUnpackedTuple) {
|
14666
|
-
flags |= 2097152 /*
|
14658
|
+
flags |= 2097152 /* EvalFlags.AllowUnpackedTuple */;
|
14667
14659
|
}
|
14668
14660
|
else {
|
14669
|
-
flags |= 64 /*
|
14661
|
+
flags |= 64 /* EvalFlags.NoTypeVarTuple */;
|
14670
14662
|
}
|
14671
14663
|
if (!options || !options.allowParamSpec) {
|
14672
|
-
flags |= 32 /*
|
14664
|
+
flags |= 32 /* EvalFlags.NoParamSpec */;
|
14673
14665
|
}
|
14674
14666
|
if (options === null || options === void 0 ? void 0 : options.enforceTypeAnnotationRules) {
|
14675
|
-
flags |= 256 /*
|
14667
|
+
flags |= 256 /* EvalFlags.TypeExpression */;
|
14676
14668
|
}
|
14677
14669
|
if (options === null || options === void 0 ? void 0 : options.disallowProtocolAndTypedDict) {
|
14678
|
-
flags |= 67108864 /*
|
14670
|
+
flags |= 67108864 /* EvalFlags.NoNonTypeSpecialForms */;
|
14679
14671
|
}
|
14680
14672
|
return getTypeOfExpression(node, flags);
|
14681
14673
|
}
|
@@ -15091,10 +15083,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15091
15083
|
if (declaration.intrinsicType === 'Any') {
|
15092
15084
|
return { type: types_1.AnyType.create() };
|
15093
15085
|
}
|
15094
|
-
if (declaration.intrinsicType === '
|
15086
|
+
if (declaration.intrinsicType === 'type[self]') {
|
15095
15087
|
const classNode = ParseTreeUtils.getEnclosingClass(declaration.node);
|
15096
15088
|
const classTypeInfo = getTypeOfClass(classNode);
|
15097
|
-
return {
|
15089
|
+
return {
|
15090
|
+
type: classTypeInfo
|
15091
|
+
? (0, typeUtils_1.synthesizeTypeVarForSelfCls)(classTypeInfo.classType, /* isClsParam */ true)
|
15092
|
+
: types_1.UnknownType.create(),
|
15093
|
+
};
|
15098
15094
|
}
|
15099
15095
|
const strType = getBuiltInObject(declaration.node, 'str');
|
15100
15096
|
const intType = getBuiltInObject(declaration.node, 'int');
|
@@ -15207,7 +15203,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15207
15203
|
}
|
15208
15204
|
function getTypeOfTypeParameter(node) {
|
15209
15205
|
// Is this type already cached?
|
15210
|
-
const cachedTypeVarType = readTypeCache(node.name, 0 /*
|
15206
|
+
const cachedTypeVarType = readTypeCache(node.name, 0 /* EvalFlags.None */);
|
15211
15207
|
if (cachedTypeVarType && (0, types_1.isTypeVar)(cachedTypeVarType)) {
|
15212
15208
|
return cachedTypeVarType;
|
15213
15209
|
}
|
@@ -15416,7 +15412,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15416
15412
|
}
|
15417
15413
|
// Special-case calls to certain built-in type functions.
|
15418
15414
|
if (((_a = resolvedDecl.inferredTypeSource) === null || _a === void 0 ? void 0 : _a.nodeType) === 9 /* ParseNodeType.Call */) {
|
15419
|
-
const baseTypeResult = getTypeOfExpression(resolvedDecl.inferredTypeSource.leftExpression, 2 /*
|
15415
|
+
const baseTypeResult = getTypeOfExpression(resolvedDecl.inferredTypeSource.leftExpression, 2 /* EvalFlags.CallBaseDefaults */);
|
15420
15416
|
const callType = baseTypeResult.type;
|
15421
15417
|
const exemptBuiltins = [
|
15422
15418
|
'TypeVar',
|
@@ -16097,7 +16093,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16097
16093
|
paramType = stripLiteralValue(paramType);
|
16098
16094
|
}
|
16099
16095
|
paramTypes.push(paramType);
|
16100
|
-
writeTypeCache(param.name, { type: paramType }, 0 /*
|
16096
|
+
writeTypeCache(param.name, { type: paramType }, 0 /* EvalFlags.None */);
|
16101
16097
|
}
|
16102
16098
|
});
|
16103
16099
|
// Don't bother trying to determine the contextual return
|
@@ -16162,46 +16158,51 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16162
16158
|
function getTypeOfMember(member) {
|
16163
16159
|
if ((0, types_1.isInstantiableClass)(member.classType)) {
|
16164
16160
|
return (0, typeUtils_1.partiallySpecializeType)(getEffectiveTypeOfSymbol(member.symbol), member.classType,
|
16165
|
-
/* selfClass */ undefined, typeClass
|
16161
|
+
/* selfClass */ undefined, typeClass && (0, types_1.isInstantiableClass)(typeClass) ? typeClass : undefined);
|
16166
16162
|
}
|
16167
16163
|
return types_1.UnknownType.create();
|
16168
16164
|
}
|
16169
16165
|
function getTypeOfMemberInternal(errorNode, member, selfClass, flags) {
|
16170
|
-
if ((0, types_1.
|
16171
|
-
const typeResult = getEffectiveTypeOfSymbolForUsage(member.symbol);
|
16172
|
-
if (typeResult) {
|
16173
|
-
// If the type is a function or overloaded function, infer
|
16174
|
-
// and cache the return type if necessary. This needs to be done
|
16175
|
-
// prior to specializing.
|
16176
|
-
inferReturnTypeIfNecessary(typeResult.type);
|
16177
|
-
// Check for ambiguous accesses to attributes with generic types?
|
16178
|
-
if (errorNode &&
|
16179
|
-
selfClass &&
|
16180
|
-
(0, types_1.isClass)(selfClass) &&
|
16181
|
-
member.isInstanceMember &&
|
16182
|
-
(0, types_1.isClass)(member.unspecializedClassType) &&
|
16183
|
-
(flags & 1024 /* MemberAccessFlags.DisallowGenericInstanceVariableAccess */) !== 0 &&
|
16184
|
-
(0, typeUtils_1.requiresSpecialization)(typeResult.type, { ignoreSelf: true, ignoreImplicitTypeArgs: true })) {
|
16185
|
-
const specializedType = (0, typeUtils_1.partiallySpecializeType)(typeResult.type, member.unspecializedClassType, (0, typeUtils_1.selfSpecializeClass)(selfClass, /* overrideTypeArgs */ true));
|
16186
|
-
if ((0, types_1.findSubtype)(specializedType, (subtype) => !(0, types_1.isFunction)(subtype) &&
|
16187
|
-
!(0, types_1.isOverloadedFunction)(subtype) &&
|
16188
|
-
(0, typeUtils_1.requiresSpecialization)(subtype, { ignoreSelf: true, ignoreImplicitTypeArgs: true }))) {
|
16189
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.genericInstanceVariableAccess(), errorNode);
|
16190
|
-
}
|
16191
|
-
}
|
16192
|
-
return {
|
16193
|
-
type: (0, typeUtils_1.partiallySpecializeType)(typeResult.type, member.classType, selfClass),
|
16194
|
-
isIncomplete: !!typeResult.isIncomplete,
|
16195
|
-
};
|
16196
|
-
}
|
16197
|
-
}
|
16198
|
-
else if ((0, types_1.isAnyOrUnknown)(member.classType)) {
|
16166
|
+
if ((0, types_1.isAnyOrUnknown)(member.classType)) {
|
16199
16167
|
return {
|
16200
16168
|
type: member.classType,
|
16201
16169
|
isIncomplete: false,
|
16202
16170
|
};
|
16203
16171
|
}
|
16204
|
-
|
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
|
+
};
|
16205
16206
|
}
|
16206
16207
|
function assignClass(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount, reportErrorsUsingObjType) {
|
16207
16208
|
// If the source or dest types are partially evaluated (i.e. they are in the
|
@@ -17333,7 +17334,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17333
17334
|
return true;
|
17334
17335
|
}
|
17335
17336
|
if ((0, types_1.isFunction)(concreteSrcType)) {
|
17336
|
-
if (assignFunction(destType, concreteSrcType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext !== null && destTypeVarContext !== void 0 ? destTypeVarContext : new typeVarContext_1.TypeVarContext((0, typeUtils_1.
|
17337
|
+
if (assignFunction(destType, concreteSrcType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext !== null && destTypeVarContext !== void 0 ? destTypeVarContext : new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeIds)(destType)), srcTypeVarContext !== null && srcTypeVarContext !== void 0 ? srcTypeVarContext : new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeIds)(concreteSrcType)), flags, recursionCount)) {
|
17337
17338
|
return true;
|
17338
17339
|
}
|
17339
17340
|
}
|
@@ -18458,7 +18459,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18458
18459
|
assignedType.typeArguments.length <= assignedType.details.typeParameters.length &&
|
18459
18460
|
!assignedType.tupleTypeArguments) {
|
18460
18461
|
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(assignedType));
|
18461
|
-
(0, constraintSolver_1.
|
18462
|
+
(0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, types_1.ClassType.cloneForSpecialization(assignedType,
|
18462
18463
|
/* typeArguments */ undefined,
|
18463
18464
|
/* isTypeArgumentExplicit */ false), declaredType, typeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start);
|
18464
18465
|
let replacedTypeArg = false;
|
@@ -19261,8 +19262,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19261
19262
|
return true;
|
19262
19263
|
}
|
19263
19264
|
function isLegalImplicitTypeAliasType(type) {
|
19264
|
-
// We explicitly exclude "
|
19265
|
-
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
|
+
}
|
19266
19275
|
return false;
|
19267
19276
|
}
|
19268
19277
|
// Look at the subtypes within the union. If any of them are not
|
@@ -19276,6 +19285,34 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19276
19285
|
});
|
19277
19286
|
return isLegal;
|
19278
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
|
+
}
|
19279
19316
|
function printObjectTypeForClass(type) {
|
19280
19317
|
return TypePrinter.printObjectTypeForClass(type, evaluatorOptions.printTypeFlags, getFunctionEffectiveReturnType);
|
19281
19318
|
}
|