@zzzen/pyright-internal 1.2.0-dev.20240526 → 1.2.0-dev.20240609
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/analyzerNodeInfo.d.ts +2 -2
- package/dist/analyzer/binder.d.ts +3 -3
- package/dist/analyzer/binder.js +46 -40
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.d.ts +3 -3
- package/dist/analyzer/checker.js +82 -65
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +4 -4
- package/dist/analyzer/codeFlowTypes.js +3 -3
- package/dist/analyzer/constraintSolver.js +26 -34
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +1 -1
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.js +12 -8
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +1 -1
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declarationUtils.js +3 -3
- package/dist/analyzer/enums.d.ts +1 -1
- package/dist/analyzer/enums.js +25 -22
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +1 -0
- package/dist/analyzer/importResolver.js +6 -3
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importStatementUtils.js +6 -6
- package/dist/analyzer/namedTuples.js +2 -2
- package/dist/analyzer/operations.js +8 -9
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/parameterUtils.js +1 -13
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +1 -1
- package/dist/analyzer/parseTreeUtils.js +94 -94
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/parseTreeWalker.d.ts +5 -5
- package/dist/analyzer/parseTreeWalker.js +64 -64
- package/dist/analyzer/parseTreeWalker.js.map +1 -1
- package/dist/analyzer/patternMatching.js +5 -5
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +1 -1
- package/dist/analyzer/program.js +23 -29
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js +2 -2
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +2 -2
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/scope.d.ts +1 -1
- package/dist/analyzer/scope.js +2 -2
- package/dist/analyzer/scope.js.map +1 -1
- package/dist/analyzer/sourceFile.js +3 -3
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceMapper.js +4 -4
- package/dist/analyzer/staticExpressions.js +3 -3
- package/dist/analyzer/testWalker.js +1 -1
- package/dist/analyzer/tracePrinter.js +4 -4
- package/dist/analyzer/typeDocStringUtils.js +1 -1
- package/dist/analyzer/typeEvaluator.js +568 -519
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -3
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +9 -8
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +21 -14
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeStubWriter.js +1 -1
- package/dist/analyzer/typeUtils.d.ts +4 -5
- package/dist/analyzer/typeUtils.js +100 -128
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.js +4 -0
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/typedDicts.d.ts +1 -2
- package/dist/analyzer/typedDicts.js +5 -17
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +11 -12
- package/dist/analyzer/types.js +137 -169
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +1 -1
- package/dist/backgroundAnalysisBase.js +3 -3
- package/dist/commands/dumpFileDebugInfoCommand.d.ts +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +15 -15
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/configOptions.d.ts +2 -1
- package/dist/common/configOptions.js +12 -3
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/realFileSystem.d.ts +3 -3
- package/dist/common/realFileSystem.js +6 -6
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/textEditTracker.js +5 -5
- package/dist/common/uri/fileUri.js +1 -0
- package/dist/common/uri/fileUri.js.map +1 -1
- package/dist/common/uri/uri.d.ts +3 -0
- package/dist/common/uri/uri.js +16 -0
- package/dist/common/uri/uri.js.map +1 -1
- package/dist/languageServerBase.js +1 -1
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/autoImporter.js +4 -4
- package/dist/languageService/callHierarchyProvider.js +1 -1
- package/dist/languageService/completionProvider.js +30 -30
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.js +7 -7
- package/dist/languageService/hoverProvider.js +2 -2
- package/dist/languageService/importSorter.js +1 -1
- package/dist/languageService/referencesProvider.js +4 -4
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/symbolIndexer.js +3 -3
- package/dist/languageService/tooltipUtils.js +2 -2
- package/dist/languageService/workspaceSymbolProvider.js +1 -1
- package/dist/localization/localize.d.ts +7 -1
- package/dist/localization/localize.js +4 -1
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +5 -3
- package/dist/localization/package.nls.de.json +5 -3
- package/dist/localization/package.nls.en-us.json +4 -1
- package/dist/localization/package.nls.es.json +5 -3
- package/dist/localization/package.nls.fr.json +5 -3
- package/dist/localization/package.nls.it.json +5 -3
- package/dist/localization/package.nls.ja.json +5 -3
- package/dist/localization/package.nls.ko.json +6 -4
- package/dist/localization/package.nls.pl.json +5 -3
- package/dist/localization/package.nls.pt-br.json +5 -3
- package/dist/localization/package.nls.qps-ploc.json +5 -3
- package/dist/localization/package.nls.ru.json +5 -3
- package/dist/localization/package.nls.tr.json +5 -3
- package/dist/localization/package.nls.zh-cn.json +5 -3
- package/dist/localization/package.nls.zh-tw.json +5 -3
- package/dist/parser/parseNodes.d.ts +42 -42
- package/dist/parser/parseNodes.js +69 -69
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.d.ts +1 -1
- package/dist/parser/parser.js +35 -35
- package/dist/parser/parser.js.map +1 -1
- package/dist/pyright.js +6 -3
- package/dist/pyright.js.map +1 -1
- package/dist/tests/classDeclaration.test.js +1 -1
- package/dist/tests/config.test.js +2 -2
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/diagnosticOverrides.test.js +7 -6
- package/dist/tests/diagnosticOverrides.test.js.map +1 -1
- package/dist/tests/importResolver.test.js +16 -0
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/parseTreeUtils.test.js +4 -4
- package/dist/tests/parser.test.js +3 -3
- package/dist/tests/testState.test.js +1 -1
- package/dist/tests/testState.test.js.map +1 -1
- package/dist/tests/testUtils.js +1 -1
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +9 -1
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +8 -0
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +7 -3
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +15 -15
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typePrinter.test.js +2 -2
- package/dist/tests/typePrinter.test.js.map +1 -1
- package/dist/tests/uri.test.js +11 -3
- package/dist/tests/uri.test.js.map +1 -1
- package/dist/workspaceFactory.js +16 -14
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -1
@@ -183,27 +183,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
183
183
|
let expectedTypeCache = new Map();
|
184
184
|
let deferredClassCompletions = [];
|
185
185
|
let cancellationToken;
|
186
|
-
let isBasicTypesInitialized = false;
|
187
|
-
let noneClassType;
|
188
|
-
let noneType;
|
189
|
-
let objectType;
|
190
|
-
let typeClassType;
|
191
|
-
let unionClassType;
|
192
|
-
let awaitableProtocolType;
|
193
|
-
let functionObj;
|
194
|
-
let tupleClassType;
|
195
|
-
let boolClassType;
|
196
|
-
let intClassType;
|
197
|
-
let strClassType;
|
198
|
-
let dictClassType;
|
199
|
-
let typedDictClassType;
|
200
|
-
let typedDictPrivateClassType;
|
201
|
-
let supportsKeysAndGetItemProtocolType;
|
202
|
-
let mappingType;
|
203
186
|
let printExpressionSpaceCount = 0;
|
204
187
|
let incompleteGenerationCount = 0;
|
205
188
|
const returnTypeInferenceContextStack = [];
|
206
189
|
let returnTypeInferenceTypeCache;
|
190
|
+
let isPrefetchedTypesInitialized = false;
|
191
|
+
// Various types prefetched from stdlib stubs
|
192
|
+
let noneTypeClass;
|
193
|
+
let objectClass;
|
194
|
+
let typeClass;
|
195
|
+
let unionTypeClass;
|
196
|
+
let awaitableClass;
|
197
|
+
let functionClass;
|
198
|
+
let tupleClass;
|
199
|
+
let boolClass;
|
200
|
+
let intClass;
|
201
|
+
let strClass;
|
202
|
+
let dictClass;
|
203
|
+
let typedDictPrivateClass;
|
204
|
+
let supportsKeysAndGetItemClass;
|
205
|
+
let mappingClass;
|
207
206
|
function runWithCancellationToken(token, callback) {
|
208
207
|
try {
|
209
208
|
cancellationToken = token;
|
@@ -383,7 +382,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
383
382
|
// type of surrounding statements to be evaluated.
|
384
383
|
function getType(node) {
|
385
384
|
var _a, _b;
|
386
|
-
|
385
|
+
initializePrefetchedTypes(node);
|
387
386
|
let type = (_a = evaluateTypeForSubnode(node, () => {
|
388
387
|
evaluateTypesForExpressionInContext(node);
|
389
388
|
})) === null || _a === void 0 ? void 0 : _a.type;
|
@@ -456,50 +455,42 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
456
455
|
}
|
457
456
|
return undefined;
|
458
457
|
}
|
459
|
-
function
|
458
|
+
function initializePrefetchedTypes(node) {
|
460
459
|
var _a;
|
461
|
-
if (!
|
460
|
+
if (!isPrefetchedTypesInitialized) {
|
462
461
|
// Some of these types have cyclical dependencies on each other,
|
463
462
|
// so don't re-enter this block once we start executing it.
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
if (
|
470
|
-
|
463
|
+
isPrefetchedTypesInitialized = true;
|
464
|
+
objectClass = getBuiltInType(node, 'object');
|
465
|
+
typeClass = getBuiltInType(node, 'type');
|
466
|
+
functionClass = getBuiltInType(node, 'function');
|
467
|
+
unionTypeClass = getTypesType(node, 'UnionType');
|
468
|
+
if (unionTypeClass && (0, types_1.isClass)(unionTypeClass)) {
|
469
|
+
unionTypeClass.details.flags |= -2147483648 /* ClassTypeFlags.SpecialFormClass */;
|
471
470
|
}
|
472
471
|
// Initialize and cache "Collection" to break a cyclical dependency
|
473
472
|
// that occurs when resolving tuple below.
|
474
473
|
getTypingType(node, 'Collection');
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
awaitableProtocolType = getTypingType(node, 'Awaitable');
|
487
|
-
mappingType = getTypingType(node, 'Mapping');
|
488
|
-
supportsKeysAndGetItemProtocolType = getTypeshedType(node, 'SupportsKeysAndGetItem');
|
489
|
-
if (!supportsKeysAndGetItemProtocolType) {
|
474
|
+
noneTypeClass = (_a = getTypeshedType(node, 'NoneType')) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
|
475
|
+
tupleClass = getBuiltInType(node, 'tuple');
|
476
|
+
boolClass = getBuiltInType(node, 'bool');
|
477
|
+
intClass = getBuiltInType(node, 'int');
|
478
|
+
strClass = getBuiltInType(node, 'str');
|
479
|
+
dictClass = getBuiltInType(node, 'dict');
|
480
|
+
typedDictPrivateClass = getTypingType(node, '_TypedDict');
|
481
|
+
awaitableClass = getTypingType(node, 'Awaitable');
|
482
|
+
mappingClass = getTypingType(node, 'Mapping');
|
483
|
+
supportsKeysAndGetItemClass = getTypeshedType(node, 'SupportsKeysAndGetItem');
|
484
|
+
if (!supportsKeysAndGetItemClass) {
|
490
485
|
// Fall back on 'Mapping' if 'SupportsKeysAndGetItem' is not available.
|
491
|
-
|
486
|
+
supportsKeysAndGetItemClass = mappingClass;
|
492
487
|
}
|
493
488
|
// Wire up the `Any` class to the special-form version of our internal AnyType.
|
494
|
-
|
495
|
-
if (objectClass &&
|
496
|
-
(0, types_1.isInstantiableClass)(objectClass) &&
|
497
|
-
typeClassType &&
|
498
|
-
(0, types_1.isInstantiableClass)(typeClassType)) {
|
489
|
+
if (objectClass && (0, types_1.isInstantiableClass)(objectClass) && typeClass && (0, types_1.isInstantiableClass)(typeClass)) {
|
499
490
|
const anyClass = types_1.ClassType.createInstantiable('Any', 'typing.Any', 'typing', uri_1.Uri.empty(), 1 /* ClassTypeFlags.BuiltInClass */ | -2147483648 /* ClassTypeFlags.SpecialFormClass */,
|
500
491
|
/* typeSourceId */ -1,
|
501
492
|
/* declaredMetaclass */ undefined,
|
502
|
-
/* effectiveMetaclass */
|
493
|
+
/* effectiveMetaclass */ typeClass);
|
503
494
|
anyClass.details.baseClasses.push(objectClass);
|
504
495
|
(0, typeUtils_1.computeMroLinearization)(anyClass);
|
505
496
|
const anySpecialForm = types_1.AnyType.createSpecialForm();
|
@@ -546,7 +537,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
546
537
|
// typeshed stubs, do so here. It would be better to fetch this when it's
|
547
538
|
// needed in assignType, but we don't have access to the parse tree
|
548
539
|
// at that point.
|
549
|
-
|
540
|
+
initializePrefetchedTypes(node);
|
550
541
|
let typeResult = getTypeOfExpressionCore(node, flags, inferenceContext, signatureTracker);
|
551
542
|
// Should we disable type promotions for bytes?
|
552
543
|
if ((0, types_1.isInstantiableClass)(typeResult.type) &&
|
@@ -605,7 +596,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
605
596
|
typeResult = getTypeOfMemberAccess(node, flags);
|
606
597
|
break;
|
607
598
|
}
|
608
|
-
case
|
599
|
+
case 27 /* ParseNodeType.Index */: {
|
609
600
|
typeResult = getTypeOfIndex(node, flags);
|
610
601
|
break;
|
611
602
|
}
|
@@ -617,7 +608,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
617
608
|
typeResult = getTypeOfTuple(node, flags, inferenceContext, signatureTracker);
|
618
609
|
break;
|
619
610
|
}
|
620
|
-
case
|
611
|
+
case 14 /* ParseNodeType.Constant */: {
|
621
612
|
typeResult = getTypeOfConstant(node, flags);
|
622
613
|
break;
|
623
614
|
}
|
@@ -635,7 +626,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
635
626
|
typeResult = getTypeOfNumber(node, typeResult);
|
636
627
|
break;
|
637
628
|
}
|
638
|
-
case
|
629
|
+
case 21 /* ParseNodeType.Ellipsis */: {
|
639
630
|
typeResult = getTypeOfEllipsis(flags, typeResult, node);
|
640
631
|
break;
|
641
632
|
}
|
@@ -657,7 +648,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
657
648
|
typeResult = (0, operations_1.getTypeOfAugmentedAssignment)(evaluatorInterface, node, inferenceContext);
|
658
649
|
break;
|
659
650
|
}
|
660
|
-
case
|
651
|
+
case 34 /* ParseNodeType.List */:
|
661
652
|
case 45 /* ParseNodeType.Set */: {
|
662
653
|
typeResult = getTypeOfListOrSet(node, flags, inferenceContext);
|
663
654
|
break;
|
@@ -674,21 +665,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
674
665
|
typeResult = (0, operations_1.getTypeOfTernaryOperation)(evaluatorInterface, node, flags, inferenceContext);
|
675
666
|
break;
|
676
667
|
}
|
677
|
-
case
|
678
|
-
typeResult =
|
668
|
+
case 11 /* ParseNodeType.Comprehension */: {
|
669
|
+
typeResult = getTypeOfComprehension(node, flags, inferenceContext);
|
679
670
|
break;
|
680
671
|
}
|
681
|
-
case
|
672
|
+
case 18 /* ParseNodeType.Dictionary */: {
|
682
673
|
typeResult = getTypeOfDictionary(node, flags, inferenceContext);
|
683
674
|
break;
|
684
675
|
}
|
685
|
-
case
|
676
|
+
case 33 /* ParseNodeType.Lambda */: {
|
686
677
|
typeResult = getTypeOfLambda(node, inferenceContext);
|
687
678
|
break;
|
688
679
|
}
|
689
680
|
case 3 /* ParseNodeType.Assignment */: {
|
690
681
|
typeResult = getTypeOfExpression(node.rightExpression, flags, inferenceContext, signatureTracker);
|
691
|
-
assignTypeToExpression(node.leftExpression, typeResult
|
682
|
+
assignTypeToExpression(node.leftExpression, typeResult, node.rightExpression,
|
692
683
|
/* ignoreEmptyContainers */ true,
|
693
684
|
/* allowAssignmentToFinalVar */ true);
|
694
685
|
break;
|
@@ -698,8 +689,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
698
689
|
addError(localize_1.LocMessage.walrusNotAllowed(), node);
|
699
690
|
}
|
700
691
|
typeResult = getTypeOfExpression(node.rightExpression, flags, inferenceContext, signatureTracker);
|
701
|
-
assignTypeToExpression(node.name, typeResult
|
702
|
-
/* ignoreEmptyContainers */ true);
|
692
|
+
assignTypeToExpression(node.name, typeResult, node.rightExpression, /* ignoreEmptyContainers */ true);
|
703
693
|
break;
|
704
694
|
}
|
705
695
|
case 60 /* ParseNodeType.Yield */: {
|
@@ -724,7 +714,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
724
714
|
break;
|
725
715
|
}
|
726
716
|
case 49 /* ParseNodeType.String */:
|
727
|
-
case
|
717
|
+
case 30 /* ParseNodeType.FormatString */: {
|
728
718
|
typeResult = getTypeOfString(node);
|
729
719
|
break;
|
730
720
|
}
|
@@ -946,7 +936,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
946
936
|
});
|
947
937
|
const isBytes = (node.strings[0].token.flags & 32 /* StringTokenFlags.Bytes */) !== 0;
|
948
938
|
// Don't create a literal type if it's an f-string.
|
949
|
-
if (node.strings.some((str) => str.nodeType ===
|
939
|
+
if (node.strings.some((str) => str.nodeType === 30 /* ParseNodeType.FormatString */)) {
|
950
940
|
if (isLiteralString) {
|
951
941
|
const literalStringType = getTypingType(node, 'LiteralString');
|
952
942
|
if (literalStringType && (0, types_1.isInstantiableClass)(literalStringType)) {
|
@@ -974,7 +964,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
974
964
|
let typeResult;
|
975
965
|
let isIncomplete = false;
|
976
966
|
// Don't create a literal type if it's an f-string.
|
977
|
-
if (node.nodeType ===
|
967
|
+
if (node.nodeType === 30 /* ParseNodeType.FormatString */) {
|
978
968
|
let isLiteralString = true;
|
979
969
|
// If all of the format expressions are of type LiteralString, then
|
980
970
|
// the resulting formatted string is also LiteralString.
|
@@ -1040,8 +1030,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1040
1030
|
}
|
1041
1031
|
if (types_1.ClassType.isBuiltIn(subtype, 'LiteralString')) {
|
1042
1032
|
// Handle "LiteralString" specially.
|
1043
|
-
if (
|
1044
|
-
let strInstance = types_1.ClassType.cloneAsInstance(
|
1033
|
+
if (strClass && (0, types_1.isInstantiableClass)(strClass)) {
|
1034
|
+
let strInstance = types_1.ClassType.cloneAsInstance(strClass);
|
1045
1035
|
if (subtype.condition) {
|
1046
1036
|
strInstance = types_1.TypeBase.cloneForCondition(strInstance, (0, typeUtils_1.getTypeCondition)(subtype));
|
1047
1037
|
}
|
@@ -1280,9 +1270,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1280
1270
|
const concreteSubtype = makeTopLevelTypeVarsConcrete(subtype);
|
1281
1271
|
if ((0, types_1.isClassInstance)(concreteSubtype)) {
|
1282
1272
|
if (concreteSubtype.literalValue !== undefined) {
|
1273
|
+
let isLiteralFalsy;
|
1274
|
+
if (concreteSubtype.literalValue instanceof types_1.EnumLiteral) {
|
1275
|
+
isLiteralFalsy = !canBeTruthy(concreteSubtype);
|
1276
|
+
}
|
1277
|
+
else {
|
1278
|
+
isLiteralFalsy = !concreteSubtype.literalValue;
|
1279
|
+
}
|
1283
1280
|
// If the object is already definitely falsy, it's fine to
|
1284
1281
|
// include, otherwise it should be removed.
|
1285
|
-
return
|
1282
|
+
return isLiteralFalsy ? subtype : undefined;
|
1286
1283
|
}
|
1287
1284
|
// If the object is a bool, make it "false", since
|
1288
1285
|
// "true" is a truthy value.
|
@@ -1316,9 +1313,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1316
1313
|
const concreteSubtype = makeTopLevelTypeVarsConcrete(subtype);
|
1317
1314
|
if ((0, types_1.isClassInstance)(concreteSubtype)) {
|
1318
1315
|
if (concreteSubtype.literalValue !== undefined) {
|
1316
|
+
let isLiteralTruthy;
|
1317
|
+
if (concreteSubtype.literalValue instanceof types_1.EnumLiteral) {
|
1318
|
+
isLiteralTruthy = !canBeFalsy(concreteSubtype);
|
1319
|
+
}
|
1320
|
+
else {
|
1321
|
+
isLiteralTruthy = !!concreteSubtype.literalValue;
|
1322
|
+
}
|
1319
1323
|
// If the object is already definitely truthy, it's fine to
|
1320
1324
|
// include, otherwise it should be removed.
|
1321
|
-
return
|
1325
|
+
return isLiteralTruthy ? subtype : undefined;
|
1322
1326
|
}
|
1323
1327
|
// If the object is a bool, make it "true", since
|
1324
1328
|
// "false" is a falsy value.
|
@@ -1733,7 +1737,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1733
1737
|
}
|
1734
1738
|
break;
|
1735
1739
|
}
|
1736
|
-
case
|
1740
|
+
case 27 /* ParseNodeType.Index */: {
|
1737
1741
|
const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.baseExpression, 2 /* EvaluatorFlags.IndexBaseDefaults */).type);
|
1738
1742
|
if (baseType && (0, types_1.isClassInstance)(baseType)) {
|
1739
1743
|
const setItemType = getBoundMagicMethod(baseType, '__setitem__');
|
@@ -1786,12 +1790,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1786
1790
|
// (object that provides an __await__ that returns a generator object).
|
1787
1791
|
// If errorNode is undefined, no errors are reported.
|
1788
1792
|
function getTypeOfAwaitable(type, errorNode) {
|
1789
|
-
if (!
|
1790
|
-
!(0, types_1.isInstantiableClass)(
|
1791
|
-
|
1793
|
+
if (!awaitableClass ||
|
1794
|
+
!(0, types_1.isInstantiableClass)(awaitableClass) ||
|
1795
|
+
awaitableClass.details.typeParameters.length !== 1) {
|
1792
1796
|
return types_1.UnknownType.create();
|
1793
1797
|
}
|
1794
|
-
const awaitableProtocolObj = types_1.ClassType.cloneAsInstance(
|
1798
|
+
const awaitableProtocolObj = types_1.ClassType.cloneAsInstance(awaitableClass);
|
1795
1799
|
return (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
|
1796
1800
|
subtype = makeTopLevelTypeVarsConcrete(subtype);
|
1797
1801
|
if ((0, types_1.isAnyOrUnknown)(subtype)) {
|
@@ -1852,8 +1856,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1852
1856
|
if (!isAsync && (0, types_1.isClassInstance)(subtype)) {
|
1853
1857
|
const getItemReturnType = getTypeOfMagicMethodCall(subtype, '__getitem__', [
|
1854
1858
|
{
|
1855
|
-
type:
|
1856
|
-
? types_1.ClassType.cloneAsInstance(
|
1859
|
+
type: intClass && (0, types_1.isInstantiableClass)(intClass)
|
1860
|
+
? types_1.ClassType.cloneAsInstance(intClass)
|
1857
1861
|
: types_1.UnknownType.create(),
|
1858
1862
|
},
|
1859
1863
|
], errorNode);
|
@@ -1882,7 +1886,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1882
1886
|
// know anything more about them.
|
1883
1887
|
nextReturnType = (0, typeUtils_1.mapSubtypes)(nextReturnType, (returnSubtype) => {
|
1884
1888
|
if ((0, types_1.isTypeVar)(returnSubtype) && (0, types_1.isUnpackedVariadicTypeVar)(returnSubtype)) {
|
1885
|
-
return
|
1889
|
+
return getObjectType();
|
1886
1890
|
}
|
1887
1891
|
return returnSubtype;
|
1888
1892
|
});
|
@@ -1983,21 +1987,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1983
1987
|
return isTypeHashable;
|
1984
1988
|
}
|
1985
1989
|
function getTypedDictClassType() {
|
1986
|
-
return
|
1987
|
-
? typedDictPrivateClassType
|
1988
|
-
: undefined;
|
1990
|
+
return typedDictPrivateClass && (0, types_1.isInstantiableClass)(typedDictPrivateClass) ? typedDictPrivateClass : undefined;
|
1989
1991
|
}
|
1990
1992
|
function getTupleClassType() {
|
1991
|
-
return
|
1993
|
+
return tupleClass && (0, types_1.isInstantiableClass)(tupleClass) ? tupleClass : undefined;
|
1992
1994
|
}
|
1993
1995
|
function getObjectType() {
|
1994
|
-
return
|
1996
|
+
return objectClass ? (0, typeUtils_1.convertToInstance)(objectClass) : types_1.UnknownType.create();
|
1995
1997
|
}
|
1996
1998
|
function getNoneType() {
|
1997
|
-
return
|
1999
|
+
return noneTypeClass ? (0, typeUtils_1.convertToInstance)(noneTypeClass) : types_1.UnknownType.create();
|
1998
2000
|
}
|
1999
2001
|
function getUnionClassType() {
|
2000
|
-
return
|
2002
|
+
return unionTypeClass !== null && unionTypeClass !== void 0 ? unionTypeClass : types_1.UnknownType.create();
|
2001
2003
|
}
|
2002
2004
|
function getTypingType(node, symbolName) {
|
2003
2005
|
var _a;
|
@@ -2022,18 +2024,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2022
2024
|
return getEffectiveTypeOfSymbol(symbol);
|
2023
2025
|
}
|
2024
2026
|
function checkCodeFlowTooComplex(node) {
|
2025
|
-
const scopeNode = node.nodeType ===
|
2027
|
+
const scopeNode = node.nodeType === 31 /* ParseNodeType.Function */ ? node : ParseTreeUtils.getExecutionScopeNode(node);
|
2026
2028
|
const codeComplexity = AnalyzerNodeInfo.getCodeFlowComplexity(scopeNode);
|
2027
2029
|
if (codeComplexity > exports.maxCodeComplexity) {
|
2028
2030
|
let errorRange = scopeNode;
|
2029
|
-
if (scopeNode.nodeType ===
|
2031
|
+
if (scopeNode.nodeType === 31 /* ParseNodeType.Function */) {
|
2030
2032
|
errorRange = scopeNode.name;
|
2031
2033
|
}
|
2032
2034
|
else if (scopeNode.nodeType === 36 /* ParseNodeType.Module */) {
|
2033
2035
|
errorRange = { start: 0, length: 0 };
|
2034
2036
|
}
|
2035
2037
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
2036
|
-
addDiagnosticForTextRange(fileInfo,
|
2038
|
+
addDiagnosticForTextRange(fileInfo, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.codeTooComplexToAnalyze(), errorRange);
|
2037
2039
|
return true;
|
2038
2040
|
}
|
2039
2041
|
return false;
|
@@ -2099,7 +2101,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2099
2101
|
// of a Literal['xxx'] statement. If so, we will not treat
|
2100
2102
|
// the string as a normal forward-declared type annotation.
|
2101
2103
|
function isAnnotationLiteralValue(node) {
|
2102
|
-
if (node.parent && node.parent.nodeType ===
|
2104
|
+
if (node.parent && node.parent.nodeType === 27 /* ParseNodeType.Index */) {
|
2103
2105
|
const baseType = getTypeOfExpression(node.parent.baseExpression).type;
|
2104
2106
|
if (baseType && (0, types_1.isInstantiableClass)(baseType)) {
|
2105
2107
|
if (types_1.ClassType.isSpecialBuiltIn(baseType, 'Literal')) {
|
@@ -2174,7 +2176,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2174
2176
|
}
|
2175
2177
|
return diagnostic;
|
2176
2178
|
}
|
2177
|
-
function addDiagnosticForTextRange(fileInfo,
|
2179
|
+
function addDiagnosticForTextRange(fileInfo, rule, message, range) {
|
2180
|
+
const diagLevel = fileInfo.diagnosticRuleSet[rule];
|
2178
2181
|
if (diagLevel === 'none') {
|
2179
2182
|
return undefined;
|
2180
2183
|
}
|
@@ -2195,7 +2198,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2195
2198
|
}
|
2196
2199
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeExpectedClass().format({ type: printType(type) }) + diag.getString(), node);
|
2197
2200
|
}
|
2198
|
-
function assignTypeToNameNode(nameNode,
|
2201
|
+
function assignTypeToNameNode(nameNode, typeResult, ignoreEmptyContainers, srcExpression, allowAssignmentToFinalVar = false, expectedTypeDiagAddendum) {
|
2199
2202
|
var _a, _b, _c;
|
2200
2203
|
const nameValue = nameNode.value;
|
2201
2204
|
const symbolWithScope = lookUpSymbolRecursive(nameNode, nameValue, /* honorCodeFlow */ false);
|
@@ -2222,18 +2225,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2222
2225
|
}
|
2223
2226
|
}
|
2224
2227
|
// We found an existing declared type. Make sure the type is assignable.
|
2225
|
-
let destType = type;
|
2228
|
+
let destType = typeResult.type;
|
2226
2229
|
const isTypeAlias = !!declaredType && (0, types_1.isClassInstance)(declaredType) && types_1.ClassType.isBuiltIn(declaredType, 'TypeAlias');
|
2227
2230
|
if (declaredType && !isTypeAlias) {
|
2228
2231
|
let diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
2229
|
-
if (!assignType(declaredType, type, diagAddendum)) {
|
2232
|
+
if (!assignType(declaredType, typeResult.type, diagAddendum)) {
|
2230
2233
|
// If there was an expected type mismatch, use that diagnostic
|
2231
2234
|
// addendum because it will be more informative.
|
2232
2235
|
if (expectedTypeDiagAddendum) {
|
2233
2236
|
diagAddendum = expectedTypeDiagAddendum;
|
2234
2237
|
}
|
2235
|
-
if (!
|
2236
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAssignmentType, localize_1.LocMessage.typeAssignmentMismatch().format(printSrcDestTypes(type, declaredType)) +
|
2238
|
+
if (!typeResult.isIncomplete) {
|
2239
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAssignmentType, localize_1.LocMessage.typeAssignmentMismatch().format(printSrcDestTypes(typeResult.type, declaredType)) +
|
2237
2240
|
diagAddendum.getString(), srcExpression !== null && srcExpression !== void 0 ? srcExpression : nameNode, (_c = (_b = diagAddendum.getEffectiveTextRange()) !== null && _b !== void 0 ? _b : srcExpression) !== null && _c !== void 0 ? _c : nameNode);
|
2238
2241
|
}
|
2239
2242
|
// Replace the assigned type with the (unnarrowed) declared type.
|
@@ -2241,7 +2244,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2241
2244
|
}
|
2242
2245
|
else {
|
2243
2246
|
// Constrain the resulting type to match the declared type.
|
2244
|
-
destType = narrowTypeBasedOnAssignment(nameNode, declaredType, type
|
2247
|
+
destType = narrowTypeBasedOnAssignment(nameNode, declaredType, typeResult).type;
|
2245
2248
|
}
|
2246
2249
|
}
|
2247
2250
|
else {
|
@@ -2274,12 +2277,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2274
2277
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalReassigned().format({ name: nameValue }), nameNode);
|
2275
2278
|
}
|
2276
2279
|
}
|
2277
|
-
if (!
|
2280
|
+
if (!typeResult.isIncomplete) {
|
2278
2281
|
reportPossibleUnknownAssignment(fileInfo.diagnosticRuleSet.reportUnknownVariableType, diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, nameNode, destType, nameNode, ignoreEmptyContainers);
|
2279
2282
|
}
|
2280
|
-
writeTypeCache(nameNode, { type: destType, isIncomplete:
|
2283
|
+
writeTypeCache(nameNode, { type: destType, isIncomplete: typeResult.isIncomplete }, 0 /* EvaluatorFlags.None */);
|
2281
2284
|
}
|
2282
|
-
function assignTypeToMemberAccessNode(target,
|
2285
|
+
function assignTypeToMemberAccessNode(target, typeResult, srcExpr, expectedTypeDiagAddendum) {
|
2283
2286
|
var _a;
|
2284
2287
|
const baseTypeResult = getTypeOfExpression(target.leftExpression, 2 /* EvaluatorFlags.MemberAccessBaseDefaults */);
|
2285
2288
|
const baseType = makeTopLevelTypeVarsConcrete(baseTypeResult.type);
|
@@ -2292,14 +2295,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2292
2295
|
if (classTypeResults && (0, types_1.isInstantiableClass)(classTypeResults.classType)) {
|
2293
2296
|
if ((0, types_1.isClassInstance)(baseType)) {
|
2294
2297
|
if (types_1.ClassType.isSameGenericClass(baseType, classTypeResults.classType)) {
|
2295
|
-
assignTypeToMemberVariable(target,
|
2296
|
-
/* isInstanceMember */ true, srcExpr);
|
2298
|
+
assignTypeToMemberVariable(target, typeResult, /* isInstanceMember */ true, srcExpr);
|
2297
2299
|
}
|
2298
2300
|
}
|
2299
2301
|
else if ((0, types_1.isInstantiableClass)(baseType)) {
|
2300
2302
|
if (types_1.ClassType.isSameGenericClass(baseType, classTypeResults.classType)) {
|
2301
|
-
assignTypeToMemberVariable(target,
|
2302
|
-
/* isInstanceMember */ false, srcExpr);
|
2303
|
+
assignTypeToMemberVariable(target, typeResult, /* isInstanceMember */ false, srcExpr);
|
2303
2304
|
}
|
2304
2305
|
}
|
2305
2306
|
// Assignments to instance or class variables through "self" or "cls" is not
|
@@ -2320,7 +2321,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2320
2321
|
}
|
2321
2322
|
const setTypeResult = getTypeOfMemberAccessWithBaseType(target, baseTypeResult, {
|
2322
2323
|
method: 'set',
|
2323
|
-
setType:
|
2324
|
+
setType: typeResult,
|
2324
2325
|
setErrorNode: srcExpr,
|
2325
2326
|
setExpectedTypeDiag: expectedTypeDiagAddendum,
|
2326
2327
|
}, 0 /* EvaluatorFlags.None */);
|
@@ -2328,14 +2329,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2328
2329
|
setAsymmetricDescriptorAssignment(target);
|
2329
2330
|
}
|
2330
2331
|
const resultToCache = {
|
2331
|
-
type: (_a = setTypeResult.narrowedTypeForSet) !== null && _a !== void 0 ? _a : type,
|
2332
|
-
isIncomplete:
|
2332
|
+
type: (_a = setTypeResult.narrowedTypeForSet) !== null && _a !== void 0 ? _a : typeResult.type,
|
2333
|
+
isIncomplete: typeResult.isIncomplete,
|
2333
2334
|
memberAccessDeprecationInfo: setTypeResult.memberAccessDeprecationInfo,
|
2334
2335
|
};
|
2335
2336
|
writeTypeCache(target.memberName, resultToCache, 0 /* EvaluatorFlags.None */);
|
2336
2337
|
writeTypeCache(target, resultToCache, 0 /* EvaluatorFlags.None */);
|
2337
2338
|
}
|
2338
|
-
function assignTypeToMemberVariable(node,
|
2339
|
+
function assignTypeToMemberVariable(node, typeResult, isInstanceMember, srcExprNode) {
|
2339
2340
|
var _a;
|
2340
2341
|
const memberName = node.memberName.value;
|
2341
2342
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
@@ -2405,21 +2406,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2405
2406
|
// The class variable is accessed in this case.
|
2406
2407
|
setSymbolAccessed(fileInfo, memberInfo.symbol, node.memberName);
|
2407
2408
|
const memberType = getTypeOfMember(memberInfo);
|
2408
|
-
|
2409
|
+
typeResult = { ...typeResult, type: (0, types_1.combineTypes)([typeResult.type, memberType]) };
|
2409
2410
|
}
|
2410
2411
|
}
|
2411
2412
|
}
|
2412
2413
|
}
|
2413
2414
|
// Look up the member info again, now that we've potentially updated it.
|
2414
2415
|
memberInfo = (0, typeUtils_1.lookUpClassMember)(classTypeInfo.classType, memberName, 64 /* MemberAccessFlags.DeclaredTypesOnly */);
|
2415
|
-
if (!memberInfo && srcExprNode && !
|
2416
|
-
reportPossibleUnknownAssignment(fileInfo.diagnosticRuleSet.reportUnknownMemberType, diagnosticRules_1.DiagnosticRule.reportUnknownMemberType, node.memberName,
|
2416
|
+
if (!memberInfo && srcExprNode && !typeResult.isIncomplete) {
|
2417
|
+
reportPossibleUnknownAssignment(fileInfo.diagnosticRuleSet.reportUnknownMemberType, diagnosticRules_1.DiagnosticRule.reportUnknownMemberType, node.memberName, typeResult.type, node,
|
2417
2418
|
/* ignoreEmptyContainers */ true);
|
2418
2419
|
}
|
2419
2420
|
}
|
2420
2421
|
}
|
2421
|
-
function assignTypeToTupleOrListNode(target,
|
2422
|
-
const targetExpressions = target.nodeType ===
|
2422
|
+
function assignTypeToTupleOrListNode(target, typeResult, srcExpr) {
|
2423
|
+
const targetExpressions = target.nodeType === 34 /* ParseNodeType.List */ ? target.entries : target.expressions;
|
2423
2424
|
// Initialize the array of target types, one for each target.
|
2424
2425
|
const targetTypes = new Array(targetExpressions.length);
|
2425
2426
|
for (let i = 0; i < targetExpressions.length; i++) {
|
@@ -2429,9 +2430,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2429
2430
|
// Do any of the targets use an unpack operator? If so, it will consume all of the
|
2430
2431
|
// entries at that location.
|
2431
2432
|
const unpackIndex = targetExpressions.findIndex((expr) => expr.nodeType === 56 /* ParseNodeType.Unpack */);
|
2432
|
-
|
2433
|
+
typeResult = { ...typeResult, type: makeTopLevelTypeVarsConcrete(typeResult.type) };
|
2433
2434
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
2434
|
-
(0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
|
2435
|
+
(0, typeUtils_1.doForEachSubtype)(typeResult.type, (subtype) => {
|
2435
2436
|
var _a, _b;
|
2436
2437
|
// Is this subtype a tuple?
|
2437
2438
|
const tupleType = (0, typeUtils_1.getSpecializedTupleType)(subtype);
|
@@ -2453,7 +2454,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2453
2454
|
if (sourceEntryTypes.length > targetTypes.length) {
|
2454
2455
|
const removedEntries = sourceEntryTypes.splice(targetUnpackIndex, sourceEntryTypes.length - targetTypes.length + 1);
|
2455
2456
|
let combinedTypes = (0, types_1.combineTypes)(removedEntries);
|
2456
|
-
if (target.nodeType ===
|
2457
|
+
if (target.nodeType === 34 /* ParseNodeType.List */) {
|
2457
2458
|
combinedTypes = stripLiteralValue(combinedTypes);
|
2458
2459
|
}
|
2459
2460
|
sourceEntryTypes.splice(targetUnpackIndex, 0, combinedTypes);
|
@@ -2470,7 +2471,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2470
2471
|
// Have we accounted for all of the targets and sources? If not, we have a size mismatch.
|
2471
2472
|
if (sourceEntryTypes.length !== targetExpressions.length) {
|
2472
2473
|
const subDiag = diagAddendum.createAddendum();
|
2473
|
-
subDiag.addMessage((target.nodeType ===
|
2474
|
+
subDiag.addMessage((target.nodeType === 34 /* ParseNodeType.List */
|
2474
2475
|
? localize_1.LocAddendum.listAssignmentMismatch()
|
2475
2476
|
: localize_1.LocAddendum.tupleAssignmentMismatch()).format({
|
2476
2477
|
type: printType(subtype),
|
@@ -2486,17 +2487,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2486
2487
|
else {
|
2487
2488
|
// The assigned expression isn't a tuple, so it had better
|
2488
2489
|
// be some iterable type.
|
2489
|
-
const iterableType = (_b = (_a = getTypeOfIterator({ type: subtype, isIncomplete:
|
2490
|
+
const iterableType = (_b = (_a = getTypeOfIterator({ type: subtype, isIncomplete: typeResult.isIncomplete },
|
2491
|
+
/* isAsync */ false, srcExpr)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
|
2490
2492
|
for (let index = 0; index < targetExpressions.length; index++) {
|
2491
2493
|
targetTypes[index].push((0, typeUtils_1.addConditionToType)(iterableType, (0, typeUtils_1.getTypeCondition)(subtype)));
|
2492
2494
|
}
|
2493
2495
|
}
|
2494
2496
|
});
|
2495
2497
|
if (!diagAddendum.isEmpty()) {
|
2496
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAssignmentType, (target.nodeType ===
|
2498
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAssignmentType, (target.nodeType === 34 /* ParseNodeType.List */
|
2497
2499
|
? localize_1.LocMessage.listAssignmentMismatch()
|
2498
2500
|
: localize_1.LocMessage.tupleAssignmentMismatch()).format({
|
2499
|
-
type: printType(type),
|
2501
|
+
type: printType(typeResult.type),
|
2500
2502
|
}) + diagAddendum.getString(), target);
|
2501
2503
|
}
|
2502
2504
|
// Assign the resulting types to the individual names in the tuple
|
@@ -2504,9 +2506,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2504
2506
|
targetExpressions.forEach((expr, index) => {
|
2505
2507
|
const typeList = targetTypes[index];
|
2506
2508
|
const targetType = typeList.length === 0 ? types_1.UnknownType.create() : (0, types_1.combineTypes)(typeList);
|
2507
|
-
assignTypeToExpression(expr, targetType,
|
2509
|
+
assignTypeToExpression(expr, { type: targetType, isIncomplete: typeResult.isIncomplete }, srcExpr,
|
2510
|
+
/* ignoreEmptyContainers */ true);
|
2508
2511
|
});
|
2509
|
-
writeTypeCache(target,
|
2512
|
+
writeTypeCache(target, typeResult, 0 /* EvaluatorFlags.None */);
|
2510
2513
|
}
|
2511
2514
|
// If the type includes promotion types, expand these to their constituent types.
|
2512
2515
|
function expandPromotionTypes(node, type, excludeBytes = false) {
|
@@ -2542,22 +2545,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2542
2545
|
// TypeVar, only the conditions that match the filter will be included.
|
2543
2546
|
function makeTopLevelTypeVarsConcrete(type, makeParamSpecsConcrete = false, conditionFilter) {
|
2544
2547
|
return (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
|
2545
|
-
var _a
|
2548
|
+
var _a;
|
2546
2549
|
if ((0, types_1.isParamSpec)(subtype)) {
|
2547
2550
|
if (subtype.paramSpecAccess === 'args') {
|
2548
|
-
|
2549
|
-
return makeTupleObject([{ type: objectType, isUnbounded: true }]);
|
2550
|
-
}
|
2551
|
-
return types_1.UnknownType.create();
|
2551
|
+
return makeTupleObject([{ type: getObjectType(), isUnbounded: true }]);
|
2552
2552
|
}
|
2553
2553
|
else if (subtype.paramSpecAccess === 'kwargs') {
|
2554
|
-
if (
|
2555
|
-
(0,
|
2556
|
-
strClassType &&
|
2557
|
-
(0, types_1.isInstantiableClass)(strClassType) &&
|
2558
|
-
objectType &&
|
2559
|
-
(0, types_1.isClassInstance)(objectType)) {
|
2560
|
-
return types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(dictClassType, [(0, typeUtils_1.convertToInstance)(strClassType), objectType],
|
2554
|
+
if (dictClass && (0, types_1.isInstantiableClass)(dictClass) && strClass && (0, types_1.isInstantiableClass)(strClass)) {
|
2555
|
+
return types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(dictClass, [(0, typeUtils_1.convertToInstance)(strClass), getObjectType()],
|
2561
2556
|
/* isTypeArgumentExplicit */ true));
|
2562
2557
|
}
|
2563
2558
|
return types_1.UnknownType.create();
|
@@ -2565,28 +2560,27 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2565
2560
|
}
|
2566
2561
|
// If this is a function that contains only a ParamSpec (no additional
|
2567
2562
|
// parameters), convert it to a concrete type of (*args: Any, **kwargs: Any).
|
2568
|
-
if (makeParamSpecsConcrete &&
|
2569
|
-
(0,
|
2570
|
-
|
2571
|
-
|
2572
|
-
|
2563
|
+
if (makeParamSpecsConcrete && (0, types_1.isFunction)(subtype)) {
|
2564
|
+
const convertedType = (0, typeUtils_1.convertParamSpecValueToType)(subtype);
|
2565
|
+
if ((0, types_1.isParamSpec)(convertedType)) {
|
2566
|
+
return types_1.FunctionType.applyParamSpecValue(subtype, (0, typeUtils_1.getUnknownTypeForCallable)());
|
2567
|
+
}
|
2573
2568
|
}
|
2574
2569
|
if ((0, types_1.isTypeVar)(subtype) && subtype.details.isVariadic) {
|
2575
2570
|
// If it's in a union, convert to type or object.
|
2576
2571
|
if (subtype.isVariadicInUnion) {
|
2577
2572
|
if (types_1.TypeBase.isInstantiable(subtype)) {
|
2578
|
-
if (
|
2579
|
-
return
|
2573
|
+
if (typeClass && (0, types_1.isInstantiableClass)(typeClass)) {
|
2574
|
+
return typeClass;
|
2580
2575
|
}
|
2581
2576
|
}
|
2582
|
-
else
|
2583
|
-
return
|
2577
|
+
else {
|
2578
|
+
return getObjectType();
|
2584
2579
|
}
|
2585
2580
|
return types_1.AnyType.create();
|
2586
2581
|
}
|
2587
2582
|
// Fall back to "*tuple[object, ...]".
|
2588
|
-
return makeTupleObject([{ type:
|
2589
|
-
/* isUnpacked */ true);
|
2583
|
+
return makeTupleObject([{ type: getObjectType(), isUnbounded: true }], /* isUnpacked */ true);
|
2590
2584
|
}
|
2591
2585
|
if ((0, types_1.isTypeVar)(subtype)) {
|
2592
2586
|
// If this is a recursive type alias placeholder
|
@@ -2619,7 +2613,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2619
2613
|
return types_1.AnyType.create();
|
2620
2614
|
}
|
2621
2615
|
// Fall back to a bound of "object" if no bound is provided.
|
2622
|
-
let boundType = (
|
2616
|
+
let boundType = (_a = subtype.details.boundType) !== null && _a !== void 0 ? _a : getObjectType();
|
2623
2617
|
boundType = types_1.TypeBase.isInstantiable(subtype) ? (0, typeUtils_1.convertToInstantiable)(boundType) : boundType;
|
2624
2618
|
return (0, typeUtils_1.addConditionToType)(boundType, [{ typeVar: subtype, constraintIndex: 0 }]);
|
2625
2619
|
}
|
@@ -2739,9 +2733,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2739
2733
|
});
|
2740
2734
|
}
|
2741
2735
|
}
|
2742
|
-
function assignTypeToExpression(target,
|
2736
|
+
function assignTypeToExpression(target, typeResult, srcExpr, ignoreEmptyContainers = false, allowAssignmentToFinalVar = false, expectedTypeDiagAddendum) {
|
2743
2737
|
// Is the source expression a TypeVar() call?
|
2744
|
-
if ((0, types_1.isTypeVar)(type)) {
|
2738
|
+
if ((0, types_1.isTypeVar)(typeResult.type)) {
|
2745
2739
|
if (srcExpr && srcExpr.nodeType === 9 /* ParseNodeType.Call */) {
|
2746
2740
|
const callType = getTypeOfExpression(srcExpr.leftExpression, 2 /* EvaluatorFlags.CallBaseDefaults */).type;
|
2747
2741
|
if ((0, types_1.isInstantiableClass)(callType) &&
|
@@ -2749,13 +2743,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2749
2743
|
types_1.ClassType.isBuiltIn(callType, 'TypeVarTuple') ||
|
2750
2744
|
types_1.ClassType.isBuiltIn(callType, 'ParamSpec'))) {
|
2751
2745
|
const typeVarTarget = target.nodeType === 54 /* ParseNodeType.TypeAnnotation */ ? target.valueExpression : target;
|
2752
|
-
if (typeVarTarget.nodeType !== 38 /* ParseNodeType.Name */ ||
|
2753
|
-
|
2746
|
+
if (typeVarTarget.nodeType !== 38 /* ParseNodeType.Name */ ||
|
2747
|
+
typeVarTarget.value !== typeResult.type.details.name) {
|
2748
|
+
addError(typeResult.type.details.isParamSpec
|
2754
2749
|
? localize_1.LocMessage.paramSpecAssignedName().format({
|
2755
|
-
name: types_1.TypeVarType.getReadableName(type),
|
2750
|
+
name: types_1.TypeVarType.getReadableName(typeResult.type),
|
2756
2751
|
})
|
2757
2752
|
: localize_1.LocMessage.typeVarAssignedName().format({
|
2758
|
-
name: types_1.TypeVarType.getReadableName(type),
|
2753
|
+
name: types_1.TypeVarType.getReadableName(typeResult.type),
|
2759
2754
|
}), typeVarTarget);
|
2760
2755
|
}
|
2761
2756
|
}
|
@@ -2764,30 +2759,32 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2764
2759
|
// If the type was partially unbound, an error will have already been logged.
|
2765
2760
|
// Remove the unbound before assigning to the target expression so the unbound
|
2766
2761
|
// error doesn't propagate.
|
2767
|
-
type
|
2762
|
+
if ((0, types_1.findSubtype)(typeResult.type, (subtype) => (0, types_1.isUnbound)(subtype))) {
|
2763
|
+
typeResult = { ...typeResult, type: (0, types_1.removeUnbound)(typeResult.type) };
|
2764
|
+
}
|
2768
2765
|
switch (target.nodeType) {
|
2769
2766
|
case 38 /* ParseNodeType.Name */: {
|
2770
|
-
assignTypeToNameNode(target,
|
2767
|
+
assignTypeToNameNode(target, typeResult, ignoreEmptyContainers, srcExpr, allowAssignmentToFinalVar, expectedTypeDiagAddendum);
|
2771
2768
|
break;
|
2772
2769
|
}
|
2773
2770
|
case 35 /* ParseNodeType.MemberAccess */: {
|
2774
|
-
assignTypeToMemberAccessNode(target,
|
2771
|
+
assignTypeToMemberAccessNode(target, typeResult, srcExpr, expectedTypeDiagAddendum);
|
2775
2772
|
break;
|
2776
2773
|
}
|
2777
|
-
case
|
2774
|
+
case 27 /* ParseNodeType.Index */: {
|
2778
2775
|
const baseTypeResult = getTypeOfExpression(target.baseExpression, 2 /* EvaluatorFlags.IndexBaseDefaults */);
|
2779
2776
|
getTypeOfIndexWithBaseType(target, baseTypeResult, {
|
2780
2777
|
method: 'set',
|
2781
|
-
setType:
|
2778
|
+
setType: typeResult,
|
2782
2779
|
setErrorNode: srcExpr,
|
2783
2780
|
setExpectedTypeDiag: expectedTypeDiagAddendum,
|
2784
2781
|
}, 0 /* EvaluatorFlags.None */);
|
2785
|
-
writeTypeCache(target,
|
2782
|
+
writeTypeCache(target, typeResult, 0 /* EvaluatorFlags.None */);
|
2786
2783
|
break;
|
2787
2784
|
}
|
2788
|
-
case
|
2785
|
+
case 34 /* ParseNodeType.List */:
|
2789
2786
|
case 52 /* ParseNodeType.Tuple */: {
|
2790
|
-
assignTypeToTupleOrListNode(target,
|
2787
|
+
assignTypeToTupleOrListNode(target, typeResult, srcExpr);
|
2791
2788
|
break;
|
2792
2789
|
}
|
2793
2790
|
case 54 /* ParseNodeType.TypeAnnotation */: {
|
@@ -2802,23 +2799,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2802
2799
|
if (!isBareFinalOrClassVar) {
|
2803
2800
|
const isTypeAliasAnnotation = (0, types_1.isClassInstance)(annotationType) && types_1.ClassType.isBuiltIn(annotationType, 'TypeAlias');
|
2804
2801
|
if (!isTypeAliasAnnotation) {
|
2805
|
-
if (assignType(annotationType, type)) {
|
2802
|
+
if (assignType(annotationType, typeResult.type)) {
|
2806
2803
|
// Don't attempt to narrow based on the annotated type if the type
|
2807
2804
|
// is a enum because the annotated type in an enum doesn't reflect
|
2808
2805
|
// the type of the symbol.
|
2809
|
-
if (!(0, types_1.isClassInstance)(type) || !types_1.ClassType.isEnumClass(type)) {
|
2810
|
-
|
2806
|
+
if (!(0, types_1.isClassInstance)(typeResult.type) || !types_1.ClassType.isEnumClass(typeResult.type)) {
|
2807
|
+
typeResult = narrowTypeBasedOnAssignment(target, annotationType, typeResult);
|
2811
2808
|
}
|
2812
2809
|
}
|
2813
2810
|
}
|
2814
2811
|
}
|
2815
|
-
assignTypeToExpression(target.valueExpression,
|
2812
|
+
assignTypeToExpression(target.valueExpression, typeResult, srcExpr, ignoreEmptyContainers, allowAssignmentToFinalVar, expectedTypeDiagAddendum);
|
2816
2813
|
break;
|
2817
2814
|
}
|
2818
2815
|
case 56 /* ParseNodeType.Unpack */: {
|
2819
2816
|
if (target.expression.nodeType === 38 /* ParseNodeType.Name */) {
|
2820
|
-
assignTypeToNameNode(target.expression,
|
2821
|
-
|
2817
|
+
assignTypeToNameNode(target.expression, {
|
2818
|
+
type: getBuiltInObject(target.expression, 'list', [typeResult.type]),
|
2819
|
+
isIncomplete: typeResult.isIncomplete,
|
2820
|
+
}, ignoreEmptyContainers, srcExpr);
|
2822
2821
|
}
|
2823
2822
|
break;
|
2824
2823
|
}
|
@@ -2912,7 +2911,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2912
2911
|
writeTypeCache(node, resultToCache, 0 /* EvaluatorFlags.None */);
|
2913
2912
|
break;
|
2914
2913
|
}
|
2915
|
-
case
|
2914
|
+
case 27 /* ParseNodeType.Index */: {
|
2916
2915
|
const baseTypeResult = getTypeOfExpression(node.baseExpression, 2 /* EvaluatorFlags.IndexBaseDefaults */);
|
2917
2916
|
getTypeOfIndexWithBaseType(node, baseTypeResult, { method: 'del' }, 0 /* EvaluatorFlags.None */);
|
2918
2917
|
writeTypeCache(node, { type: types_1.UnboundType.create() }, 0 /* EvaluatorFlags.None */);
|
@@ -3162,8 +3161,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3162
3161
|
// Find the parse node associated with the scope that is just inside of the
|
3163
3162
|
// scope that declares the captured variable.
|
3164
3163
|
const innerScopeNode = ScopeUtils.findTopNodeInScope(node, scopeHierarchy[scopeHierarchy.length - 2]);
|
3165
|
-
if ((innerScopeNode === null || innerScopeNode === void 0 ? void 0 : innerScopeNode.nodeType) ===
|
3166
|
-
(innerScopeNode === null || innerScopeNode === void 0 ? void 0 : innerScopeNode.nodeType) ===
|
3164
|
+
if ((innerScopeNode === null || innerScopeNode === void 0 ? void 0 : innerScopeNode.nodeType) === 31 /* ParseNodeType.Function */ ||
|
3165
|
+
(innerScopeNode === null || innerScopeNode === void 0 ? void 0 : innerScopeNode.nodeType) === 33 /* ParseNodeType.Lambda */ ||
|
3167
3166
|
(innerScopeNode === null || innerScopeNode === void 0 ? void 0 : innerScopeNode.nodeType) === 10 /* ParseNodeType.Class */) {
|
3168
3167
|
const innerScopeCodeFlowNode = AnalyzerNodeInfo.getFlowNode(innerScopeNode);
|
3169
3168
|
if (innerScopeCodeFlowNode) {
|
@@ -3236,7 +3235,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3236
3235
|
const memberName = node.parent.memberName.value;
|
3237
3236
|
if (memberName === 'args' || memberName === 'kwargs') {
|
3238
3237
|
const outerFunctionScope = ParseTreeUtils.getEnclosingClassOrFunction(enclosingScope);
|
3239
|
-
if ((outerFunctionScope === null || outerFunctionScope === void 0 ? void 0 : outerFunctionScope.nodeType) ===
|
3238
|
+
if ((outerFunctionScope === null || outerFunctionScope === void 0 ? void 0 : outerFunctionScope.nodeType) === 31 /* ParseNodeType.Function */) {
|
3240
3239
|
enclosingScope = outerFunctionScope;
|
3241
3240
|
}
|
3242
3241
|
else if (!scopedTypeVarInfo.type.scopeId) {
|
@@ -3256,7 +3255,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3256
3255
|
container: enclosingScope.name.value,
|
3257
3256
|
}), node);
|
3258
3257
|
}
|
3259
|
-
type = types_1.TypeVarType.cloneForScopeId(type, ParseTreeUtils.getScopeIdForNode(enclosingScope), enclosingScope.name.value, enclosingScope.nodeType ===
|
3258
|
+
type = types_1.TypeVarType.cloneForScopeId(type, ParseTreeUtils.getScopeIdForNode(enclosingScope), enclosingScope.name.value, enclosingScope.nodeType === 31 /* ParseNodeType.Function */
|
3260
3259
|
? 1 /* TypeVarScopeType.Function */
|
3261
3260
|
: 0 /* TypeVarScopeType.Class */);
|
3262
3261
|
}
|
@@ -3327,7 +3326,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3327
3326
|
if (param.details.isDefaultExplicit || param.details.isParamSpec) {
|
3328
3327
|
defaultType = (0, typeUtils_1.applySolvedTypeVars)(param, typeVarContext, { unknownIfNotFound: true });
|
3329
3328
|
}
|
3330
|
-
else if (param.details.isVariadic &&
|
3329
|
+
else if (param.details.isVariadic && tupleClass && (0, types_1.isInstantiableClass)(tupleClass)) {
|
3331
3330
|
defaultType = makeTupleObject([{ type: types_1.UnknownType.create(), isUnbounded: true }],
|
3332
3331
|
/* isUnpackedTuple */ true);
|
3333
3332
|
}
|
@@ -3367,7 +3366,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3367
3366
|
scopeUsesTypeParameterSyntax = !!curNode.typeParameters;
|
3368
3367
|
nestedClassCount++;
|
3369
3368
|
}
|
3370
|
-
else if (curNode.nodeType ===
|
3369
|
+
else if (curNode.nodeType === 31 /* ParseNodeType.Function */) {
|
3371
3370
|
const functionType = getTypeOfFunctionPredecorated(curNode);
|
3372
3371
|
if (functionType) {
|
3373
3372
|
const functionDetails = functionType.details;
|
@@ -3731,8 +3730,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3731
3730
|
// be reported elsewhere.
|
3732
3731
|
return undefined;
|
3733
3732
|
}
|
3734
|
-
if ((0, typeUtils_1.isNoneInstance)(subtype)
|
3735
|
-
|
3733
|
+
if ((0, typeUtils_1.isNoneInstance)(subtype)) {
|
3734
|
+
(0, debug_1.assert)((0, types_1.isClassInstance)(subtype));
|
3735
|
+
const typeResult = getTypeOfBoundMember(node.memberName, subtype, memberName, usage, diag);
|
3736
3736
|
if (typeResult && !typeResult.typeErrors) {
|
3737
3737
|
type = (0, typeUtils_1.addConditionToType)(typeResult.type, (0, typeUtils_1.getTypeCondition)(baseType));
|
3738
3738
|
if (typeResult.isIncomplete) {
|
@@ -3774,7 +3774,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3774
3774
|
}
|
3775
3775
|
}
|
3776
3776
|
else {
|
3777
|
-
type = getTypeOfMemberAccessWithBaseType(node, { type:
|
3777
|
+
type = getTypeOfMemberAccessWithBaseType(node, { type: functionClass ? (0, typeUtils_1.convertToInstance)(functionClass) : types_1.UnknownType.create() }, usage, flags).type;
|
3778
3778
|
}
|
3779
3779
|
break;
|
3780
3780
|
}
|
@@ -4008,7 +4008,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4008
4008
|
// If a Final instance variable is declared in the class body but is
|
4009
4009
|
// being assigned within an __init__ method, it's allowed.
|
4010
4010
|
const enclosingFunctionNode = ParseTreeUtils.getEnclosingFunction(errorNode);
|
4011
|
-
if (!enclosingFunctionNode ||
|
4011
|
+
if (!enclosingFunctionNode ||
|
4012
|
+
enclosingFunctionNode.name.value !== '__init__' ||
|
4013
|
+
finalVarTypeDecl.inferredTypeSource !== undefined ||
|
4014
|
+
(0, types_1.isInstantiableClass)(classType)) {
|
4012
4015
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocMessage.finalReassigned().format({ name: memberName }));
|
4013
4016
|
isDescriptorError = true;
|
4014
4017
|
}
|
@@ -4030,7 +4033,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4030
4033
|
// descriptor-based accesses.
|
4031
4034
|
narrowedTypeForSet = isDescriptorApplied
|
4032
4035
|
? usage.setType.type
|
4033
|
-
: narrowTypeBasedOnAssignment(errorNode, type, usage.setType.type
|
4036
|
+
: narrowTypeBasedOnAssignment(errorNode, type, usage.setType).type;
|
4034
4037
|
}
|
4035
4038
|
// Verify that the assigned type is compatible.
|
4036
4039
|
if (!assignType(type, usage.setType.type, diag === null || diag === void 0 ? void 0 : diag.createAddendum())) {
|
@@ -4317,7 +4320,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4317
4320
|
// If there's no declared return type on the getter, assume it's symmetric.
|
4318
4321
|
if (setterType.details.parameters.length >= 3 && getterType.details.declaredReturnType) {
|
4319
4322
|
const setterValueType = types_1.FunctionType.getEffectiveParameterType(setterType, 2);
|
4320
|
-
const getterReturnType = (_a = types_1.FunctionType.
|
4323
|
+
const getterReturnType = (_a = types_1.FunctionType.getEffectiveReturnType(getterType)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
|
4321
4324
|
if (!(0, types_1.isTypeSame)(setterValueType, getterReturnType)) {
|
4322
4325
|
isAsymmetric = true;
|
4323
4326
|
}
|
@@ -4349,7 +4352,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4349
4352
|
// If there's no declared return type on the getter, assume it's symmetric.
|
4350
4353
|
if (setterType.details.parameters.length >= 3 && getterType.details.declaredReturnType) {
|
4351
4354
|
const setterValueType = types_1.FunctionType.getEffectiveParameterType(setterType, 2);
|
4352
|
-
const getterReturnType = (_a = types_1.FunctionType.
|
4355
|
+
const getterReturnType = (_a = types_1.FunctionType.getEffectiveReturnType(getterType)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
|
4353
4356
|
if (!(0, types_1.isTypeSame)(setterValueType, getterReturnType)) {
|
4354
4357
|
isAsymmetric = true;
|
4355
4358
|
}
|
@@ -4392,8 +4395,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4392
4395
|
argList.push({
|
4393
4396
|
argumentCategory: 0 /* ArgumentCategory.Simple */,
|
4394
4397
|
typeResult: {
|
4395
|
-
type:
|
4396
|
-
? types_1.ClassType.cloneWithLiteral(types_1.ClassType.cloneAsInstance(
|
4398
|
+
type: strClass && (0, types_1.isInstantiableClass)(strClass)
|
4399
|
+
? types_1.ClassType.cloneWithLiteral(types_1.ClassType.cloneAsInstance(strClass), memberName)
|
4397
4400
|
: types_1.AnyType.create(),
|
4398
4401
|
},
|
4399
4402
|
});
|
@@ -4715,11 +4718,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4715
4718
|
if (index === concatTypeArgs.length - 1) {
|
4716
4719
|
types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
|
4717
4720
|
if ((0, types_1.isParamSpec)(typeArg)) {
|
4718
|
-
|
4721
|
+
types_1.FunctionType.addParamSpecVariadics(functionType, typeArg);
|
4719
4722
|
}
|
4720
4723
|
else if ((0, typeUtils_1.isEllipsisType)(typeArg)) {
|
4721
4724
|
types_1.FunctionType.addDefaultParameters(functionType);
|
4722
|
-
functionType.details.flags |= 32768 /* FunctionTypeFlags.
|
4725
|
+
functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
|
4723
4726
|
}
|
4724
4727
|
}
|
4725
4728
|
else {
|
@@ -4736,7 +4739,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4736
4739
|
(0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, functionType, diag, typeVarContext, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */);
|
4737
4740
|
}
|
4738
4741
|
else if ((0, typeUtils_1.isEllipsisType)(typeArgType)) {
|
4739
|
-
const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */ | 32768 /* FunctionTypeFlags.
|
4742
|
+
const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */ | 32768 /* FunctionTypeFlags.GradualCallableForm */);
|
4740
4743
|
types_1.FunctionType.addDefaultParameters(functionType);
|
4741
4744
|
(0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, functionType, diag, typeVarContext);
|
4742
4745
|
}
|
@@ -4901,17 +4904,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4901
4904
|
types_1.ClassType.isPartiallyEvaluated(concreteSubtype);
|
4902
4905
|
const isFinalAnnotation = (0, types_1.isInstantiableClass)(concreteSubtype) && types_1.ClassType.isBuiltIn(concreteSubtype, 'Final');
|
4903
4906
|
const isClassVarAnnotation = (0, types_1.isInstantiableClass)(concreteSubtype) && types_1.ClassType.isBuiltIn(concreteSubtype, 'ClassVar');
|
4904
|
-
// Inlined TypedDicts are supported only for 'dict' (and not for 'Dict').
|
4905
|
-
// This feature is currently experimental.
|
4906
|
-
const supportsTypedDictTypeArg = AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures &&
|
4907
|
-
types_1.ClassType.isBuiltIn(concreteSubtype, 'dict') &&
|
4908
|
-
!types_1.ClassType.isBuiltIn(concreteSubtype, 'Dict');
|
4909
4907
|
let typeArgs = getTypeArgs(node, flags, {
|
4910
4908
|
isAnnotatedClass,
|
4911
4909
|
hasCustomClassGetItem: hasCustomClassGetItem || !isGenericClass,
|
4912
4910
|
isFinalAnnotation,
|
4913
4911
|
isClassVarAnnotation,
|
4914
|
-
supportsTypedDictTypeArg,
|
4915
4912
|
});
|
4916
4913
|
if (!isAnnotatedClass) {
|
4917
4914
|
typeArgs = adjustTypeArgumentsForVariadicTypeVar(typeArgs, concreteSubtype.details.typeParameters, node);
|
@@ -5059,8 +5056,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5059
5056
|
});
|
5060
5057
|
}
|
5061
5058
|
function makeTupleObject(typeArgs, isUnpackedTuple = false) {
|
5062
|
-
if (
|
5063
|
-
return (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(
|
5059
|
+
if (tupleClass && (0, types_1.isInstantiableClass)(tupleClass)) {
|
5060
|
+
return (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClass, typeArgs, /* isTypeArgumentExplicit */ true, isUnpackedTuple));
|
5064
5061
|
}
|
5065
5062
|
return types_1.UnknownType.create();
|
5066
5063
|
}
|
@@ -5371,7 +5368,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5371
5368
|
};
|
5372
5369
|
}
|
5373
5370
|
else {
|
5374
|
-
typeResult = getTypeArg(expr, adjFlags
|
5371
|
+
typeResult = getTypeArg(expr, adjFlags);
|
5375
5372
|
}
|
5376
5373
|
return typeResult;
|
5377
5374
|
};
|
@@ -5415,7 +5412,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5415
5412
|
}
|
5416
5413
|
return typeArgs;
|
5417
5414
|
}
|
5418
|
-
function getTypeArg(node, flags
|
5415
|
+
function getTypeArg(node, flags) {
|
5419
5416
|
let typeResult;
|
5420
5417
|
let adjustedFlags = flags |
|
5421
5418
|
128 /* EvaluatorFlags.ExpectingInstantiableType */ |
|
@@ -5425,7 +5422,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5425
5422
|
if (fileInfo.isStubFile) {
|
5426
5423
|
adjustedFlags |= 4 /* EvaluatorFlags.AllowForwardReferences */;
|
5427
5424
|
}
|
5428
|
-
if (node.nodeType ===
|
5425
|
+
if (node.nodeType === 34 /* ParseNodeType.List */) {
|
5429
5426
|
typeResult = {
|
5430
5427
|
type: types_1.UnknownType.create(),
|
5431
5428
|
typeList: node.entries.map((entry) => {
|
@@ -5436,20 +5433,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5436
5433
|
// Set the node's type so it isn't reevaluated later.
|
5437
5434
|
setTypeResultForNode(node, { type: types_1.UnknownType.create() });
|
5438
5435
|
}
|
5439
|
-
else if (node.nodeType === 15 /* ParseNodeType.Dictionary */ && supportsDictExpression) {
|
5440
|
-
const inlinedTypeDict = typedDictClassType && (0, types_1.isInstantiableClass)(typedDictClassType)
|
5441
|
-
? (0, typedDicts_1.createTypedDictTypeInlined)(evaluatorInterface, node, typedDictClassType)
|
5442
|
-
: undefined;
|
5443
|
-
const keyTypeFallback = strClassType && (0, types_1.isInstantiableClass)(strClassType) ? strClassType : types_1.UnknownType.create();
|
5444
|
-
typeResult = {
|
5445
|
-
type: keyTypeFallback,
|
5446
|
-
inlinedTypeDict,
|
5447
|
-
node,
|
5448
|
-
};
|
5449
|
-
}
|
5450
5436
|
else {
|
5451
5437
|
typeResult = { ...getTypeOfExpression(node, adjustedFlags), node };
|
5452
|
-
if (node.nodeType ===
|
5438
|
+
if (node.nodeType === 18 /* ParseNodeType.Dictionary */) {
|
5453
5439
|
addError(localize_1.LocMessage.dictInAnnotation(), node);
|
5454
5440
|
}
|
5455
5441
|
if ((flags & 131072 /* EvaluatorFlags.DisallowClassVar */) !== 0) {
|
@@ -5525,7 +5511,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5525
5511
|
if (!(0, types_1.isClassInstance)(inferenceContext.expectedType)) {
|
5526
5512
|
return undefined;
|
5527
5513
|
}
|
5528
|
-
if (!
|
5514
|
+
if (!tupleClass || !(0, types_1.isInstantiableClass)(tupleClass)) {
|
5529
5515
|
return undefined;
|
5530
5516
|
}
|
5531
5517
|
// Build an array of expected types.
|
@@ -5545,11 +5531,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5545
5531
|
}
|
5546
5532
|
}
|
5547
5533
|
else {
|
5548
|
-
const tupleTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(
|
5549
|
-
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(
|
5534
|
+
const tupleTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(tupleClass));
|
5535
|
+
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(tupleClass), inferenceContext.expectedType, tupleTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
|
5550
5536
|
return undefined;
|
5551
5537
|
}
|
5552
|
-
const specializedTuple = (0, typeUtils_1.applySolvedTypeVars)(
|
5538
|
+
const specializedTuple = (0, typeUtils_1.applySolvedTypeVars)(tupleClass, tupleTypeVarContext);
|
5553
5539
|
if (!specializedTuple.typeArguments || specializedTuple.typeArguments.length !== 1) {
|
5554
5540
|
return undefined;
|
5555
5541
|
}
|
@@ -5641,7 +5627,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5641
5627
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeCallNotAllowed() + diag.getString(), node);
|
5642
5628
|
}
|
5643
5629
|
// Handle immediate calls of lambdas specially.
|
5644
|
-
if (node.leftExpression.nodeType ===
|
5630
|
+
if (node.leftExpression.nodeType === 33 /* ParseNodeType.Lambda */) {
|
5645
5631
|
baseTypeResult = getTypeOfLambdaForCall(node, inferenceContext);
|
5646
5632
|
}
|
5647
5633
|
else {
|
@@ -5748,7 +5734,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5748
5734
|
// to determine the lambda's type. It needs to be inferred from the argument
|
5749
5735
|
// types instead.
|
5750
5736
|
function getTypeOfLambdaForCall(node, inferenceContext) {
|
5751
|
-
(0, debug_1.assert)(node.leftExpression.nodeType ===
|
5737
|
+
(0, debug_1.assert)(node.leftExpression.nodeType === 33 /* ParseNodeType.Lambda */);
|
5752
5738
|
const expectedType = types_1.FunctionType.createSynthesizedInstance('');
|
5753
5739
|
expectedType.details.declaredReturnType = inferenceContext
|
5754
5740
|
? inferenceContext.expectedType
|
@@ -5855,24 +5841,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5855
5841
|
const type = typeResult.type;
|
5856
5842
|
const exprString = ParseTreeUtils.printExpression(arg0Value);
|
5857
5843
|
const typeString = printType(type, { expandTypeAlias: true });
|
5858
|
-
if (
|
5859
|
-
if (expectedText !==
|
5860
|
-
|
5861
|
-
|
5862
|
-
|
5863
|
-
|
5844
|
+
if (!typeResult.isIncomplete) {
|
5845
|
+
if (expectedText !== undefined) {
|
5846
|
+
if (expectedText !== typeString) {
|
5847
|
+
addError(localize_1.LocMessage.revealTypeExpectedTextMismatch().format({
|
5848
|
+
expected: expectedText,
|
5849
|
+
received: typeString,
|
5850
|
+
}), expectedTextNode !== null && expectedTextNode !== void 0 ? expectedTextNode : arg0Value);
|
5851
|
+
}
|
5864
5852
|
}
|
5865
|
-
|
5866
|
-
|
5867
|
-
|
5868
|
-
|
5869
|
-
|
5870
|
-
|
5871
|
-
|
5872
|
-
}
|
5853
|
+
if (expectedRevealType) {
|
5854
|
+
if (!(0, types_1.isTypeSame)(expectedRevealType, type, { ignorePseudoGeneric: true })) {
|
5855
|
+
const expectedRevealTypeText = printType(expectedRevealType);
|
5856
|
+
addError(localize_1.LocMessage.revealTypeExpectedTypeMismatch().format({
|
5857
|
+
expected: expectedRevealTypeText,
|
5858
|
+
received: typeString,
|
5859
|
+
}), expectedRevealTypeNode !== null && expectedRevealTypeNode !== void 0 ? expectedRevealTypeNode : arg0Value);
|
5860
|
+
}
|
5873
5861
|
}
|
5862
|
+
addInformation(localize_1.LocAddendum.typeOfSymbol().format({ name: exprString, type: typeString }), node.arguments[0]);
|
5874
5863
|
}
|
5875
|
-
addInformation(localize_1.LocAddendum.typeOfSymbol().format({ name: exprString, type: typeString }), node.arguments[0]);
|
5876
5864
|
return { type, isIncomplete: typeResult.isIncomplete };
|
5877
5865
|
}
|
5878
5866
|
function getTypeOfRevealLocals(node) {
|
@@ -5882,7 +5870,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5882
5870
|
scope = ScopeUtils.getScopeForNode(curNode);
|
5883
5871
|
// Stop when we get a valid scope that's not a list comprehension
|
5884
5872
|
// scope. That includes lambdas, functions, classes, and modules.
|
5885
|
-
if (scope && scope.type !== 1 /* ScopeType.
|
5873
|
+
if (scope && scope.type !== 1 /* ScopeType.Comprehension */) {
|
5886
5874
|
break;
|
5887
5875
|
}
|
5888
5876
|
curNode = curNode.parent;
|
@@ -6058,10 +6046,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6058
6046
|
}
|
6059
6047
|
else if (effectiveTargetClass &&
|
6060
6048
|
!(0, types_1.isAnyOrUnknown)(effectiveTargetClass) &&
|
6061
|
-
!(0, typeUtils_1.derivesFromAnyOrUnknown)(effectiveTargetClass)
|
6062
|
-
|
6063
|
-
(0, types_1.isClassInstance)(objectType)) {
|
6064
|
-
resultType = types_1.ClassType.cloneAsInstantiable(objectType);
|
6049
|
+
!(0, typeUtils_1.derivesFromAnyOrUnknown)(effectiveTargetClass)) {
|
6050
|
+
resultType = objectClass !== null && objectClass !== void 0 ? objectClass : types_1.UnknownType.create();
|
6065
6051
|
}
|
6066
6052
|
else {
|
6067
6053
|
resultType = types_1.UnknownType.create();
|
@@ -6102,9 +6088,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6102
6088
|
return { type: resultIsInstance ? (0, typeUtils_1.convertToInstance)(nextBaseClassType) : nextBaseClassType };
|
6103
6089
|
}
|
6104
6090
|
// There's not much we can say about the type. Simply return object or type.
|
6105
|
-
if (
|
6091
|
+
if (typeClass && (0, types_1.isInstantiableClass)(typeClass)) {
|
6106
6092
|
return {
|
6107
|
-
type: resultIsInstance ?
|
6093
|
+
type: resultIsInstance ? getObjectType() : (0, typeUtils_1.convertToInstance)(typeClass),
|
6108
6094
|
};
|
6109
6095
|
}
|
6110
6096
|
}
|
@@ -7063,7 +7049,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7063
7049
|
// If this is a tuple with specified element types, use those
|
7064
7050
|
// specified types rather than using the more generic iterator
|
7065
7051
|
// type which will be a union of all element types.
|
7066
|
-
const combinedArgType = (0, typeUtils_1.combineSameSizedTuples)(makeTopLevelTypeVarsConcrete(argType),
|
7052
|
+
const combinedArgType = (0, typeUtils_1.combineSameSizedTuples)(makeTopLevelTypeVarsConcrete(argType), tupleClass);
|
7067
7053
|
if ((0, types_1.isClassInstance)(combinedArgType) && (0, typeUtils_1.isTupleClass)(combinedArgType)) {
|
7068
7054
|
const tupleTypeArgs = (_a = combinedArgType.tupleTypeArguments) !== null && _a !== void 0 ? _a : [];
|
7069
7055
|
if (tupleTypeArgs.length !== 1 || !tupleTypeArgs[0].isUnbounded) {
|
@@ -7109,6 +7095,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7109
7095
|
let reportedArgError = false;
|
7110
7096
|
let isTypeIncomplete = !!typeResult.isIncomplete;
|
7111
7097
|
let isVariadicTypeVarFullyMatched = false;
|
7098
|
+
const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(typeResult.type);
|
7112
7099
|
// Expand any unpacked tuples in the arg list.
|
7113
7100
|
argList = expandArgList(argList, signatureTracker);
|
7114
7101
|
// Build a map of parameters by name.
|
@@ -7134,6 +7121,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7134
7121
|
let paramSpecArgList;
|
7135
7122
|
let paramSpecTarget;
|
7136
7123
|
let hasParamSpecArgsKwargs = false;
|
7124
|
+
// Determine how many positional args are being passed before
|
7125
|
+
// we see a keyword arg.
|
7126
|
+
let positionalArgCount = argList.findIndex((arg) => arg.argumentCategory === 2 /* ArgumentCategory.UnpackedDictionary */ || arg.name !== undefined);
|
7127
|
+
if (positionalArgCount < 0) {
|
7128
|
+
positionalArgCount = argList.length;
|
7129
|
+
}
|
7137
7130
|
if (varArgListParamIndex !== undefined && varArgDictParamIndex !== undefined) {
|
7138
7131
|
(0, debug_1.assert)(paramDetails.params[varArgListParamIndex], 'varArgListParamIndex params entry is undefined');
|
7139
7132
|
const varArgListParam = paramDetails.params[varArgListParamIndex].param;
|
@@ -7155,16 +7148,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7155
7148
|
}
|
7156
7149
|
else {
|
7157
7150
|
positionalOnlyLimitIndex = varArgListParamIndex;
|
7151
|
+
positionalArgCount = varArgListParamIndex;
|
7152
|
+
positionParamLimitIndex = varArgListParamIndex;
|
7158
7153
|
}
|
7159
7154
|
}
|
7160
7155
|
}
|
7161
|
-
else if (
|
7162
|
-
|
7163
|
-
if ((_c = (0, typeUtils_1.getTypeVarScopeIds)(typeResult.type)) === null || _c === void 0 ? void 0 : _c.some((id) => id === paramSpecScopeId)) {
|
7156
|
+
else if (paramSpec) {
|
7157
|
+
if ((_c = (0, typeUtils_1.getTypeVarScopeIds)(typeResult.type)) === null || _c === void 0 ? void 0 : _c.some((id) => id === paramSpec.scopeId)) {
|
7164
7158
|
hasParamSpecArgsKwargs = true;
|
7165
7159
|
paramSpecArgList = [];
|
7166
|
-
paramSpecTarget =
|
7167
|
-
/* access */ undefined);
|
7160
|
+
paramSpecTarget = paramSpec;
|
7168
7161
|
}
|
7169
7162
|
}
|
7170
7163
|
// If there are keyword arguments present after a *args argument,
|
@@ -7194,12 +7187,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7194
7187
|
if (positionParamLimitIndex < 0) {
|
7195
7188
|
positionParamLimitIndex = paramDetails.params.length;
|
7196
7189
|
}
|
7197
|
-
// Determine how many positional args are being passed before
|
7198
|
-
// we see a keyword arg.
|
7199
|
-
let positionalArgCount = argList.findIndex((arg) => arg.argumentCategory === 2 /* ArgumentCategory.UnpackedDictionary */ || arg.name !== undefined);
|
7200
|
-
if (positionalArgCount < 0) {
|
7201
|
-
positionalArgCount = argList.length;
|
7202
|
-
}
|
7203
7190
|
let validateArgTypeParams = [];
|
7204
7191
|
let activeParam;
|
7205
7192
|
function trySetActive(arg, param) {
|
@@ -7576,13 +7563,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7576
7563
|
reportedArgError = true;
|
7577
7564
|
}
|
7578
7565
|
}
|
7579
|
-
else if (
|
7580
|
-
(0, parameterUtils_1.isParamSpecKwargsArgument)(typeResult.type.details.paramSpec, argType)) {
|
7566
|
+
else if (paramSpec && (0, parameterUtils_1.isParamSpecKwargsArgument)(paramSpec, argType)) {
|
7581
7567
|
unpackedDictionaryArgType = types_1.AnyType.create();
|
7582
7568
|
if (!paramSpecArgList) {
|
7583
7569
|
validateArgTypeParams.push({
|
7584
7570
|
paramCategory: 2 /* ParameterCategory.KwargsDict */,
|
7585
|
-
paramType:
|
7571
|
+
paramType: paramSpec,
|
7586
7572
|
requiresTypeVarMatching: false,
|
7587
7573
|
argument: argList[argIndex],
|
7588
7574
|
argType: (0, types_1.isParamSpec)(argType) ? undefined : types_1.AnyType.create(),
|
@@ -7592,20 +7578,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7592
7578
|
}
|
7593
7579
|
else {
|
7594
7580
|
const strObjType = getBuiltInObject(errorNode, 'str');
|
7595
|
-
if (
|
7596
|
-
(0, types_1.isInstantiableClass)(
|
7581
|
+
if (supportsKeysAndGetItemClass &&
|
7582
|
+
(0, types_1.isInstantiableClass)(supportsKeysAndGetItemClass) &&
|
7597
7583
|
strObjType &&
|
7598
7584
|
(0, types_1.isClassInstance)(strObjType)) {
|
7599
|
-
const mappingTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(
|
7585
|
+
const mappingTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(supportsKeysAndGetItemClass));
|
7600
7586
|
let isValidMappingType = false;
|
7601
7587
|
// If this was a TypeVar (e.g. for pseudo-generic classes),
|
7602
7588
|
// don't emit this error.
|
7603
7589
|
if ((0, types_1.isTypeVar)(argType)) {
|
7604
7590
|
isValidMappingType = true;
|
7605
7591
|
}
|
7606
|
-
else if (assignType(types_1.ClassType.cloneAsInstance(
|
7592
|
+
else if (assignType(types_1.ClassType.cloneAsInstance(supportsKeysAndGetItemClass), argType,
|
7607
7593
|
/* diag */ undefined, mappingTypeVarContext)) {
|
7608
|
-
const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(
|
7594
|
+
const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(supportsKeysAndGetItemClass, mappingTypeVarContext);
|
7609
7595
|
const typeArgs = specializedMapping.typeArguments;
|
7610
7596
|
if (typeArgs && typeArgs.length >= 2) {
|
7611
7597
|
if (assignType(strObjType, typeArgs[0])) {
|
@@ -7720,17 +7706,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7720
7706
|
else if (argList[argIndex].argumentCategory === 1 /* ArgumentCategory.UnpackedList */) {
|
7721
7707
|
// Handle the case where a *args: P.args (or *args: Any) is passed as an
|
7722
7708
|
// argument to a function that accepts a ParamSpec.
|
7723
|
-
if (
|
7709
|
+
if (paramSpec) {
|
7724
7710
|
const argTypeResult = getTypeOfArgument(argList[argIndex],
|
7725
7711
|
/* inferenceContext */ undefined, signatureTracker);
|
7726
7712
|
const argType = argTypeResult.type;
|
7727
7713
|
if (argTypeResult.isIncomplete) {
|
7728
7714
|
isTypeIncomplete = true;
|
7729
7715
|
}
|
7730
|
-
if ((0, parameterUtils_1.isParamSpecArgsArgument)(
|
7716
|
+
if ((0, parameterUtils_1.isParamSpecArgsArgument)(paramSpec, argType)) {
|
7731
7717
|
validateArgTypeParams.push({
|
7732
7718
|
paramCategory: 1 /* ParameterCategory.ArgsList */,
|
7733
|
-
paramType:
|
7719
|
+
paramType: paramSpec,
|
7734
7720
|
requiresTypeVarMatching: false,
|
7735
7721
|
argument: argList[argIndex],
|
7736
7722
|
argType: (0, types_1.isParamSpec)(argType) ? undefined : types_1.AnyType.create(),
|
@@ -7939,7 +7925,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7939
7925
|
(0, types_1.isAnyOrUnknown)(inferenceContext.expectedType) ||
|
7940
7926
|
(0, types_1.isNever)(inferenceContext.expectedType) ||
|
7941
7927
|
!type.details.declaredReturnType ||
|
7942
|
-
!(0, typeUtils_1.requiresSpecialization)((_a = types_1.FunctionType.
|
7928
|
+
!(0, typeUtils_1.requiresSpecialization)((_a = types_1.FunctionType.getEffectiveReturnType(type)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create())) {
|
7943
7929
|
return validateFunctionArgumentTypes(errorNode, matchResults, typeVarContext, signatureTracker, skipUnknownArgCheck);
|
7944
7930
|
}
|
7945
7931
|
const effectiveReturnType = getFunctionEffectiveReturnType(type);
|
@@ -8030,6 +8016,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8030
8016
|
let specializedInitSelfType;
|
8031
8017
|
let anyOrUnknownArgument;
|
8032
8018
|
const typeCondition = (0, typeUtils_1.getTypeCondition)(type);
|
8019
|
+
const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(type);
|
8033
8020
|
// Check for an attempt to invoke an unimplemented abstract method.
|
8034
8021
|
if (type.boundToType && !type.boundToType.includeSubclasses && type.details.methodClass) {
|
8035
8022
|
const abstractSymbolInfo = getAbstractSymbolInfo(type.details.methodClass, type.details.name);
|
@@ -8050,7 +8037,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8050
8037
|
}
|
8051
8038
|
}
|
8052
8039
|
// The type annotation for the "self" parameter in an __init__ method to
|
8053
|
-
// can
|
8040
|
+
// can influence the type being constructed.
|
8054
8041
|
if (type.details.name === '__init__' &&
|
8055
8042
|
type.strippedFirstParamType &&
|
8056
8043
|
type.boundToType &&
|
@@ -8159,14 +8146,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8159
8146
|
? (0, typeUtils_1.preserveUnknown)(argResult.argType, anyOrUnknownArgument)
|
8160
8147
|
: argResult.argType;
|
8161
8148
|
}
|
8162
|
-
if (
|
8149
|
+
if (paramSpec) {
|
8163
8150
|
if (argParam.argument.argumentCategory === 1 /* ArgumentCategory.UnpackedList */) {
|
8164
|
-
if ((0, parameterUtils_1.isParamSpecArgsArgument)(
|
8151
|
+
if ((0, parameterUtils_1.isParamSpecArgsArgument)(paramSpec, argResult.argType)) {
|
8165
8152
|
sawParamSpecArgs = true;
|
8166
8153
|
}
|
8167
8154
|
}
|
8168
8155
|
if (argParam.argument.argumentCategory === 2 /* ArgumentCategory.UnpackedDictionary */) {
|
8169
|
-
if ((0, parameterUtils_1.isParamSpecKwargsArgument)(
|
8156
|
+
if ((0, parameterUtils_1.isParamSpecKwargsArgument)(paramSpec, argResult.argType)) {
|
8170
8157
|
sawParamSpecKwargs = true;
|
8171
8158
|
}
|
8172
8159
|
}
|
@@ -8182,10 +8169,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8182
8169
|
}
|
8183
8170
|
paramSpecTypeVarContext = paramSpecArgResult.typeVarContexts;
|
8184
8171
|
}
|
8185
|
-
else if (
|
8172
|
+
else if (paramSpec) {
|
8186
8173
|
if (!sawParamSpecArgs || !sawParamSpecKwargs) {
|
8187
8174
|
if (!isTypeIncomplete) {
|
8188
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.paramSpecArgsMissing().format({ type: printType(
|
8175
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.paramSpecArgsMissing().format({ type: printType(paramSpec) }), errorNode);
|
8189
8176
|
}
|
8190
8177
|
argumentErrors = true;
|
8191
8178
|
argumentMatchScore += 1;
|
@@ -8252,7 +8239,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8252
8239
|
types_1.ClassType.isBuiltIn(specializedReturnType, ['TypeGuard', 'TypeIs']) &&
|
8253
8240
|
specializedReturnType.typeArguments &&
|
8254
8241
|
specializedReturnType.typeArguments.length > 0) {
|
8255
|
-
if (
|
8242
|
+
if (boolClass && (0, types_1.isInstantiableClass)(boolClass)) {
|
8256
8243
|
let typeGuardType = specializedReturnType.typeArguments[0];
|
8257
8244
|
// If the first argument is a simple (non-constrained) TypeVar,
|
8258
8245
|
// associate that TypeVar with the resulting TypeGuard type.
|
@@ -8267,7 +8254,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8267
8254
|
}
|
8268
8255
|
}
|
8269
8256
|
const useTypeIsSemantics = types_1.ClassType.isBuiltIn(specializedReturnType, 'TypeIs');
|
8270
|
-
specializedReturnType = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForTypeGuard(
|
8257
|
+
specializedReturnType = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForTypeGuard(boolClass, typeGuardType, useTypeIsSemantics));
|
8271
8258
|
}
|
8272
8259
|
}
|
8273
8260
|
const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(errorNode);
|
@@ -8408,39 +8395,42 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8408
8395
|
});
|
8409
8396
|
return { argumentErrors: true, typeVarContexts: [srcTypeVarContext] };
|
8410
8397
|
}
|
8398
|
+
const functionParamSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(functionType);
|
8399
|
+
const functionWithoutParamSpec = types_1.FunctionType.cloneRemoveParamSpecArgsKwargs(functionType);
|
8411
8400
|
// Handle the recursive case where we're passing (*args: P.args, **kwargs: P.args)
|
8412
8401
|
// a remaining function of type (*P).
|
8413
|
-
if (
|
8414
|
-
|
8415
|
-
(0, types_1.isTypeSame)(
|
8402
|
+
if (functionParamSpec &&
|
8403
|
+
functionWithoutParamSpec.details.parameters.length === 0 &&
|
8404
|
+
(0, types_1.isTypeSame)(functionParamSpec, paramSpec)) {
|
8416
8405
|
// If there are any arguments other than *args: P.args or **kwargs: P.kwargs,
|
8417
8406
|
// report an error.
|
8418
|
-
let
|
8419
|
-
let
|
8407
|
+
let argsCount = 0;
|
8408
|
+
let kwargsCount = 0;
|
8420
8409
|
let argumentErrors = false;
|
8421
8410
|
let argErrorNode;
|
8422
8411
|
for (const arg of argList) {
|
8423
8412
|
const argType = (_a = getTypeOfArgument(arg, /* inferenceContext */ undefined, signatureTracker)) === null || _a === void 0 ? void 0 : _a.type;
|
8424
|
-
|
8425
|
-
|
8426
|
-
|
8413
|
+
if (arg.argumentCategory === 1 /* ArgumentCategory.UnpackedList */) {
|
8414
|
+
if ((0, parameterUtils_1.isParamSpecArgsArgument)(paramSpec, argType)) {
|
8415
|
+
argsCount++;
|
8416
|
+
}
|
8427
8417
|
}
|
8428
|
-
else if (arg.argumentCategory === 2 /* ArgumentCategory.UnpackedDictionary */
|
8429
|
-
|
8430
|
-
|
8431
|
-
|
8418
|
+
else if (arg.argumentCategory === 2 /* ArgumentCategory.UnpackedDictionary */) {
|
8419
|
+
if ((0, parameterUtils_1.isParamSpecKwargsArgument)(paramSpec, argType)) {
|
8420
|
+
kwargsCount++;
|
8421
|
+
}
|
8432
8422
|
}
|
8433
8423
|
else {
|
8434
8424
|
argErrorNode = argErrorNode !== null && argErrorNode !== void 0 ? argErrorNode : arg.valueExpression;
|
8435
8425
|
argumentErrors = true;
|
8436
8426
|
}
|
8437
8427
|
}
|
8438
|
-
if (
|
8428
|
+
if (argsCount !== 1 || kwargsCount !== 1) {
|
8439
8429
|
argumentErrors = true;
|
8440
8430
|
}
|
8441
8431
|
if (argumentErrors) {
|
8442
8432
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.paramSpecArgsMissing().format({
|
8443
|
-
type: printType(
|
8433
|
+
type: printType(functionParamSpec),
|
8444
8434
|
}), argErrorNode !== null && argErrorNode !== void 0 ? argErrorNode : errorNode);
|
8445
8435
|
}
|
8446
8436
|
return { argumentErrors, typeVarContexts: [srcTypeVarContext] };
|
@@ -8473,7 +8463,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8473
8463
|
// the solved TypeVars if the typeVarContext has more than one signature.
|
8474
8464
|
// This will expand the ParamSpec into an overload, which will cause problems.
|
8475
8465
|
const skipApplySolvedTypeVars = (0, types_1.isFunction)(argParam.paramType) &&
|
8476
|
-
|
8466
|
+
types_1.FunctionType.getParamSpecFromArgsKwargs(argParam.paramType) &&
|
8477
8467
|
typeVarContext.getSignatureContexts().length > 1;
|
8478
8468
|
if (!skipApplySolvedTypeVars) {
|
8479
8469
|
expectedType = (0, typeUtils_1.applySolvedTypeVars)(expectedType, typeVarContext, {
|
@@ -8990,12 +8980,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8990
8980
|
}
|
8991
8981
|
function getParamSpecDefaultType(node, isPep695Syntax) {
|
8992
8982
|
const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */);
|
8993
|
-
if (node.nodeType ===
|
8983
|
+
if (node.nodeType === 21 /* ParseNodeType.Ellipsis */) {
|
8994
8984
|
types_1.FunctionType.addDefaultParameters(functionType);
|
8995
|
-
functionType.details.flags |= 32768 /* FunctionTypeFlags.
|
8985
|
+
functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
|
8996
8986
|
return functionType;
|
8997
8987
|
}
|
8998
|
-
if (node.nodeType ===
|
8988
|
+
if (node.nodeType === 34 /* ParseNodeType.List */) {
|
8999
8989
|
node.entries.forEach((paramExpr, index) => {
|
9000
8990
|
const typeResult = getTypeOfExpressionExpectingType(paramExpr, {
|
9001
8991
|
allowTypeVarsWithoutScopeId: true,
|
@@ -9026,7 +9016,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9026
9016
|
return undefined;
|
9027
9017
|
}
|
9028
9018
|
if ((0, types_1.isParamSpec)(typeResult.type)) {
|
9029
|
-
|
9019
|
+
types_1.FunctionType.addParamSpecVariadics(functionType, typeResult.type);
|
9030
9020
|
return functionType;
|
9031
9021
|
}
|
9032
9022
|
if ((0, types_1.isClassInstance)(typeResult.type) &&
|
@@ -9125,7 +9115,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9125
9115
|
/* typeParamNodes */ undefined, () => typeParameters);
|
9126
9116
|
}
|
9127
9117
|
function getBooleanValue(node) {
|
9128
|
-
if (node.nodeType ===
|
9118
|
+
if (node.nodeType === 14 /* ParseNodeType.Constant */) {
|
9129
9119
|
if (node.constType === 15 /* KeywordType.False */) {
|
9130
9120
|
return false;
|
9131
9121
|
}
|
@@ -9179,9 +9169,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9179
9169
|
let baseClass = getTypeOfArgumentExpectingType(argList[1]).type;
|
9180
9170
|
let isBaseClassAny = false;
|
9181
9171
|
if ((0, types_1.isAnyOrUnknown)(baseClass)) {
|
9182
|
-
|
9183
|
-
baseClass = types_1.ClassType.cloneAsInstantiable(objectType);
|
9184
|
-
}
|
9172
|
+
baseClass = objectClass !== null && objectClass !== void 0 ? objectClass : types_1.UnknownType.create();
|
9185
9173
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeAnyOrUnknown(), (_c = argList[1].node) !== null && _c !== void 0 ? _c : errorNode);
|
9186
9174
|
isBaseClassAny = true;
|
9187
9175
|
}
|
@@ -9264,7 +9252,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9264
9252
|
classType.details.baseClasses.push(specializedType);
|
9265
9253
|
}
|
9266
9254
|
else {
|
9267
|
-
|
9255
|
+
classType.details.baseClasses.push(types_1.UnknownType.create());
|
9268
9256
|
}
|
9269
9257
|
});
|
9270
9258
|
if (!(0, typeUtils_1.computeMroLinearization)(classType)) {
|
@@ -9275,7 +9263,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9275
9263
|
function getTypeOfConstant(node, flags) {
|
9276
9264
|
let type;
|
9277
9265
|
if (node.constType === 26 /* KeywordType.None */) {
|
9278
|
-
|
9266
|
+
if (noneTypeClass) {
|
9267
|
+
type =
|
9268
|
+
(flags & 128 /* EvaluatorFlags.ExpectingInstantiableType */) !== 0
|
9269
|
+
? noneTypeClass
|
9270
|
+
: (0, typeUtils_1.convertToInstance)(noneTypeClass);
|
9271
|
+
}
|
9279
9272
|
}
|
9280
9273
|
else if (node.constType === 33 /* KeywordType.True */ ||
|
9281
9274
|
node.constType === 15 /* KeywordType.False */ ||
|
@@ -9346,15 +9339,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9346
9339
|
return handleSubtype(subtype);
|
9347
9340
|
}
|
9348
9341
|
if ((0, typeUtils_1.isNoneInstance)(subtype)) {
|
9349
|
-
if (
|
9342
|
+
if (objectClass && (0, types_1.isInstantiableClass)(objectClass)) {
|
9350
9343
|
// Use 'object' for 'None'.
|
9351
|
-
return handleSubtype(
|
9344
|
+
return handleSubtype((0, typeUtils_1.convertToInstance)(objectClass));
|
9352
9345
|
}
|
9353
9346
|
}
|
9354
9347
|
if ((0, typeUtils_1.isNoneTypeClass)(subtype)) {
|
9355
|
-
if (
|
9348
|
+
if (typeClass && (0, types_1.isInstantiableClass)(typeClass)) {
|
9356
9349
|
// Use 'type' for 'type[None]'.
|
9357
|
-
return handleSubtype(types_1.ClassType.cloneAsInstance(
|
9350
|
+
return handleSubtype(types_1.ClassType.cloneAsInstance(typeClass));
|
9358
9351
|
}
|
9359
9352
|
}
|
9360
9353
|
magicMethodSupported = false;
|
@@ -9569,9 +9562,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9569
9562
|
128 /* EvaluatorFlags.ExpectingInstantiableType */);
|
9570
9563
|
// Infer the key and value types if possible.
|
9571
9564
|
node.entries.forEach((entryNode, index) => {
|
9572
|
-
var _a, _b, _c
|
9565
|
+
var _a, _b, _c;
|
9573
9566
|
let addUnknown = true;
|
9574
|
-
if (entryNode.nodeType ===
|
9567
|
+
if (entryNode.nodeType === 20 /* ParseNodeType.DictionaryKeyEntry */) {
|
9575
9568
|
const keyTypeResult = getTypeOfExpression(entryNode.keyExpression, keyFlags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, (0, typeUtils_1.makeInferenceContext)(expectedKeyType !== null && expectedKeyType !== void 0 ? expectedKeyType : (forceStrictInference ? types_1.NeverType.createNever() : undefined)));
|
9576
9569
|
if (keyTypeResult.isIncomplete) {
|
9577
9570
|
isIncomplete = true;
|
@@ -9633,11 +9626,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9633
9626
|
}
|
9634
9627
|
addUnknown = false;
|
9635
9628
|
}
|
9636
|
-
else if (entryNode.nodeType ===
|
9629
|
+
else if (entryNode.nodeType === 19 /* ParseNodeType.DictionaryExpandEntry */) {
|
9637
9630
|
let expectedType;
|
9638
9631
|
if (expectedKeyType && expectedValueType) {
|
9639
|
-
if (
|
9640
|
-
expectedType = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(
|
9632
|
+
if (supportsKeysAndGetItemClass && (0, types_1.isInstantiableClass)(supportsKeysAndGetItemClass)) {
|
9633
|
+
expectedType = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(supportsKeysAndGetItemClass, [expectedKeyType, expectedValueType],
|
9641
9634
|
/* isTypeArgumentExplicit */ true));
|
9642
9635
|
}
|
9643
9636
|
}
|
@@ -9661,8 +9654,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9661
9654
|
}
|
9662
9655
|
else if ((0, types_1.isClassInstance)(unexpandedType) && types_1.ClassType.isTypedDictClass(unexpandedType)) {
|
9663
9656
|
// Handle dictionary expansion for a TypedDict.
|
9664
|
-
if (
|
9665
|
-
const strObject = types_1.ClassType.cloneAsInstance(
|
9657
|
+
if (strClass && (0, types_1.isInstantiableClass)(strClass)) {
|
9658
|
+
const strObject = types_1.ClassType.cloneAsInstance(strClass);
|
9666
9659
|
const tdEntries = (0, typedDicts_1.getTypedDictMembersForClass)(evaluatorInterface, unexpandedType,
|
9667
9660
|
/* allowNarrowed */ true);
|
9668
9661
|
tdEntries.knownItems.forEach((entry, name) => {
|
@@ -9678,20 +9671,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9678
9671
|
keyTypes.push({ node: entryNode, type: types_1.ClassType.cloneAsInstance(strObject) });
|
9679
9672
|
valueTypes.push({
|
9680
9673
|
node: entryNode,
|
9681
|
-
type: (
|
9674
|
+
type: (_b = (_a = tdEntries.extraItems) === null || _a === void 0 ? void 0 : _a.valueType) !== null && _b !== void 0 ? _b : getObjectType(),
|
9682
9675
|
});
|
9683
9676
|
}
|
9684
9677
|
addUnknown = false;
|
9685
9678
|
}
|
9686
9679
|
}
|
9687
|
-
else if (
|
9688
|
-
(0,
|
9689
|
-
|
9690
|
-
|
9691
|
-
if (assignType(types_1.ClassType.cloneAsInstance(supportsKeysAndGetItemProtocolType), unexpandedType,
|
9680
|
+
else if (supportsKeysAndGetItemClass && (0, types_1.isInstantiableClass)(supportsKeysAndGetItemClass)) {
|
9681
|
+
const mappingTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(supportsKeysAndGetItemClass));
|
9682
|
+
supportsKeysAndGetItemClass = (0, typeUtils_1.selfSpecializeClass)(supportsKeysAndGetItemClass);
|
9683
|
+
if (assignType(types_1.ClassType.cloneAsInstance(supportsKeysAndGetItemClass), unexpandedType,
|
9692
9684
|
/* diag */ undefined, mappingTypeVarContext,
|
9693
9685
|
/* srcTypeVarContext */ undefined, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */)) {
|
9694
|
-
const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(
|
9686
|
+
const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(supportsKeysAndGetItemClass, mappingTypeVarContext);
|
9695
9687
|
const typeArgs = specializedMapping.typeArguments;
|
9696
9688
|
if (typeArgs && typeArgs.length >= 2) {
|
9697
9689
|
if (forceStrictInference || index < maxEntriesToUseForInference) {
|
@@ -9706,8 +9698,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9706
9698
|
}
|
9707
9699
|
}
|
9708
9700
|
}
|
9709
|
-
else if (entryNode.nodeType ===
|
9710
|
-
const dictEntryTypeResult =
|
9701
|
+
else if (entryNode.nodeType === 11 /* ParseNodeType.Comprehension */) {
|
9702
|
+
const dictEntryTypeResult = getElementTypeFromComprehension(entryNode, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, expectedValueType, expectedKeyType);
|
9711
9703
|
const dictEntryType = dictEntryTypeResult.type;
|
9712
9704
|
if (dictEntryTypeResult.isIncomplete) {
|
9713
9705
|
isIncomplete = true;
|
@@ -9717,7 +9709,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9717
9709
|
}
|
9718
9710
|
// The result should be a tuple.
|
9719
9711
|
if ((0, types_1.isClassInstance)(dictEntryType) && (0, typeUtils_1.isTupleClass)(dictEntryType)) {
|
9720
|
-
const typeArgs = (
|
9712
|
+
const typeArgs = (_c = dictEntryType.tupleTypeArguments) === null || _c === void 0 ? void 0 : _c.map((t) => t.type);
|
9721
9713
|
if (typeArgs && typeArgs.length === 2) {
|
9722
9714
|
if (forceStrictInference || index < maxEntriesToUseForInference) {
|
9723
9715
|
keyTypes.push({ node: entryNode, type: typeArgs[0] });
|
@@ -9739,7 +9731,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9739
9731
|
function getTypeOfListOrSet(node, flags, inferenceContext) {
|
9740
9732
|
var _a;
|
9741
9733
|
if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0 &&
|
9742
|
-
node.nodeType ===
|
9734
|
+
node.nodeType === 34 /* ParseNodeType.List */ &&
|
9743
9735
|
((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== 1 /* ParseNodeType.Argument */) {
|
9744
9736
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
9745
9737
|
diag.addMessage(localize_1.LocAddendum.useListInstead());
|
@@ -9789,7 +9781,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9789
9781
|
// Attempts to determine the type of a list or set statement based on an expected type.
|
9790
9782
|
// Returns undefined if that type cannot be honored.
|
9791
9783
|
function getTypeOfListOrSetWithContext(node, flags, inferenceContext) {
|
9792
|
-
const builtInClassName = node.nodeType ===
|
9784
|
+
const builtInClassName = node.nodeType === 34 /* ParseNodeType.List */ ? 'list' : 'set';
|
9793
9785
|
inferenceContext.expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(inferenceContext.expectedType);
|
9794
9786
|
let isIncomplete = false;
|
9795
9787
|
let typeErrors = false;
|
@@ -9802,8 +9794,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9802
9794
|
const expectedTypeDiagAddendum = new diagnostic_1.DiagnosticAddendum();
|
9803
9795
|
node.entries.forEach((entry) => {
|
9804
9796
|
let entryTypeResult;
|
9805
|
-
if (entry.nodeType ===
|
9806
|
-
entryTypeResult =
|
9797
|
+
if (entry.nodeType === 11 /* ParseNodeType.Comprehension */) {
|
9798
|
+
entryTypeResult = getElementTypeFromComprehension(entry, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, expectedEntryType);
|
9807
9799
|
}
|
9808
9800
|
else {
|
9809
9801
|
entryTypeResult = getTypeOfExpression(entry, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, (0, typeUtils_1.makeInferenceContext)(expectedEntryType));
|
@@ -9861,7 +9853,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9861
9853
|
}
|
9862
9854
|
// Attempts to infer the type of a list or set statement with no "expected type".
|
9863
9855
|
function getTypeOfListOrSetInferred(node, flags, hasExpectedType) {
|
9864
|
-
const builtInClassName = node.nodeType ===
|
9856
|
+
const builtInClassName = node.nodeType === 34 /* ParseNodeType.List */ ? 'list' : 'set';
|
9865
9857
|
const verifyHashable = node.nodeType === 45 /* ParseNodeType.Set */;
|
9866
9858
|
let isEmptyContainer = false;
|
9867
9859
|
let isIncomplete = false;
|
@@ -9869,8 +9861,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9869
9861
|
let entryTypes = [];
|
9870
9862
|
node.entries.forEach((entry, index) => {
|
9871
9863
|
let entryTypeResult;
|
9872
|
-
if (entry.nodeType ===
|
9873
|
-
entryTypeResult =
|
9864
|
+
if (entry.nodeType === 11 /* ParseNodeType.Comprehension */ && !entry.isGenerator) {
|
9865
|
+
entryTypeResult = getElementTypeFromComprehension(entry, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */);
|
9874
9866
|
}
|
9875
9867
|
else {
|
9876
9868
|
entryTypeResult = getTypeOfExpression(entry, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */);
|
@@ -9977,7 +9969,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9977
9969
|
if (enclosingFunction) {
|
9978
9970
|
const functionTypeInfo = getTypeOfFunction(enclosingFunction);
|
9979
9971
|
if (functionTypeInfo) {
|
9980
|
-
const returnType = types_1.FunctionType.
|
9972
|
+
const returnType = types_1.FunctionType.getEffectiveReturnType(functionTypeInfo.functionType);
|
9981
9973
|
if (returnType) {
|
9982
9974
|
expectedYieldType = (0, typeUtils_1.getGeneratorYieldType)(returnType, !!enclosingFunction.isAsync);
|
9983
9975
|
const generatorTypeArgs = (0, typeUtils_1.getGeneratorTypeArgs)(returnType);
|
@@ -10189,14 +10181,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10189
10181
|
}
|
10190
10182
|
return { type: functionType, isIncomplete, typeErrors };
|
10191
10183
|
}
|
10192
|
-
function
|
10184
|
+
function getTypeOfComprehension(node, flags, inferenceContext) {
|
10193
10185
|
let isIncomplete = false;
|
10194
10186
|
let typeErrors = false;
|
10195
10187
|
// If any of the "for" clauses are marked async or any of the "if" clauses
|
10196
10188
|
// or any clause other than the leftmost "for" contain an "await" operator,
|
10197
10189
|
// it is treated as an async generator.
|
10198
10190
|
let isAsync = node.forIfNodes.some((comp, index) => {
|
10199
|
-
if (comp.nodeType ===
|
10191
|
+
if (comp.nodeType === 12 /* ParseNodeType.ComprehensionFor */ && comp.isAsync) {
|
10200
10192
|
return true;
|
10201
10193
|
}
|
10202
10194
|
return index > 0 && ParseTreeUtils.containsAwaitNode(comp);
|
@@ -10207,7 +10199,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10207
10199
|
}
|
10208
10200
|
const builtInIteratorType = getTypingType(node, isAsync ? 'AsyncGenerator' : 'Generator');
|
10209
10201
|
const expectedEntryType = getExpectedEntryTypeForIterable(node, builtInIteratorType, inferenceContext);
|
10210
|
-
const elementTypeResult =
|
10202
|
+
const elementTypeResult = getElementTypeFromComprehension(node, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, expectedEntryType);
|
10211
10203
|
if (elementTypeResult.isIncomplete) {
|
10212
10204
|
isIncomplete = true;
|
10213
10205
|
}
|
@@ -10251,10 +10243,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10251
10243
|
}
|
10252
10244
|
}
|
10253
10245
|
}
|
10254
|
-
function
|
10246
|
+
function evaluateComprehensionForIf(node) {
|
10255
10247
|
var _a;
|
10256
10248
|
let isIncomplete = false;
|
10257
|
-
if (node.nodeType ===
|
10249
|
+
if (node.nodeType === 12 /* ParseNodeType.ComprehensionFor */) {
|
10258
10250
|
const iterableTypeResult = getTypeOfExpression(node.iterableExpression);
|
10259
10251
|
if (iterableTypeResult.isIncomplete) {
|
10260
10252
|
isIncomplete = true;
|
@@ -10262,34 +10254,33 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10262
10254
|
const iterableType = stripLiteralValue(iterableTypeResult.type);
|
10263
10255
|
const itemTypeResult = (_a = getTypeOfIterator({ type: iterableType, isIncomplete: iterableTypeResult.isIncomplete }, !!node.isAsync, node.iterableExpression)) !== null && _a !== void 0 ? _a : { type: types_1.UnknownType.create(), isIncomplete: iterableTypeResult.isIncomplete };
|
10264
10256
|
const targetExpr = node.targetExpression;
|
10265
|
-
assignTypeToExpression(targetExpr, itemTypeResult
|
10257
|
+
assignTypeToExpression(targetExpr, itemTypeResult, node.iterableExpression);
|
10266
10258
|
}
|
10267
10259
|
else {
|
10268
|
-
(0, debug_1.assert)(node.nodeType ===
|
10260
|
+
(0, debug_1.assert)(node.nodeType === 13 /* ParseNodeType.ComprehensionIf */);
|
10269
10261
|
// Evaluate the test expression to validate it and mark symbols
|
10270
|
-
// as referenced.
|
10271
|
-
//
|
10272
|
-
|
10273
|
-
|
10274
|
-
|
10262
|
+
// as referenced. This doesn't affect the type of the evaluated
|
10263
|
+
// comprehension, but it is important for evaluating intermediate
|
10264
|
+
// expressions such as assignment expressions that can affect other
|
10265
|
+
// subexpressions.
|
10266
|
+
getTypeOfExpression(node.testExpression);
|
10275
10267
|
}
|
10276
10268
|
return isIncomplete;
|
10277
10269
|
}
|
10278
|
-
// Returns the type of one entry returned by the
|
10279
|
-
|
10280
|
-
function getElementTypeFromListComprehension(node, flags, expectedValueOrElementType, expectedKeyType) {
|
10270
|
+
// Returns the type of one entry returned by the comprehension.
|
10271
|
+
function getElementTypeFromComprehension(node, flags, expectedValueOrElementType, expectedKeyType) {
|
10281
10272
|
let isIncomplete = false;
|
10282
10273
|
let typeErrors = false;
|
10283
10274
|
// "Execute" the list comprehensions from start to finish.
|
10284
10275
|
for (const forIfNode of node.forIfNodes) {
|
10285
|
-
if (
|
10276
|
+
if (evaluateComprehensionForIf(forIfNode)) {
|
10286
10277
|
isIncomplete = true;
|
10287
10278
|
}
|
10288
10279
|
}
|
10289
10280
|
let type = types_1.UnknownType.create();
|
10290
|
-
if (node.expression.nodeType ===
|
10281
|
+
if (node.expression.nodeType === 20 /* ParseNodeType.DictionaryKeyEntry */) {
|
10291
10282
|
// Create a tuple with the key/value types.
|
10292
|
-
const keyTypeResult = getTypeOfExpression(node.expression.keyExpression, flags
|
10283
|
+
const keyTypeResult = getTypeOfExpression(node.expression.keyExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedKeyType));
|
10293
10284
|
if (keyTypeResult.isIncomplete) {
|
10294
10285
|
isIncomplete = true;
|
10295
10286
|
}
|
@@ -10300,7 +10291,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10300
10291
|
if (!expectedKeyType || !(0, typeUtils_1.containsLiteralType)(expectedKeyType)) {
|
10301
10292
|
keyType = stripLiteralValue(keyType);
|
10302
10293
|
}
|
10303
|
-
const valueTypeResult = getTypeOfExpression(node.expression.valueExpression, flags
|
10294
|
+
const valueTypeResult = getTypeOfExpression(node.expression.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
|
10304
10295
|
if (valueTypeResult.isIncomplete) {
|
10305
10296
|
isIncomplete = true;
|
10306
10297
|
}
|
@@ -10316,12 +10307,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10316
10307
|
{ type: valueType, isUnbounded: false },
|
10317
10308
|
]);
|
10318
10309
|
}
|
10319
|
-
else if (node.expression.nodeType ===
|
10310
|
+
else if (node.expression.nodeType === 19 /* ParseNodeType.DictionaryExpandEntry */) {
|
10320
10311
|
// The parser should have reported an error in this case because it's not allowed.
|
10321
|
-
getTypeOfExpression(node.expression.expandExpression, flags
|
10312
|
+
getTypeOfExpression(node.expression.expandExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
|
10322
10313
|
}
|
10323
10314
|
else if ((0, parseNodes_1.isExpressionNode)(node)) {
|
10324
|
-
const exprTypeResult = getTypeOfExpression(node.expression, flags
|
10315
|
+
const exprTypeResult = getTypeOfExpression(node.expression, flags, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
|
10325
10316
|
if (exprTypeResult.isIncomplete) {
|
10326
10317
|
isIncomplete = true;
|
10327
10318
|
}
|
@@ -10404,6 +10395,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10404
10395
|
// The second argument, if present, should specify the return type.
|
10405
10396
|
function createCallableType(classType, typeArgs, errorNode) {
|
10406
10397
|
const functionType = types_1.FunctionType.createInstantiable(0 /* FunctionTypeFlags.None */);
|
10398
|
+
let paramSpec;
|
10407
10399
|
functionType.specialForm = classType;
|
10408
10400
|
functionType.details.declaredReturnType = types_1.UnknownType.create();
|
10409
10401
|
functionType.details.typeVarScopeId = ParseTreeUtils.getScopeIdForNode(errorNode);
|
@@ -10458,10 +10450,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10458
10450
|
}
|
10459
10451
|
else if ((0, typeUtils_1.isEllipsisType)(typeArgs[0].type)) {
|
10460
10452
|
types_1.FunctionType.addDefaultParameters(functionType);
|
10461
|
-
functionType.details.flags |= 32768 /* FunctionTypeFlags.
|
10453
|
+
functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
|
10462
10454
|
}
|
10463
10455
|
else if ((0, types_1.isParamSpec)(typeArgs[0].type)) {
|
10464
|
-
|
10456
|
+
paramSpec = typeArgs[0].type;
|
10465
10457
|
}
|
10466
10458
|
else {
|
10467
10459
|
if ((0, types_1.isInstantiableClass)(typeArgs[0].type) && types_1.ClassType.isBuiltIn(typeArgs[0].type, 'Concatenate')) {
|
@@ -10471,11 +10463,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10471
10463
|
if (index === concatTypeArgs.length - 1) {
|
10472
10464
|
types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
|
10473
10465
|
if ((0, types_1.isParamSpec)(typeArg)) {
|
10474
|
-
|
10466
|
+
paramSpec = typeArg;
|
10475
10467
|
}
|
10476
10468
|
else if ((0, typeUtils_1.isEllipsisType)(typeArg)) {
|
10477
10469
|
types_1.FunctionType.addDefaultParameters(functionType);
|
10478
|
-
functionType.details.flags |= 32768 /* FunctionTypeFlags.
|
10470
|
+
functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
|
10479
10471
|
}
|
10480
10472
|
}
|
10481
10473
|
else {
|
@@ -10511,7 +10503,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10511
10503
|
}
|
10512
10504
|
else {
|
10513
10505
|
types_1.FunctionType.addDefaultParameters(functionType, /* useUnknown */ true);
|
10514
|
-
functionType.details.flags |= 32768 /* FunctionTypeFlags.
|
10506
|
+
functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
|
10507
|
+
}
|
10508
|
+
if (paramSpec) {
|
10509
|
+
types_1.FunctionType.addParamSpecVariadics(functionType, paramSpec);
|
10515
10510
|
}
|
10516
10511
|
return functionType;
|
10517
10512
|
}
|
@@ -10539,9 +10534,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10539
10534
|
addExpectedClassDiagnostic(typeArg0Type, typeArgs[0].node);
|
10540
10535
|
typeArg0Type = types_1.UnknownType.create();
|
10541
10536
|
}
|
10542
|
-
let optionalType = (0, types_1.combineTypes)([typeArg0Type,
|
10543
|
-
if (
|
10544
|
-
optionalType = types_1.TypeBase.cloneAsSpecialForm(optionalType, types_1.ClassType.cloneAsInstance(
|
10537
|
+
let optionalType = (0, types_1.combineTypes)([typeArg0Type, noneTypeClass !== null && noneTypeClass !== void 0 ? noneTypeClass : types_1.UnknownType.create()]);
|
10538
|
+
if (unionTypeClass && (0, types_1.isInstantiableClass)(unionTypeClass)) {
|
10539
|
+
optionalType = types_1.TypeBase.cloneAsSpecialForm(optionalType, types_1.ClassType.cloneAsInstance(unionTypeClass));
|
10545
10540
|
}
|
10546
10541
|
return optionalType;
|
10547
10542
|
}
|
@@ -10601,7 +10596,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10601
10596
|
type = cloneBuiltinClassWithLiteral(node, classType, 'int', itemExpr.value);
|
10602
10597
|
}
|
10603
10598
|
}
|
10604
|
-
else if (itemExpr.nodeType ===
|
10599
|
+
else if (itemExpr.nodeType === 14 /* ParseNodeType.Constant */) {
|
10605
10600
|
if (itemExpr.constType === 33 /* KeywordType.True */) {
|
10606
10601
|
type = cloneBuiltinClassWithLiteral(node, classType, 'bool', true);
|
10607
10602
|
}
|
@@ -10609,7 +10604,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10609
10604
|
type = cloneBuiltinClassWithLiteral(node, classType, 'bool', false);
|
10610
10605
|
}
|
10611
10606
|
else if (itemExpr.constType === 26 /* KeywordType.None */) {
|
10612
|
-
type =
|
10607
|
+
type = noneTypeClass !== null && noneTypeClass !== void 0 ? noneTypeClass : types_1.UnknownType.create();
|
10613
10608
|
}
|
10614
10609
|
}
|
10615
10610
|
else if (itemExpr.nodeType === 55 /* ParseNodeType.UnaryOperation */) {
|
@@ -10653,8 +10648,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10653
10648
|
literalTypes.push(type);
|
10654
10649
|
}
|
10655
10650
|
let result = (0, types_1.combineTypes)(literalTypes);
|
10656
|
-
if ((0, types_1.isUnion)(result) &&
|
10657
|
-
result = types_1.TypeBase.cloneAsSpecialForm(result, types_1.ClassType.cloneAsInstance(
|
10651
|
+
if ((0, types_1.isUnion)(result) && unionTypeClass && (0, types_1.isInstantiableClass)(unionTypeClass)) {
|
10652
|
+
result = types_1.TypeBase.cloneAsSpecialForm(result, types_1.ClassType.cloneAsInstance(unionTypeClass));
|
10658
10653
|
}
|
10659
10654
|
return result;
|
10660
10655
|
}
|
@@ -10900,8 +10895,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10900
10895
|
return createSpecialType(classType, typeArgs, /* paramLimit */ undefined, /* allowParamSpec */ true);
|
10901
10896
|
}
|
10902
10897
|
function createAnnotatedType(classType, errorNode, typeArgs) {
|
10903
|
-
if (typeArgs
|
10904
|
-
|
10898
|
+
if (typeArgs) {
|
10899
|
+
if (typeArgs.length < 2) {
|
10900
|
+
addError(localize_1.LocMessage.annotatedTypeArgMissing(), errorNode);
|
10901
|
+
}
|
10902
|
+
else {
|
10903
|
+
validateAnnotatedMetadata(errorNode, typeArgs[0].type, typeArgs.slice(1));
|
10904
|
+
}
|
10905
10905
|
}
|
10906
10906
|
if (!typeArgs || typeArgs.length === 0) {
|
10907
10907
|
return { type: types_1.AnyType.create() };
|
@@ -10916,6 +10916,46 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10916
10916
|
isNotRequired: typeArgs[0].isNotRequired,
|
10917
10917
|
};
|
10918
10918
|
}
|
10919
|
+
// Enforces metadata consistency as specified in PEP 746.
|
10920
|
+
function validateAnnotatedMetadata(errorNode, annotatedType, metaArgs) {
|
10921
|
+
var _a;
|
10922
|
+
// This is an experimental feature because PEP 746 hasn't been accepted.
|
10923
|
+
if (!AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.enableExperimentalFeatures) {
|
10924
|
+
return;
|
10925
|
+
}
|
10926
|
+
for (const metaArg of metaArgs) {
|
10927
|
+
if ((0, types_1.isClass)(metaArg.type)) {
|
10928
|
+
const supportsTypeMethod = (_a = getTypeOfBoundMember(
|
10929
|
+
/* errorNode */ undefined, metaArg.type, '__supports_type__')) === null || _a === void 0 ? void 0 : _a.type;
|
10930
|
+
if (!supportsTypeMethod) {
|
10931
|
+
continue;
|
10932
|
+
}
|
10933
|
+
// "Call" the __supports_type__ method to determine if the type is supported.
|
10934
|
+
const callResult = useSpeculativeMode(errorNode, () => validateCallArguments(errorNode, [
|
10935
|
+
{
|
10936
|
+
argumentCategory: 0 /* ArgumentCategory.Simple */,
|
10937
|
+
typeResult: { type: (0, typeUtils_1.convertToInstance)(annotatedType) },
|
10938
|
+
},
|
10939
|
+
], { type: supportsTypeMethod },
|
10940
|
+
/* typeVarContext */ undefined,
|
10941
|
+
/* skipUnknownArgCheck */ true,
|
10942
|
+
/* inferenceContext */ undefined,
|
10943
|
+
/* signatureTracker */ undefined));
|
10944
|
+
if (callResult.isTypeIncomplete || !callResult.returnType) {
|
10945
|
+
continue;
|
10946
|
+
}
|
10947
|
+
// If there are no errors and the return type is potentially truthy,
|
10948
|
+
// we know that the type is supported by this metadata object.
|
10949
|
+
if (!callResult.argumentErrors && canBeTruthy(callResult.returnType)) {
|
10950
|
+
continue;
|
10951
|
+
}
|
10952
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.annotatedMetadataInconsistent().format({
|
10953
|
+
metadataType: printType(metaArg.type),
|
10954
|
+
type: printType((0, typeUtils_1.convertToInstance)(annotatedType)),
|
10955
|
+
}), metaArg.node);
|
10956
|
+
}
|
10957
|
+
}
|
10958
|
+
}
|
10919
10959
|
// Creates one of several "special" types that are defined in typing.pyi
|
10920
10960
|
// but not declared in their entirety. This includes the likes of "Tuple",
|
10921
10961
|
// "Dict", etc.
|
@@ -11048,6 +11088,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11048
11088
|
}
|
11049
11089
|
for (const typeArg of typeArgs) {
|
11050
11090
|
let typeArgType = typeArg.type;
|
11091
|
+
// This is an experimental feature because Unions of unpacked TypeVarTuples are not officially supported.
|
11051
11092
|
if (!validateTypeArg(typeArg, {
|
11052
11093
|
allowVariadicTypeVar: fileInfo.diagnosticRuleSet.enableExperimentalFeatures,
|
11053
11094
|
})) {
|
@@ -11059,6 +11100,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11059
11100
|
}
|
11060
11101
|
// If this is an unpacked tuple, explode out the individual items.
|
11061
11102
|
if ((0, types_1.isUnpackedClass)(typeArg.type) && typeArg.type.tupleTypeArguments) {
|
11103
|
+
// This is an experimental feature because Unions of unpacked TypeVarTuples are not officially supported.
|
11062
11104
|
if (fileInfo.diagnosticRuleSet.enableExperimentalFeatures) {
|
11063
11105
|
typeArg.type.tupleTypeArguments.forEach((tupleTypeArg) => {
|
11064
11106
|
types.push((0, typeUtils_1.convertToInstantiable)(tupleTypeArg.type));
|
@@ -11072,6 +11114,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11072
11114
|
}
|
11073
11115
|
else {
|
11074
11116
|
if ((0, types_1.isTypeVar)(typeArgType) && (0, types_1.isUnpackedVariadicTypeVar)(typeArgType)) {
|
11117
|
+
// This is an experimental feature because Unions of unpacked TypeVarTuples are not officially supported.
|
11075
11118
|
if (fileInfo.diagnosticRuleSet.enableExperimentalFeatures) {
|
11076
11119
|
// If this is an unpacked TypeVar, note that it is in a union so we can
|
11077
11120
|
// differentiate between Unpack[Vs] and Union[Unpack[Vs]].
|
@@ -11093,8 +11136,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11093
11136
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.unionTypeArgCount(), errorNode);
|
11094
11137
|
}
|
11095
11138
|
let unionType = (0, types_1.combineTypes)(types);
|
11096
|
-
if (
|
11097
|
-
unionType = types_1.TypeBase.cloneAsSpecialForm(unionType, types_1.ClassType.cloneAsInstance(
|
11139
|
+
if (unionTypeClass && (0, types_1.isInstantiableClass)(unionTypeClass)) {
|
11140
|
+
unionType = types_1.TypeBase.cloneAsSpecialForm(unionType, types_1.ClassType.cloneAsInstance(unionTypeClass));
|
11098
11141
|
}
|
11099
11142
|
return unionType;
|
11100
11143
|
}
|
@@ -11144,10 +11187,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11144
11187
|
// Determine if there are any generic type parameters associated
|
11145
11188
|
// with this type alias.
|
11146
11189
|
typeParameters = [];
|
11147
|
-
(0, typeUtils_1.
|
11148
|
-
(0, debug_1.assert)(typeParameters !== undefined);
|
11149
|
-
(0, typeUtils_1.addTypeVarsToListIfUnique)(typeParameters, (0, typeUtils_1.getTypeVarArgumentsRecursive)(subtype));
|
11150
|
-
});
|
11190
|
+
(0, typeUtils_1.addTypeVarsToListIfUnique)(typeParameters, (0, typeUtils_1.getTypeVarArgumentsRecursive)(type));
|
11151
11191
|
// Don't include any synthesized type variables.
|
11152
11192
|
typeParameters = typeParameters.filter((typeVar) => !typeVar.details.isSynthesized);
|
11153
11193
|
}
|
@@ -11321,7 +11361,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11321
11361
|
// Handle 'LiteralString' specially because we want it to act as
|
11322
11362
|
// though it derives from 'str'.
|
11323
11363
|
if (assignedName === 'LiteralString') {
|
11324
|
-
specialType.details.baseClasses.push(
|
11364
|
+
specialType.details.baseClasses.push(strClass !== null && strClass !== void 0 ? strClass : types_1.AnyType.create());
|
11325
11365
|
(0, typeUtils_1.computeMroLinearization)(specialType);
|
11326
11366
|
}
|
11327
11367
|
writeTypeCache(node, { type: specialType }, 0 /* EvaluatorFlags.None */);
|
@@ -11492,7 +11532,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11492
11532
|
}
|
11493
11533
|
}
|
11494
11534
|
}
|
11495
|
-
assignTypeToExpression(node.leftExpression, rightHandType, isIncomplete, node.rightExpression,
|
11535
|
+
assignTypeToExpression(node.leftExpression, { type: rightHandType, isIncomplete }, node.rightExpression,
|
11496
11536
|
/* ignoreEmptyContainers */ true,
|
11497
11537
|
/* allowAssignmentToFinalVar */ true, expectedTypeDiagAddendum);
|
11498
11538
|
writeTypeCache(node, { type: rightHandType, isIncomplete }, 0 /* EvaluatorFlags.None */);
|
@@ -11599,7 +11639,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11599
11639
|
return `__type_of_${paramName}`;
|
11600
11640
|
}
|
11601
11641
|
function getTypeOfClass(node) {
|
11602
|
-
|
11642
|
+
initializePrefetchedTypes(node);
|
11603
11643
|
// Is this type already cached?
|
11604
11644
|
const cachedClassType = readTypeCache(node.name, 0 /* EvaluatorFlags.None */);
|
11605
11645
|
if (cachedClassType) {
|
@@ -11861,6 +11901,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11861
11901
|
classType.details.flags |= 1024 /* ClassTypeFlags.CanOmitDictValues */;
|
11862
11902
|
}
|
11863
11903
|
else if (arg.name.value === 'closed' && constArgValue) {
|
11904
|
+
// This is an experimental feature because PEP 728 hasn't been accepted yet.
|
11864
11905
|
if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures) {
|
11865
11906
|
classType.details.flags |=
|
11866
11907
|
256 /* ClassTypeFlags.TypedDictMarkedClosed */ | 512 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
|
@@ -12216,9 +12257,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12216
12257
|
if (!classType.details.requiresVarianceInference) {
|
12217
12258
|
return;
|
12218
12259
|
}
|
12219
|
-
if (!objectType || !(0, types_1.isClassInstance)(objectType)) {
|
12220
|
-
return;
|
12221
|
-
}
|
12222
12260
|
// Presumptively mark the variance inference as complete. This
|
12223
12261
|
// prevents potential recursion.
|
12224
12262
|
classType.details.requiresVarianceInference = false;
|
@@ -12245,8 +12283,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12245
12283
|
if (p.details.isVariadic) {
|
12246
12284
|
return p;
|
12247
12285
|
}
|
12248
|
-
(
|
12249
|
-
return i === paramIndex ? objectType : dummyTypeObject;
|
12286
|
+
return i === paramIndex ? getObjectType() : dummyTypeObject;
|
12250
12287
|
});
|
12251
12288
|
// Replace all type arguments with a dummy type except for the
|
12252
12289
|
// TypeVar of interest, which is replaced with itself.
|
@@ -12303,7 +12340,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12303
12340
|
if (!effectiveMetaclass || (0, types_1.isInstantiableClass)(effectiveMetaclass)) {
|
12304
12341
|
for (const baseClass of classType.details.baseClasses) {
|
12305
12342
|
if ((0, types_1.isInstantiableClass)(baseClass)) {
|
12306
|
-
const baseClassMeta = baseClass.details.effectiveMetaclass ||
|
12343
|
+
const baseClassMeta = baseClass.details.effectiveMetaclass || typeClass;
|
12307
12344
|
if (baseClassMeta && (0, types_1.isInstantiableClass)(baseClassMeta)) {
|
12308
12345
|
// Make sure there is no metaclass conflict.
|
12309
12346
|
if (!effectiveMetaclass) {
|
@@ -12536,7 +12573,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12536
12573
|
});
|
12537
12574
|
}
|
12538
12575
|
function getTypeOfFunction(node) {
|
12539
|
-
|
12576
|
+
initializePrefetchedTypes(node);
|
12540
12577
|
// Is this predecorated function type cached?
|
12541
12578
|
let functionType = readTypeCache(node.name, 0 /* EvaluatorFlags.None */);
|
12542
12579
|
if (functionType) {
|
@@ -12877,7 +12914,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12877
12914
|
paramType1.paramSpecAccess === 'args' &&
|
12878
12915
|
(0, types_1.isParamSpec)(paramType2) &&
|
12879
12916
|
paramType2.paramSpecAccess === 'kwargs') {
|
12880
|
-
functionType.details.flags |= 32768 /* FunctionTypeFlags.
|
12917
|
+
functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
|
12881
12918
|
}
|
12882
12919
|
}
|
12883
12920
|
// If the function contains an *args and a **kwargs parameter and both
|
@@ -12885,7 +12922,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12885
12922
|
// args/kwargs compatibility checks.
|
12886
12923
|
const variadicsWithAnyType = functionType.details.parameters.filter((param) => param.category !== 0 /* ParameterCategory.Simple */ && param.name && (0, types_1.isAnyOrUnknown)(param.type));
|
12887
12924
|
if (variadicsWithAnyType.length >= 2) {
|
12888
|
-
functionType.details.flags |= 32768 /* FunctionTypeFlags.
|
12925
|
+
functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
|
12889
12926
|
}
|
12890
12927
|
// If there was a defined return type, analyze that first so when we
|
12891
12928
|
// walk the contents of the function, return statements can be
|
@@ -12963,7 +13000,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12963
13000
|
// the type checker should assume that the type is optional (i.e. a union
|
12964
13001
|
// of the specified type and 'None'). Skip this step if the type is already
|
12965
13002
|
// optional to avoid losing alias names when combining the types.
|
12966
|
-
if (((_a = param.defaultValue) === null || _a === void 0 ? void 0 : _a.nodeType) ===
|
13003
|
+
if (((_a = param.defaultValue) === null || _a === void 0 ? void 0 : _a.nodeType) === 14 /* ParseNodeType.Constant */ &&
|
12967
13004
|
param.defaultValue.constType === 26 /* KeywordType.None */ &&
|
12968
13005
|
!(0, typeUtils_1.isOptionalType)(type) &&
|
12969
13006
|
!AnalyzerNodeInfo.getFileInfo(param).diagnosticRuleSet.strictParameterNoneValue) {
|
@@ -13356,7 +13393,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13356
13393
|
}
|
13357
13394
|
const iteratorTypeResult = getTypeOfExpression(node.iterableExpression);
|
13358
13395
|
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();
|
13359
|
-
assignTypeToExpression(node.targetExpression, iteratedType,
|
13396
|
+
assignTypeToExpression(node.targetExpression, { type: iteratedType, isIncomplete: iteratorTypeResult.isIncomplete }, node.targetExpression);
|
13360
13397
|
writeTypeCache(node, { type: iteratedType, isIncomplete: !!iteratorTypeResult.isIncomplete }, 0 /* EvaluatorFlags.None */);
|
13361
13398
|
}
|
13362
13399
|
function evaluateTypesForExceptStatement(node) {
|
@@ -13405,7 +13442,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13405
13442
|
targetType = getBuiltInObject(node, 'BaseExceptionGroup', [targetType]);
|
13406
13443
|
}
|
13407
13444
|
if (node.name) {
|
13408
|
-
assignTypeToExpression(node.name,
|
13445
|
+
assignTypeToExpression(node.name, { type: targetType }, node.name);
|
13409
13446
|
}
|
13410
13447
|
writeTypeCache(node, { type: targetType }, 0 /* EvaluatorFlags.None */);
|
13411
13448
|
}
|
@@ -13467,7 +13504,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13467
13504
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeNotUsableWith().format({ type: printType(subtype), method: exitMethodName }), node.expression);
|
13468
13505
|
});
|
13469
13506
|
if (node.target) {
|
13470
|
-
assignTypeToExpression(node.target, scopedType,
|
13507
|
+
assignTypeToExpression(node.target, { type: scopedType, isIncomplete: exprTypeResult.isIncomplete }, node.target);
|
13471
13508
|
}
|
13472
13509
|
writeTypeCache(node, { type: scopedType, isIncomplete: !!exprTypeResult.isIncomplete }, 0 /* EvaluatorFlags.None */);
|
13473
13510
|
}
|
@@ -13500,7 +13537,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13500
13537
|
symbolType = cachedModuleType;
|
13501
13538
|
}
|
13502
13539
|
}
|
13503
|
-
assignTypeToNameNode(symbolNameNode,
|
13540
|
+
assignTypeToNameNode(symbolNameNode, { type: symbolType }, /* ignoreEmptyContainers */ false);
|
13504
13541
|
writeTypeCache(node, { type: symbolType }, 0 /* EvaluatorFlags.None */);
|
13505
13542
|
}
|
13506
13543
|
function evaluateTypesForImportFromAs(node) {
|
@@ -13529,7 +13566,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13529
13566
|
let symbolType = getAliasedSymbolTypeForName(node, aliasNode.value);
|
13530
13567
|
if (!symbolType) {
|
13531
13568
|
const parentNode = node.parent;
|
13532
|
-
(0, debug_1.assert)(parentNode && parentNode.nodeType ===
|
13569
|
+
(0, debug_1.assert)(parentNode && parentNode.nodeType === 25 /* ParseNodeType.ImportFrom */);
|
13533
13570
|
(0, debug_1.assert)(!parentNode.isWildcardImport);
|
13534
13571
|
const importInfo = AnalyzerNodeInfo.getImportInfo(parentNode.module);
|
13535
13572
|
if (importInfo && importInfo.isImportFound && !importInfo.isNativeLib) {
|
@@ -13566,7 +13603,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13566
13603
|
symbolType = types_1.UnknownType.create();
|
13567
13604
|
}
|
13568
13605
|
}
|
13569
|
-
assignTypeToNameNode(aliasNode,
|
13606
|
+
assignTypeToNameNode(aliasNode, { type: symbolType }, /* ignoreEmptyContainers */ false);
|
13570
13607
|
writeTypeCache(node, { type: symbolType }, 0 /* EvaluatorFlags.None */);
|
13571
13608
|
}
|
13572
13609
|
function evaluateTypesForMatchStatement(node) {
|
@@ -13664,9 +13701,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13664
13701
|
symbolType = cachedModuleType;
|
13665
13702
|
}
|
13666
13703
|
}
|
13667
|
-
assignTypeToNameNode(symbolNameNode, symbolType,
|
13668
|
-
/* isIncomplete */ false,
|
13669
|
-
/* ignoreEmptyContainers */ false);
|
13704
|
+
assignTypeToNameNode(symbolNameNode, { type: symbolType }, /* ignoreEmptyContainers */ false);
|
13670
13705
|
writeTypeCache(node, { type: symbolType }, 0 /* EvaluatorFlags.None */);
|
13671
13706
|
}
|
13672
13707
|
}
|
@@ -13721,7 +13756,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13721
13756
|
if (!resolvedAliasInfo.declaration) {
|
13722
13757
|
return evaluatorOptions.evaluateUnknownImportsAsAny ? types_1.AnyType.create() : types_1.UnknownType.create();
|
13723
13758
|
}
|
13724
|
-
if (node.nodeType ===
|
13759
|
+
if (node.nodeType === 26 /* ParseNodeType.ImportFromAs */) {
|
13725
13760
|
if (resolvedAliasInfo.isPrivate) {
|
13726
13761
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportPrivateUsage, localize_1.LocMessage.privateUsedOutsideOfModule().format({
|
13727
13762
|
name: node.name.value,
|
@@ -13751,7 +13786,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13751
13786
|
// is technically not part of an expression. We'll handle these here so
|
13752
13787
|
// callers don't need to include special-case logic.
|
13753
13788
|
if (node.nodeType === 38 /* ParseNodeType.Name */ && node.parent) {
|
13754
|
-
if (node.parent.nodeType ===
|
13789
|
+
if (node.parent.nodeType === 31 /* ParseNodeType.Function */ && node.parent.name === node) {
|
13755
13790
|
getTypeOfFunction(node.parent);
|
13756
13791
|
return;
|
13757
13792
|
}
|
@@ -13759,11 +13794,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13759
13794
|
getTypeOfClass(node.parent);
|
13760
13795
|
return;
|
13761
13796
|
}
|
13762
|
-
if (node.parent.nodeType ===
|
13797
|
+
if (node.parent.nodeType === 26 /* ParseNodeType.ImportFromAs */) {
|
13763
13798
|
evaluateTypesForImportFromAs(node.parent);
|
13764
13799
|
return;
|
13765
13800
|
}
|
13766
|
-
if (node.parent.nodeType ===
|
13801
|
+
if (node.parent.nodeType === 24 /* ParseNodeType.ImportAs */) {
|
13767
13802
|
evaluateTypesForImportAs(node.parent);
|
13768
13803
|
return;
|
13769
13804
|
}
|
@@ -13771,7 +13806,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13771
13806
|
getTypeOfTypeAlias(node.parent);
|
13772
13807
|
return;
|
13773
13808
|
}
|
13774
|
-
if (node.parent.nodeType ===
|
13809
|
+
if (node.parent.nodeType === 32 /* ParseNodeType.Global */ || node.parent.nodeType === 39 /* ParseNodeType.Nonlocal */) {
|
13775
13810
|
// For global and nonlocal statements, allow forward references so
|
13776
13811
|
// we don't use code flow during symbol lookups.
|
13777
13812
|
getTypeOfExpression(node, 4 /* EvaluatorFlags.AllowForwardReferences */);
|
@@ -13807,7 +13842,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13807
13842
|
evaluateTypesForTypeAnnotationNode(annotationParent);
|
13808
13843
|
return;
|
13809
13844
|
}
|
13810
|
-
if (annotationParent.nodeType ===
|
13845
|
+
if (annotationParent.nodeType === 31 /* ParseNodeType.Function */ &&
|
13811
13846
|
annotationNode === annotationParent.returnTypeAnnotation) {
|
13812
13847
|
getTypeOfAnnotation(annotationNode, {
|
13813
13848
|
associateTypeVarsWithScope: true,
|
@@ -13843,7 +13878,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13843
13878
|
if (argumentNode && argumentNode !== nodeToEvaluate) {
|
13844
13879
|
(0, debug_1.assert)(argumentNode.parent !== undefined);
|
13845
13880
|
if (argumentNode.parent.nodeType === 9 /* ParseNodeType.Call */ ||
|
13846
|
-
argumentNode.parent.nodeType ===
|
13881
|
+
argumentNode.parent.nodeType === 27 /* ParseNodeType.Index */) {
|
13847
13882
|
nodeToEvaluate = argumentNode.parent;
|
13848
13883
|
continue;
|
13849
13884
|
}
|
@@ -13875,7 +13910,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13875
13910
|
continue;
|
13876
13911
|
}
|
13877
13912
|
// Handle the special case where the LHS is a call to a lambda.
|
13878
|
-
if (parent.nodeType === 9 /* ParseNodeType.Call */ && nodeToEvaluate.nodeType ===
|
13913
|
+
if (parent.nodeType === 9 /* ParseNodeType.Call */ && nodeToEvaluate.nodeType === 33 /* ParseNodeType.Lambda */) {
|
13879
13914
|
nodeToEvaluate = parent;
|
13880
13915
|
continue;
|
13881
13916
|
}
|
@@ -13883,7 +13918,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13883
13918
|
break;
|
13884
13919
|
}
|
13885
13920
|
}
|
13886
|
-
else if (parent.nodeType ===
|
13921
|
+
else if (parent.nodeType === 27 /* ParseNodeType.Index */) {
|
13887
13922
|
// The base expression of an index expression is not contextual.
|
13888
13923
|
if (nodeToEvaluate === parent.baseExpression) {
|
13889
13924
|
flags = 2 /* EvaluatorFlags.IndexBaseDefaults */;
|
@@ -13903,17 +13938,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13903
13938
|
// stop. However, there are a few special "pass through"
|
13904
13939
|
// node types that we can skip over to get to a known
|
13905
13940
|
// expression node.
|
13906
|
-
if (parent.nodeType ===
|
13907
|
-
parent.nodeType ===
|
13908
|
-
parent.nodeType ===
|
13909
|
-
parent.nodeType ===
|
13941
|
+
if (parent.nodeType === 20 /* ParseNodeType.DictionaryKeyEntry */ ||
|
13942
|
+
parent.nodeType === 19 /* ParseNodeType.DictionaryExpandEntry */ ||
|
13943
|
+
parent.nodeType === 12 /* ParseNodeType.ComprehensionFor */ ||
|
13944
|
+
parent.nodeType === 13 /* ParseNodeType.ComprehensionIf */) {
|
13910
13945
|
(0, debug_1.assert)(parent.parent !== undefined && (0, parseNodes_1.isExpressionNode)(parent.parent));
|
13911
13946
|
parent = parent.parent;
|
13912
13947
|
}
|
13913
13948
|
else if (parent.nodeType === 41 /* ParseNodeType.Parameter */) {
|
13914
13949
|
(0, debug_1.assert)(parent.parent !== undefined);
|
13915
13950
|
// Parameters are contextual for lambdas.
|
13916
|
-
if (parent.parent.nodeType ===
|
13951
|
+
if (parent.parent.nodeType === 33 /* ParseNodeType.Lambda */) {
|
13917
13952
|
parent = parent.parent;
|
13918
13953
|
}
|
13919
13954
|
else {
|
@@ -13938,7 +13973,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13938
13973
|
const parent = nodeToEvaluate.parent;
|
13939
13974
|
(0, debug_1.assert)(parent !== undefined);
|
13940
13975
|
switch (parent.nodeType) {
|
13941
|
-
case
|
13976
|
+
case 17 /* ParseNodeType.Del */: {
|
13942
13977
|
verifyDeleteExpression(nodeToEvaluate);
|
13943
13978
|
return;
|
13944
13979
|
}
|
@@ -13957,11 +13992,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13957
13992
|
getTypeOfTypeAlias(parent);
|
13958
13993
|
return;
|
13959
13994
|
}
|
13960
|
-
case
|
13995
|
+
case 16 /* ParseNodeType.Decorator */: {
|
13961
13996
|
if (((_d = parent.parent) === null || _d === void 0 ? void 0 : _d.nodeType) === 10 /* ParseNodeType.Class */) {
|
13962
13997
|
getTypeOfClass(parent.parent);
|
13963
13998
|
}
|
13964
|
-
else if (((_e = parent.parent) === null || _e === void 0 ? void 0 : _e.nodeType) ===
|
13999
|
+
else if (((_e = parent.parent) === null || _e === void 0 ? void 0 : _e.nodeType) === 31 /* ParseNodeType.Function */) {
|
13965
14000
|
getTypeOfFunction(parent.parent);
|
13966
14001
|
}
|
13967
14002
|
return;
|
@@ -14023,11 +14058,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14023
14058
|
// be inferred, whereas the latter sometimes have type annotations
|
14024
14059
|
// but cannot be inferred.
|
14025
14060
|
const parent = node.parent;
|
14026
|
-
if (parent.nodeType ===
|
14061
|
+
if (parent.nodeType === 33 /* ParseNodeType.Lambda */) {
|
14027
14062
|
evaluateTypesForExpressionInContext(parent);
|
14028
14063
|
return;
|
14029
14064
|
}
|
14030
|
-
(0, debug_1.assert)(parent.nodeType ===
|
14065
|
+
(0, debug_1.assert)(parent.nodeType === 31 /* ParseNodeType.Function */);
|
14031
14066
|
const functionNode = parent;
|
14032
14067
|
const paramIndex = functionNode.parameters.findIndex((param) => param === node);
|
14033
14068
|
const typeAnnotation = ParseTreeUtils.getTypeAnnotationForParameter(functionNode, paramIndex);
|
@@ -14063,7 +14098,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14063
14098
|
// be evaluated to provide sufficient context for the type. Evaluated types
|
14064
14099
|
// are written back to the type cache for later retrieval.
|
14065
14100
|
function evaluateTypesForStatement(node) {
|
14066
|
-
|
14101
|
+
initializePrefetchedTypes(node);
|
14067
14102
|
let curNode = node;
|
14068
14103
|
while (curNode) {
|
14069
14104
|
switch (curNode.nodeType) {
|
@@ -14086,7 +14121,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14086
14121
|
return;
|
14087
14122
|
}
|
14088
14123
|
case 4 /* ParseNodeType.AssignmentExpression */: {
|
14089
|
-
|
14124
|
+
evaluateTypesForExpressionInContext(curNode);
|
14090
14125
|
return;
|
14091
14126
|
}
|
14092
14127
|
case 5 /* ParseNodeType.AugmentedAssignment */: {
|
@@ -14101,19 +14136,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14101
14136
|
evaluateTypeOfParameter(curNode);
|
14102
14137
|
return;
|
14103
14138
|
}
|
14104
|
-
case
|
14139
|
+
case 33 /* ParseNodeType.Lambda */: {
|
14105
14140
|
evaluateTypesForExpressionInContext(curNode);
|
14106
14141
|
return;
|
14107
14142
|
}
|
14108
|
-
case
|
14143
|
+
case 31 /* ParseNodeType.Function */: {
|
14109
14144
|
getTypeOfFunction(curNode);
|
14110
14145
|
return;
|
14111
14146
|
}
|
14112
|
-
case
|
14147
|
+
case 29 /* ParseNodeType.For */: {
|
14113
14148
|
evaluateTypesForForStatement(curNode);
|
14114
14149
|
return;
|
14115
14150
|
}
|
14116
|
-
case
|
14151
|
+
case 28 /* ParseNodeType.Except */: {
|
14117
14152
|
evaluateTypesForExceptStatement(curNode);
|
14118
14153
|
return;
|
14119
14154
|
}
|
@@ -14121,17 +14156,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14121
14156
|
evaluateTypesForWithStatement(curNode);
|
14122
14157
|
return;
|
14123
14158
|
}
|
14124
|
-
case
|
14125
|
-
const
|
14126
|
-
(0, debug_1.assert)(
|
14127
|
-
if (curNode ===
|
14128
|
-
evaluateTypesForExpressionInContext(
|
14159
|
+
case 12 /* ParseNodeType.ComprehensionFor */: {
|
14160
|
+
const comprehension = curNode.parent;
|
14161
|
+
(0, debug_1.assert)(comprehension.nodeType === 11 /* ParseNodeType.Comprehension */);
|
14162
|
+
if (curNode === comprehension.expression) {
|
14163
|
+
evaluateTypesForExpressionInContext(comprehension);
|
14129
14164
|
}
|
14130
14165
|
else {
|
14131
14166
|
// Evaluate the individual iterations starting with the first
|
14132
14167
|
// up to the curNode.
|
14133
|
-
for (const forIfNode of
|
14134
|
-
|
14168
|
+
for (const forIfNode of comprehension.forIfNodes) {
|
14169
|
+
evaluateComprehensionForIf(forIfNode);
|
14135
14170
|
if (forIfNode === curNode) {
|
14136
14171
|
break;
|
14137
14172
|
}
|
@@ -14139,15 +14174,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14139
14174
|
}
|
14140
14175
|
return;
|
14141
14176
|
}
|
14142
|
-
case
|
14177
|
+
case 24 /* ParseNodeType.ImportAs */: {
|
14143
14178
|
evaluateTypesForImportAs(curNode);
|
14144
14179
|
return;
|
14145
14180
|
}
|
14146
|
-
case
|
14181
|
+
case 26 /* ParseNodeType.ImportFromAs */: {
|
14147
14182
|
evaluateTypesForImportFromAs(curNode);
|
14148
14183
|
return;
|
14149
14184
|
}
|
14150
|
-
case
|
14185
|
+
case 25 /* ParseNodeType.ImportFrom */: {
|
14151
14186
|
evaluateTypesForImportFrom(curNode);
|
14152
14187
|
return;
|
14153
14188
|
}
|
@@ -14371,8 +14406,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14371
14406
|
return { type: types_1.UnknownType.create() };
|
14372
14407
|
}
|
14373
14408
|
}
|
14374
|
-
if (
|
14375
|
-
let typeType = createSpecialType(
|
14409
|
+
if (typeClass && (0, types_1.isInstantiableClass)(typeClass)) {
|
14410
|
+
let typeType = createSpecialType(typeClass, typeArgs, 1,
|
14376
14411
|
/* allowParamSpec */ undefined,
|
14377
14412
|
/* isSpecialForm */ false);
|
14378
14413
|
if ((0, types_1.isInstantiableClass)(typeType)) {
|
@@ -14503,7 +14538,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14503
14538
|
const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */);
|
14504
14539
|
if ((0, typeUtils_1.isEllipsisType)(typeArg.type)) {
|
14505
14540
|
types_1.FunctionType.addDefaultParameters(functionType);
|
14506
|
-
functionType.details.flags |= 32768 /* FunctionTypeFlags.
|
14541
|
+
functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
|
14507
14542
|
typeArgTypes.push(functionType);
|
14508
14543
|
typeVarContext.setTypeVarType(typeParam, (0, typeUtils_1.convertTypeToParamSpecValue)(functionType));
|
14509
14544
|
return;
|
@@ -14531,12 +14566,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14531
14566
|
concatTypeArgs.forEach((typeArg, index) => {
|
14532
14567
|
if (index === concatTypeArgs.length - 1) {
|
14533
14568
|
if ((0, types_1.isParamSpec)(typeArg)) {
|
14534
|
-
|
14569
|
+
types_1.FunctionType.addParamSpecVariadics(functionType, typeArg);
|
14535
14570
|
}
|
14536
14571
|
else if ((0, typeUtils_1.isEllipsisType)(typeArg)) {
|
14537
14572
|
types_1.FunctionType.addDefaultParameters(functionType);
|
14538
|
-
functionType.details.flags |=
|
14539
|
-
32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */;
|
14573
|
+
functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
|
14540
14574
|
}
|
14541
14575
|
}
|
14542
14576
|
else {
|
@@ -14710,7 +14744,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14710
14744
|
// Functions and list comprehensions don't allow access to implicitly
|
14711
14745
|
// aliased symbols in outer scopes if they haven't yet been assigned
|
14712
14746
|
// within the local scope.
|
14713
|
-
let scopeTypeHonorsCodeFlow = scopeType !== 2 /* ScopeType.Function */ && scopeType !== 1 /* ScopeType.
|
14747
|
+
let scopeTypeHonorsCodeFlow = scopeType !== 2 /* ScopeType.Function */ && scopeType !== 1 /* ScopeType.Comprehension */;
|
14714
14748
|
// TypeParameter scopes don't honor code flow, but if the symbol is resolved
|
14715
14749
|
// using the proxy scope for the TypeParameter scope, we should use code flow.
|
14716
14750
|
if (scopeType === 0 /* ScopeType.TypeParameter */ && symbolWithScope && symbolWithScope.scope === scope) {
|
@@ -14914,7 +14948,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14914
14948
|
}
|
14915
14949
|
function getAliasFromImport(node) {
|
14916
14950
|
if (node.parent &&
|
14917
|
-
node.parent.nodeType ===
|
14951
|
+
node.parent.nodeType === 26 /* ParseNodeType.ImportFromAs */ &&
|
14918
14952
|
node.parent.alias &&
|
14919
14953
|
node === node.parent.name) {
|
14920
14954
|
return node.parent.alias;
|
@@ -15145,7 +15179,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15145
15179
|
// has a function-level annotation comment that provides
|
15146
15180
|
// this parameter's annotation type.
|
15147
15181
|
if (!typeAnnotationNode) {
|
15148
|
-
if (((_a = declaration.node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) ===
|
15182
|
+
if (((_a = declaration.node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 31 /* ParseNodeType.Function */) {
|
15149
15183
|
const functionNode = declaration.node.parent;
|
15150
15184
|
if (functionNode.functionAnnotationComment &&
|
15151
15185
|
!functionNode.functionAnnotationComment.isParamListEllipsis) {
|
@@ -15313,7 +15347,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15313
15347
|
// Set the variance to "auto" for class-scoped TypeVars.
|
15314
15348
|
typeVar.details.declaredVariance = 0 /* Variance.Auto */;
|
15315
15349
|
}
|
15316
|
-
else if (scopeNode.nodeType ===
|
15350
|
+
else if (scopeNode.nodeType === 31 /* ParseNodeType.Function */) {
|
15317
15351
|
scopeType = 1 /* TypeVarScopeType.Function */;
|
15318
15352
|
}
|
15319
15353
|
else {
|
@@ -15899,7 +15933,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15899
15933
|
// the return type. If a list of args is provided, the inference logic may take
|
15900
15934
|
// into account argument types to infer the return type.
|
15901
15935
|
function getFunctionEffectiveReturnType(type, callSiteInfo, inferTypeIfNeeded = true) {
|
15902
|
-
const specializedReturnType = types_1.FunctionType.
|
15936
|
+
const specializedReturnType = types_1.FunctionType.getEffectiveReturnType(type, /* includeInferred */ false);
|
15903
15937
|
if (specializedReturnType && !(0, types_1.isUnknown)(specializedReturnType)) {
|
15904
15938
|
const liveTypeVarScopes = (callSiteInfo === null || callSiteInfo === void 0 ? void 0 : callSiteInfo.errorNode)
|
15905
15939
|
? ParseTreeUtils.getTypeVarScopesForNode(callSiteInfo === null || callSiteInfo === void 0 ? void 0 : callSiteInfo.errorNode)
|
@@ -16158,7 +16192,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16158
16192
|
function getTypeOfMember(member) {
|
16159
16193
|
if ((0, types_1.isInstantiableClass)(member.classType)) {
|
16160
16194
|
return (0, typeUtils_1.partiallySpecializeType)(getEffectiveTypeOfSymbol(member.symbol), member.classType,
|
16161
|
-
/* selfClass */ undefined,
|
16195
|
+
/* selfClass */ undefined, typeClass !== null && typeClass !== void 0 ? typeClass : types_1.UnknownType.create());
|
16162
16196
|
}
|
16163
16197
|
return types_1.UnknownType.create();
|
16164
16198
|
}
|
@@ -16170,20 +16204,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16170
16204
|
// and cache the return type if necessary. This needs to be done
|
16171
16205
|
// prior to specializing.
|
16172
16206
|
inferReturnTypeIfNecessary(typeResult.type);
|
16173
|
-
|
16174
|
-
|
16175
|
-
|
16176
|
-
(0,
|
16177
|
-
|
16178
|
-
|
16179
|
-
|
16180
|
-
|
16181
|
-
|
16182
|
-
|
16183
|
-
|
16184
|
-
}
|
16185
|
-
});
|
16186
|
-
if (isGenericNonCallable && errorNode) {
|
16207
|
+
// Check for ambiguous accesses to attributes with generic types?
|
16208
|
+
if (errorNode &&
|
16209
|
+
selfClass &&
|
16210
|
+
(0, types_1.isClass)(selfClass) &&
|
16211
|
+
member.isInstanceMember &&
|
16212
|
+
(0, types_1.isClass)(member.unspecializedClassType) &&
|
16213
|
+
(flags & 1024 /* MemberAccessFlags.DisallowGenericInstanceVariableAccess */) !== 0 &&
|
16214
|
+
(0, typeUtils_1.requiresSpecialization)(typeResult.type, { ignoreSelf: true, ignoreImplicitTypeArgs: true })) {
|
16215
|
+
const specializedType = (0, typeUtils_1.partiallySpecializeType)(typeResult.type, member.unspecializedClassType, (0, typeUtils_1.selfSpecializeClass)(selfClass, /* overrideTypeArgs */ true));
|
16216
|
+
if ((0, types_1.findSubtype)(specializedType, (subtype) => !(0, types_1.isFunction)(subtype) &&
|
16217
|
+
!(0, types_1.isOverloadedFunction)(subtype) &&
|
16218
|
+
(0, typeUtils_1.requiresSpecialization)(subtype, { ignoreSelf: true, ignoreImplicitTypeArgs: true }))) {
|
16187
16219
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.genericInstanceVariableAccess(), errorNode);
|
16188
16220
|
}
|
16189
16221
|
}
|
@@ -16235,22 +16267,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16235
16267
|
if (types_1.ClassType.isBuiltIn(destType, 'Mapping')) {
|
16236
16268
|
const mappingValueType = (0, typedDicts_1.getTypedDictMappingEquivalent)(evaluatorInterface, srcType);
|
16237
16269
|
if (mappingValueType &&
|
16238
|
-
|
16239
|
-
(0, types_1.isInstantiableClass)(
|
16240
|
-
|
16241
|
-
(0, types_1.isInstantiableClass)(
|
16242
|
-
srcType = types_1.ClassType.cloneForSpecialization(
|
16270
|
+
mappingClass &&
|
16271
|
+
(0, types_1.isInstantiableClass)(mappingClass) &&
|
16272
|
+
strClass &&
|
16273
|
+
(0, types_1.isInstantiableClass)(strClass)) {
|
16274
|
+
srcType = types_1.ClassType.cloneForSpecialization(mappingClass, [types_1.ClassType.cloneAsInstance(strClass), mappingValueType],
|
16243
16275
|
/* isTypeArgumentExplicit */ true);
|
16244
16276
|
}
|
16245
16277
|
}
|
16246
16278
|
else if (types_1.ClassType.isBuiltIn(destType, ['dict', 'MutableMapping'])) {
|
16247
16279
|
const dictValueType = (0, typedDicts_1.getTypedDictDictEquivalent)(evaluatorInterface, srcType, recursionCount);
|
16248
16280
|
if (dictValueType &&
|
16249
|
-
|
16250
|
-
(0, types_1.isInstantiableClass)(
|
16251
|
-
|
16252
|
-
(0, types_1.isInstantiableClass)(
|
16253
|
-
srcType = types_1.ClassType.cloneForSpecialization(
|
16281
|
+
dictClass &&
|
16282
|
+
(0, types_1.isInstantiableClass)(dictClass) &&
|
16283
|
+
strClass &&
|
16284
|
+
(0, types_1.isInstantiableClass)(strClass)) {
|
16285
|
+
srcType = types_1.ClassType.cloneForSpecialization(dictClass, [types_1.ClassType.cloneAsInstance(strClass), dictValueType],
|
16254
16286
|
/* isTypeArgumentExplicit */ true);
|
16255
16287
|
}
|
16256
16288
|
}
|
@@ -16477,7 +16509,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16477
16509
|
// If the only removed arg from the dest type args is itself a variadic,
|
16478
16510
|
// don't bother adjusting it.
|
16479
16511
|
const skipAdjustment = destArgsToCapture === 1 && (0, types_1.isVariadicTypeVar)(destTypeArgs[srcVariadicIndex].type);
|
16480
|
-
if (!skipAdjustment &&
|
16512
|
+
if (!skipAdjustment && tupleClass && (0, types_1.isInstantiableClass)(tupleClass)) {
|
16481
16513
|
const removedArgs = destTypeArgs.splice(srcVariadicIndex, destArgsToCapture);
|
16482
16514
|
// Package up the remaining type arguments into a tuple object.
|
16483
16515
|
const variadicTuple = makeTupleObject(removedArgs.map((typeArg) => {
|
@@ -16501,7 +16533,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16501
16533
|
// If the dest contains a variadic element, determine which source
|
16502
16534
|
// args map to this element and package them up into an unpacked tuple.
|
16503
16535
|
if ((0, types_1.isVariadicTypeVar)(destTypeArgs[destUnboundedOrVariadicIndex].type)) {
|
16504
|
-
if (
|
16536
|
+
if (tupleClass && (0, types_1.isInstantiableClass)(tupleClass)) {
|
16505
16537
|
const removedArgs = srcTypeArgs.splice(destUnboundedOrVariadicIndex, srcArgsToCapture);
|
16506
16538
|
let variadicTuple;
|
16507
16539
|
// If we're left with a single unpacked variadic type var, there's no
|
@@ -16966,20 +16998,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16966
16998
|
// rather than dest. If the type variable is not in the scope of the
|
16967
16999
|
// provided TypeVarContext, simply verify that the concrete types are
|
16968
17000
|
// compatible.
|
16969
|
-
if (
|
17001
|
+
if ((flags & 1024 /* AssignTypeFlags.IgnoreTypeVarScope */) === 0 &&
|
17002
|
+
(!srcTypeVarContext || !srcTypeVarContext.hasSolveForScope((0, typeUtils_1.getTypeVarScopeId)(srcType)))) {
|
16970
17003
|
return assignType(makeTopLevelTypeVarsConcrete(destType), makeTopLevelTypeVarsConcrete(srcType), diag,
|
16971
17004
|
/* destTypeVarContext */ undefined,
|
16972
17005
|
/* srcTypeVarContext */ undefined, originalFlags, recursionCount);
|
16973
17006
|
}
|
16974
17007
|
else {
|
16975
|
-
if ((0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, srcType, destType, diag, srcTypeVarContext, originalFlags, recursionCount)) {
|
17008
|
+
if ((0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, srcType, destType, diag, srcTypeVarContext !== null && srcTypeVarContext !== void 0 ? srcTypeVarContext : new typeVarContext_1.TypeVarContext(), originalFlags, recursionCount)) {
|
16976
17009
|
return true;
|
16977
17010
|
}
|
16978
17011
|
// If the dest type is a union, only one of the subtypes needs to match.
|
16979
17012
|
let isAssignable = false;
|
16980
17013
|
if ((0, types_1.isUnion)(destType)) {
|
16981
17014
|
(0, typeUtils_1.doForEachSubtype)(destType, (destSubtype) => {
|
16982
|
-
if ((0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, srcType, destSubtype, diag, srcTypeVarContext, originalFlags, recursionCount)) {
|
17015
|
+
if ((0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, srcType, destSubtype, diag, srcTypeVarContext !== null && srcTypeVarContext !== void 0 ? srcTypeVarContext : new typeVarContext_1.TypeVarContext(), originalFlags, recursionCount)) {
|
16983
17016
|
isAssignable = true;
|
16984
17017
|
}
|
16985
17018
|
});
|
@@ -16996,7 +17029,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16996
17029
|
// it's Any.
|
16997
17030
|
if ((0, types_1.isParamSpec)(srcType) &&
|
16998
17031
|
(0, types_1.isFunction)(destType) &&
|
16999
|
-
types_1.FunctionType.
|
17032
|
+
types_1.FunctionType.isGradualCallableForm(destType) &&
|
17000
17033
|
destType.details.parameters.length <= 2) {
|
17001
17034
|
return true;
|
17002
17035
|
}
|
@@ -17209,10 +17242,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17209
17242
|
}
|
17210
17243
|
}
|
17211
17244
|
else if (types_1.ClassType.isBuiltIn(concreteSrcType, 'LiteralString') &&
|
17212
|
-
|
17213
|
-
(0, types_1.isInstantiableClass)(
|
17245
|
+
strClass &&
|
17246
|
+
(0, types_1.isInstantiableClass)(strClass) &&
|
17214
17247
|
(flags & 1 /* AssignTypeFlags.EnforceInvariance */) === 0) {
|
17215
|
-
concreteSrcType = types_1.ClassType.cloneAsInstance(
|
17248
|
+
concreteSrcType = types_1.ClassType.cloneAsInstance(strClass);
|
17216
17249
|
}
|
17217
17250
|
if (!assignClass(types_1.ClassType.cloneAsInstantiable(destType), types_1.ClassType.cloneAsInstantiable(concreteSrcType), diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount,
|
17218
17251
|
/* reportErrorsUsingObjType */ true)) {
|
@@ -17227,8 +17260,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17227
17260
|
return assignType(destCallbackType, concreteSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
|
17228
17261
|
}
|
17229
17262
|
// All functions are considered instances of "builtins.function".
|
17230
|
-
if (
|
17231
|
-
return assignType(destType,
|
17263
|
+
if (functionClass) {
|
17264
|
+
return assignType(destType, (0, typeUtils_1.convertToInstance)(functionClass), diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
|
17232
17265
|
}
|
17233
17266
|
}
|
17234
17267
|
else if ((0, types_1.isModule)(concreteSrcType)) {
|
@@ -17278,7 +17311,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17278
17311
|
/* selfType */ undefined,
|
17279
17312
|
/* diag */ undefined, recursionCount);
|
17280
17313
|
if (boundMethod) {
|
17281
|
-
concreteSrcType =
|
17314
|
+
concreteSrcType = boundMethod;
|
17282
17315
|
}
|
17283
17316
|
}
|
17284
17317
|
// If it's a class, use the constructor for type compatibility checking.
|
@@ -17382,8 +17415,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17382
17415
|
}
|
17383
17416
|
// Are we trying to assign None to a protocol?
|
17384
17417
|
if ((0, typeUtils_1.isNoneInstance)(srcType) && (0, types_1.isClassInstance)(destType) && types_1.ClassType.isProtocolClass(destType)) {
|
17385
|
-
if (
|
17386
|
-
return (0, protocols_1.assignClassToProtocol)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destType), types_1.ClassType.cloneAsInstance(
|
17418
|
+
if (noneTypeClass && (0, types_1.isInstantiableClass)(noneTypeClass)) {
|
17419
|
+
return (0, protocols_1.assignClassToProtocol)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destType), types_1.ClassType.cloneAsInstance(noneTypeClass), diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
|
17387
17420
|
}
|
17388
17421
|
}
|
17389
17422
|
if ((0, typeUtils_1.isNoneInstance)(destType)) {
|
@@ -17810,8 +17843,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17810
17843
|
for (const field of types_1.ClassType.getSymbolTable(mroClass)) {
|
17811
17844
|
if (field[0] !== '__call__' && !field[1].isIgnoredForProtocolMatch()) {
|
17812
17845
|
let fieldIsPartOfFunction = false;
|
17813
|
-
if (
|
17814
|
-
if (types_1.ClassType.getSymbolTable(
|
17846
|
+
if (functionClass && (0, types_1.isClass)(functionClass)) {
|
17847
|
+
if (types_1.ClassType.getSymbolTable(functionClass).has(field[0])) {
|
17815
17848
|
fieldIsPartOfFunction = true;
|
17816
17849
|
}
|
17817
17850
|
}
|
@@ -17822,13 +17855,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17822
17855
|
}
|
17823
17856
|
}
|
17824
17857
|
}
|
17825
|
-
|
17826
|
-
/* selfType */ undefined,
|
17827
|
-
/* diag */ undefined, recursionCount);
|
17828
|
-
if (boundMethod) {
|
17829
|
-
return (0, typeUtils_1.removeParamSpecVariadicsFromSignature)(boundMethod);
|
17830
|
-
}
|
17831
|
-
return undefined;
|
17858
|
+
return getBoundMagicMethod(objType, '__call__', /* selfType */ undefined, /* diag */ undefined, recursionCount);
|
17832
17859
|
}
|
17833
17860
|
function assignFunctionParameter(destType, srcType, paramIndex, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
|
17834
17861
|
// Handle the special case where the dest type is a synthesized
|
@@ -17960,17 +17987,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17960
17987
|
}
|
17961
17988
|
}
|
17962
17989
|
function assignFunction(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
|
17963
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
17990
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
17964
17991
|
let canAssign = true;
|
17965
17992
|
const checkReturnType = (flags & 64 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */) === 0;
|
17966
17993
|
const reverseMatching = (flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) !== 0;
|
17967
17994
|
flags &= ~64 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */;
|
17968
|
-
|
17969
|
-
|
17995
|
+
const destParamSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(destType);
|
17996
|
+
if (destParamSpec) {
|
17997
|
+
destType = types_1.FunctionType.cloneRemoveParamSpecArgsKwargs(destType);
|
17998
|
+
}
|
17999
|
+
const srcParamSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(srcType);
|
18000
|
+
if (srcParamSpec) {
|
18001
|
+
srcType = types_1.FunctionType.cloneRemoveParamSpecArgsKwargs(srcType);
|
18002
|
+
}
|
17970
18003
|
const destParamDetails = (0, parameterUtils_1.getParameterListDetails)(destType);
|
17971
18004
|
const srcParamDetails = (0, parameterUtils_1.getParameterListDetails)(srcType);
|
17972
18005
|
adjustSourceParamDetailsForDestVariadic(reverseMatching ? destParamDetails : srcParamDetails, reverseMatching ? srcParamDetails : destParamDetails);
|
17973
|
-
const targetIncludesParamSpec = reverseMatching ? !!
|
18006
|
+
const targetIncludesParamSpec = reverseMatching ? !!srcParamSpec : !!destParamSpec;
|
17974
18007
|
const destPositionalCount = (_a = destParamDetails.firstKeywordOnlyIndex) !== null && _a !== void 0 ? _a : destParamDetails.params.length;
|
17975
18008
|
const srcPositionalCount = (_b = srcParamDetails.firstKeywordOnlyIndex) !== null && _b !== void 0 ? _b : srcParamDetails.params.length;
|
17976
18009
|
const positionalsToMatch = Math.min(destPositionalCount, srcPositionalCount);
|
@@ -18058,7 +18091,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18058
18091
|
canAssign = false;
|
18059
18092
|
}
|
18060
18093
|
}
|
18061
|
-
if (!types_1.FunctionType.
|
18094
|
+
if (!types_1.FunctionType.isGradualCallableForm(destType) &&
|
18062
18095
|
destParamDetails.firstPositionOrKeywordIndex < srcParamDetails.positionOnlyParamCount &&
|
18063
18096
|
!targetIncludesParamSpec) {
|
18064
18097
|
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.argsPositionOnly().format({
|
@@ -18094,7 +18127,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18094
18127
|
}
|
18095
18128
|
continue;
|
18096
18129
|
}
|
18097
|
-
// If the source parameter is also
|
18130
|
+
// If the source parameter is also addressable by keyword, it is OK
|
18098
18131
|
// that there is no matching positional parameter in the dest.
|
18099
18132
|
if (srcParam.kind === parameterUtils_1.ParameterKind.Standard) {
|
18100
18133
|
continue;
|
@@ -18161,7 +18194,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18161
18194
|
// their types are compatible.
|
18162
18195
|
if (srcParamDetails.argsIndex !== undefined &&
|
18163
18196
|
destParamDetails.argsIndex !== undefined &&
|
18164
|
-
!types_1.FunctionType.
|
18197
|
+
!types_1.FunctionType.isGradualCallableForm(destType)) {
|
18165
18198
|
let destArgsType = destParamDetails.params[destParamDetails.argsIndex].type;
|
18166
18199
|
let srcArgsType = srcParamDetails.params[srcParamDetails.argsIndex].type;
|
18167
18200
|
if (!(0, types_1.isUnpacked)(destArgsType)) {
|
@@ -18176,9 +18209,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18176
18209
|
}
|
18177
18210
|
// If the dest has an "*args" but the source doesn't, report the incompatibility.
|
18178
18211
|
// The converse situation is OK.
|
18179
|
-
if (!types_1.FunctionType.
|
18212
|
+
if (!types_1.FunctionType.isGradualCallableForm(destType) &&
|
18180
18213
|
srcParamDetails.argsIndex === undefined &&
|
18181
|
-
|
18214
|
+
srcParamSpec === undefined &&
|
18182
18215
|
destParamDetails.argsIndex !== undefined &&
|
18183
18216
|
!destParamDetails.hasUnpackedVariadicTypeVar) {
|
18184
18217
|
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.argsParamMissing().format({
|
@@ -18293,9 +18326,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18293
18326
|
}
|
18294
18327
|
// If the dest has a "**kwargs" but the source doesn't, report the incompatibility.
|
18295
18328
|
// The converse situation is OK.
|
18296
|
-
if (!types_1.FunctionType.
|
18329
|
+
if (!types_1.FunctionType.isGradualCallableForm(destType) &&
|
18297
18330
|
srcParamDetails.kwargsIndex === undefined &&
|
18298
|
-
|
18331
|
+
srcParamSpec === undefined &&
|
18299
18332
|
destParamDetails.kwargsIndex !== undefined) {
|
18300
18333
|
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.kwargsParamMissing().format({
|
18301
18334
|
paramName: destParamDetails.params[destParamDetails.kwargsIndex].param.name,
|
@@ -18305,8 +18338,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18305
18338
|
}
|
18306
18339
|
// If the source and the dest are using the same ParamSpec, any additional
|
18307
18340
|
// concatenated parameters must match.
|
18308
|
-
if (targetIncludesParamSpec &&
|
18309
|
-
((_j = srcType.details.paramSpec) === null || _j === void 0 ? void 0 : _j.nameWithScope) === ((_k = destType.details.paramSpec) === null || _k === void 0 ? void 0 : _k.nameWithScope)) {
|
18341
|
+
if (targetIncludesParamSpec && (srcParamSpec === null || srcParamSpec === void 0 ? void 0 : srcParamSpec.nameWithScope) === (destParamSpec === null || destParamSpec === void 0 ? void 0 : destParamSpec.nameWithScope)) {
|
18310
18342
|
if (srcParamDetails.params.length !== destParamDetails.params.length) {
|
18311
18343
|
canAssign = false;
|
18312
18344
|
}
|
@@ -18321,9 +18353,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18321
18353
|
});
|
18322
18354
|
// Are we assigning to a function with a ParamSpec?
|
18323
18355
|
if (targetIncludesParamSpec) {
|
18324
|
-
const effectiveDestType = reverseMatching ? srcType : destType;
|
18325
18356
|
const effectiveSrcType = reverseMatching ? destType : srcType;
|
18326
|
-
|
18357
|
+
const effectiveDestType = reverseMatching ? srcType : destType;
|
18358
|
+
const effectiveSrcParamSpec = reverseMatching ? destParamSpec : srcParamSpec;
|
18359
|
+
const effectiveDestParamSpec = reverseMatching ? srcParamSpec : destParamSpec;
|
18360
|
+
if (effectiveDestParamSpec) {
|
18327
18361
|
const requiredMatchParamCount = effectiveDestType.details.parameters.filter((p) => {
|
18328
18362
|
if (!p.name) {
|
18329
18363
|
return false;
|
@@ -18360,13 +18394,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18360
18394
|
});
|
18361
18395
|
}
|
18362
18396
|
});
|
18363
|
-
const srcParamSpec = effectiveSrcType.details.paramSpec;
|
18364
|
-
const destParamSpec = effectiveDestType.details.paramSpec;
|
18365
18397
|
// If there are remaining parameters and the source and dest do not contain
|
18366
18398
|
// the same ParamSpec, synthesize a function for the remaining parameters.
|
18367
18399
|
if (remainingParams.length > 0 ||
|
18368
|
-
!
|
18369
|
-
!(0, types_1.isTypeSame)(
|
18400
|
+
!effectiveSrcParamSpec ||
|
18401
|
+
!(0, types_1.isTypeSame)(effectiveSrcParamSpec, effectiveDestParamSpec, { ignoreTypeFlags: true })) {
|
18370
18402
|
const remainingFunction = types_1.FunctionType.createInstance('', '', '', effectiveSrcType.details.flags | 64 /* FunctionTypeFlags.SynthesizedMethod */, effectiveSrcType.details.docString);
|
18371
18403
|
remainingFunction.details.deprecatedMessage = effectiveSrcType.details.deprecatedMessage;
|
18372
18404
|
remainingFunction.details.typeVarScopeId = effectiveSrcType.details.typeVarScopeId;
|
@@ -18376,16 +18408,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18376
18408
|
remainingParams.forEach((param) => {
|
18377
18409
|
types_1.FunctionType.addParameter(remainingFunction, param);
|
18378
18410
|
});
|
18379
|
-
|
18411
|
+
if (effectiveSrcParamSpec) {
|
18412
|
+
types_1.FunctionType.addParamSpecVariadics(remainingFunction, (0, typeUtils_1.convertToInstance)(effectiveSrcParamSpec));
|
18413
|
+
}
|
18380
18414
|
types_1.FunctionType.addHigherOrderTypeVarScopeIds(remainingFunction, effectiveSrcType.details.higherOrderTypeVarScopeIds);
|
18381
|
-
if (!assignType(
|
18415
|
+
if (!assignType(effectiveDestParamSpec, remainingFunction,
|
18382
18416
|
/* diag */ undefined, destTypeVarContext, srcTypeVarContext, flags)) {
|
18383
18417
|
// If we couldn't assign the function to the ParamSpec, see if we can
|
18384
18418
|
// assign only the ParamSpec. This is possible if there were no
|
18385
18419
|
// remaining parameters.
|
18386
18420
|
if (remainingParams.length > 0 ||
|
18387
|
-
!
|
18388
|
-
!assignType((0, typeUtils_1.convertToInstance)(
|
18421
|
+
!effectiveSrcParamSpec ||
|
18422
|
+
!assignType((0, typeUtils_1.convertToInstance)(effectiveDestParamSpec), (0, typeUtils_1.convertToInstance)(effectiveSrcParamSpec),
|
18389
18423
|
/* diag */ undefined, destTypeVarContext, srcTypeVarContext, flags)) {
|
18390
18424
|
canAssign = false;
|
18391
18425
|
}
|
@@ -18417,9 +18451,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18417
18451
|
// type at runtime.
|
18418
18452
|
if ((0, types_1.isClassInstance)(srcReturnType) &&
|
18419
18453
|
types_1.ClassType.isBuiltIn(srcReturnType, ['TypeGuard', 'TypeIs']) &&
|
18420
|
-
|
18421
|
-
(0, types_1.isInstantiableClass)(
|
18422
|
-
if (assignType(destReturnType, types_1.ClassType.cloneAsInstance(
|
18454
|
+
boolClass &&
|
18455
|
+
(0, types_1.isInstantiableClass)(boolClass)) {
|
18456
|
+
if (assignType(destReturnType, types_1.ClassType.cloneAsInstance(boolClass), returnDiag === null || returnDiag === void 0 ? void 0 : returnDiag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
18423
18457
|
isReturnTypeCompatible = true;
|
18424
18458
|
}
|
18425
18459
|
}
|
@@ -18467,7 +18501,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18467
18501
|
replacedTypeArg = true;
|
18468
18502
|
return expectedTypeArgType;
|
18469
18503
|
}
|
18470
|
-
|
18504
|
+
if ((0, types_1.isClassInstance)(expectedTypeArgType) && (0, types_1.isClassInstance)(typeArg)) {
|
18471
18505
|
// Recursively replace Any in the type argument.
|
18472
18506
|
const recursiveReplacement = replaceTypeArgsWithAny(node, expectedTypeArgType, typeArg, recursionCount);
|
18473
18507
|
if (recursiveReplacement) {
|
@@ -18506,8 +18540,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18506
18540
|
}
|
18507
18541
|
// When a value is assigned to a variable with a declared type,
|
18508
18542
|
// we may be able to narrow the type based on the assignment.
|
18509
|
-
function narrowTypeBasedOnAssignment(node, declaredType,
|
18510
|
-
|
18543
|
+
function narrowTypeBasedOnAssignment(node, declaredType, assignedTypeResult) {
|
18544
|
+
// TODO: The rules for narrowing types on assignment are not defined in
|
18545
|
+
// the typing spec. Pyright's current logic is currently not even internally
|
18546
|
+
// consistent and probably not sound from a type theory perspective. It
|
18547
|
+
// should be completely reworked once there has been a public discussion
|
18548
|
+
// about the correct behavior.
|
18549
|
+
// If the result is incomplete, do not attempt to narrow the type.
|
18550
|
+
if (assignedTypeResult.isIncomplete) {
|
18551
|
+
return assignedTypeResult;
|
18552
|
+
}
|
18553
|
+
const narrowedType = (0, typeUtils_1.mapSubtypes)(assignedTypeResult.type, (assignedSubtype) => {
|
18511
18554
|
// Handle the special case where the assigned type is a literal type.
|
18512
18555
|
// Some types include very large unions of literal types, and we don't
|
18513
18556
|
// want to use an n^2 loop to compare them.
|
@@ -18541,8 +18584,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18541
18584
|
return declaredSubtype;
|
18542
18585
|
}
|
18543
18586
|
// If the declared type doesn't contain any `Any` but the assigned
|
18544
|
-
// type does, stick with the declared type.
|
18545
|
-
|
18587
|
+
// type does, stick with the declared type. We don't include unknowns
|
18588
|
+
// in the assigned subtype check here so unknowns are preserved so
|
18589
|
+
// reportUnknownVariableType assignment diagnostics are reported.
|
18590
|
+
// TODO - this is an inconsistency because Any and Unknown should
|
18591
|
+
// always be treated the same for purposes of type narrowing. This
|
18592
|
+
// should be revisited once the narrowing-on-assignment behavior
|
18593
|
+
// is properly specified in the typing spec.
|
18594
|
+
if ((0, typeUtils_1.containsAnyRecursive)(assignedSubtype, /* includeUnknown */ false) &&
|
18595
|
+
!(0, typeUtils_1.containsAnyRecursive)(declaredSubtype)) {
|
18546
18596
|
return declaredSubtype;
|
18547
18597
|
}
|
18548
18598
|
return assignedSubtype;
|
@@ -18562,12 +18612,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18562
18612
|
// with the declared type. In strict mode, this will retain the "unknown type"
|
18563
18613
|
// diagnostics while still providing reasonable completion suggestions.
|
18564
18614
|
if ((0, typeUtils_1.isIncompleteUnknown)(narrowedType)) {
|
18565
|
-
return narrowedType;
|
18615
|
+
return { type: narrowedType };
|
18566
18616
|
}
|
18567
18617
|
else if ((0, types_1.isUnknown)(narrowedType)) {
|
18568
|
-
return (0, types_1.combineTypes)([narrowedType, declaredType]);
|
18618
|
+
return { type: (0, types_1.combineTypes)([narrowedType, declaredType]) };
|
18569
18619
|
}
|
18570
|
-
return narrowedType;
|
18620
|
+
return { type: narrowedType };
|
18571
18621
|
}
|
18572
18622
|
function validateOverrideMethod(baseMethod, overrideMethod, baseClass, diag, enforceParamNames = true) {
|
18573
18623
|
// If we're overriding a non-method with a method, report it as an error.
|
@@ -18697,8 +18747,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18697
18747
|
const baseParamDetails = (0, parameterUtils_1.getParameterListDetails)(baseMethod);
|
18698
18748
|
const overrideParamDetails = (0, parameterUtils_1.getParameterListDetails)(overrideMethod);
|
18699
18749
|
let canOverride = true;
|
18700
|
-
if (!types_1.FunctionType.
|
18701
|
-
!types_1.FunctionType.shouldSkipArgsKwargsCompatibilityCheck(overrideMethod)) {
|
18750
|
+
if (!types_1.FunctionType.isGradualCallableForm(baseMethod) && !types_1.FunctionType.isGradualCallableForm(overrideMethod)) {
|
18702
18751
|
// Verify that we're not overriding a static, class or instance method with
|
18703
18752
|
// an incompatible type.
|
18704
18753
|
if (types_1.FunctionType.isStaticMethod(baseMethod)) {
|
@@ -19158,7 +19207,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19158
19207
|
memberTypeFirstParam.hasDeclaredType) {
|
19159
19208
|
if (subDiag) {
|
19160
19209
|
subDiag.addMessage(localize_1.LocMessage.bindTypeMismatch().format({
|
19161
|
-
type: printType(
|
19210
|
+
type: printType(firstParamType),
|
19162
19211
|
methodName: memberType.details.name || '<anonymous>',
|
19163
19212
|
paramName: memberTypeFirstParam.name,
|
19164
19213
|
}));
|
@@ -19215,21 +19264,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19215
19264
|
case 56 /* ParseNodeType.Unpack */:
|
19216
19265
|
case 52 /* ParseNodeType.Tuple */:
|
19217
19266
|
case 9 /* ParseNodeType.Call */:
|
19218
|
-
case
|
19267
|
+
case 11 /* ParseNodeType.Comprehension */:
|
19219
19268
|
case 46 /* ParseNodeType.Slice */:
|
19220
19269
|
case 60 /* ParseNodeType.Yield */:
|
19221
19270
|
case 61 /* ParseNodeType.YieldFrom */:
|
19222
|
-
case
|
19271
|
+
case 33 /* ParseNodeType.Lambda */:
|
19223
19272
|
case 40 /* ParseNodeType.Number */:
|
19224
|
-
case
|
19225
|
-
case
|
19273
|
+
case 18 /* ParseNodeType.Dictionary */:
|
19274
|
+
case 34 /* ParseNodeType.List */:
|
19226
19275
|
case 45 /* ParseNodeType.Set */:
|
19227
19276
|
return false;
|
19228
19277
|
case 7 /* ParseNodeType.BinaryOperation */:
|
19229
19278
|
return (node.operator === 6 /* OperatorType.BitwiseOr */ &&
|
19230
19279
|
isLegalTypeAliasExpressionForm(node.leftExpression) &&
|
19231
19280
|
isLegalTypeAliasExpressionForm(node.rightExpression));
|
19232
|
-
case
|
19281
|
+
case 27 /* ParseNodeType.Index */:
|
19233
19282
|
return isLegalTypeAliasExpressionForm(node.baseExpression);
|
19234
19283
|
case 35 /* ParseNodeType.MemberAccess */:
|
19235
19284
|
return isLegalTypeAliasExpressionForm(node.leftExpression);
|