@zzzen/pyright-internal 1.2.0-dev.20240707 → 1.2.0-dev.20240714
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.js +74 -46
- package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
- package/dist/analyzer/binder.js +506 -512
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +649 -634
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +5 -3
- package/dist/analyzer/codeFlowEngine.js +87 -101
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/codeFlowTypes.js +30 -28
- package/dist/analyzer/codeFlowTypes.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +68 -64
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +22 -22
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.js +51 -48
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +109 -175
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declarationUtils.js +14 -15
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/decorators.js +77 -77
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/enums.js +70 -56
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/functionTransform.js +8 -18
- package/dist/analyzer/functionTransform.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +2 -1
- package/dist/analyzer/importResolver.js +40 -29
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importStatementUtils.js +27 -27
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/namedTuples.js +33 -59
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.js +66 -66
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +66 -62
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parameterUtils.d.ts +4 -4
- package/dist/analyzer/parameterUtils.js +28 -46
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.js +268 -269
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/parseTreeWalker.js +76 -76
- package/dist/analyzer/parseTreeWalker.js.map +1 -1
- package/dist/analyzer/patternMatching.js +176 -143
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.js +1 -1
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js +78 -147
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +21 -21
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/sourceFile.js +3 -3
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceMapper.js +20 -19
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/staticExpressions.js +83 -84
- package/dist/analyzer/staticExpressions.js.map +1 -1
- package/dist/analyzer/testWalker.js +2 -2
- package/dist/analyzer/testWalker.js.map +1 -1
- package/dist/analyzer/tracePrinter.js +20 -20
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.js +25 -25
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +1884 -1937
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +6 -5
- package/dist/analyzer/typeEvaluatorTypes.js +4 -1
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +211 -211
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +118 -115
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeStubWriter.js +104 -103
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +14 -3
- package/dist/analyzer/typeUtils.js +432 -402
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.js +8 -8
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/typeWalker.js +13 -10
- package/dist/analyzer/typeWalker.js.map +1 -1
- package/dist/analyzer/typedDicts.js +96 -198
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +144 -102
- package/dist/analyzer/types.js +662 -494
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +33 -33
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/fileSystem.d.ts +1 -0
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/fullAccessHost.js +6 -4
- package/dist/common/fullAccessHost.js.map +1 -1
- package/dist/common/realFileSystem.d.ts +1 -0
- package/dist/common/realFileSystem.js +4 -0
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/textEditTracker.js +14 -14
- package/dist/common/textEditTracker.js.map +1 -1
- package/dist/languageService/autoImporter.js +10 -10
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.js +23 -23
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/completionProvider.js +153 -151
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.d.ts +1 -1
- package/dist/languageService/definitionProvider.js +3 -1
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.js +19 -19
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/hoverProvider.js +25 -24
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/importSorter.js +8 -8
- package/dist/languageService/importSorter.js.map +1 -1
- package/dist/languageService/referencesProvider.js +8 -8
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.d.ts +1 -1
- package/dist/languageService/signatureHelpProvider.js +6 -6
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/symbolIndexer.js +3 -3
- package/dist/languageService/symbolIndexer.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +13 -13
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/parser/parseNodes.d.ts +468 -401
- package/dist/parser/parseNodes.js +626 -355
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.d.ts +1 -0
- package/dist/parser/parser.js +316 -294
- package/dist/parser/parser.js.map +1 -1
- package/dist/tests/classDeclaration.test.js +14 -14
- package/dist/tests/classDeclaration.test.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +3 -2
- package/dist/tests/harness/vfs/filesystem.js +6 -2
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/importResolver.test.js +4 -3
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/parseTreeUtils.test.js +5 -5
- package/dist/tests/parseTreeUtils.test.js.map +1 -1
- package/dist/tests/parser.test.js +8 -8
- package/dist/tests/parser.test.js.map +1 -1
- package/dist/tests/sourceMapperUtils.test.js +7 -7
- package/dist/tests/sourceMapperUtils.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +8 -3
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typePrinter.test.js +14 -39
- package/dist/tests/typePrinter.test.js.map +1 -1
- package/package.json +1 -1
@@ -6,9 +6,11 @@ import { Type, TypeVarType } from './types';
|
|
6
6
|
export interface FlowNodeTypeResult {
|
7
7
|
type: Type | undefined;
|
8
8
|
isIncomplete: boolean;
|
9
|
-
generationCount
|
10
|
-
|
11
|
-
|
9
|
+
generationCount: number | undefined;
|
10
|
+
incompleteSubtypes: IncompleteSubtypeInfo[] | undefined;
|
11
|
+
}
|
12
|
+
export declare namespace FlowNodeTypeResult {
|
13
|
+
function create(type: Type | undefined, isIncomplete: boolean, generationCount?: number, incompleteSubtypes?: IncompleteSubtypeInfo[]): FlowNodeTypeResult;
|
12
14
|
}
|
13
15
|
export interface FlowNodeTypeOptions {
|
14
16
|
targetSymbolId?: number;
|
@@ -12,7 +12,7 @@
|
|
12
12
|
* TypeScript compiler.
|
13
13
|
*/
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
exports.getCodeFlowEngine = exports.isIncompleteType = void 0;
|
15
|
+
exports.getCodeFlowEngine = exports.isIncompleteType = exports.FlowNodeTypeResult = void 0;
|
16
16
|
const debug_1 = require("../common/debug");
|
17
17
|
const positionUtils_1 = require("../common/positionUtils");
|
18
18
|
const analyzerNodeInfo_1 = require("./analyzerNodeInfo");
|
@@ -25,6 +25,18 @@ const typedDicts_1 = require("./typedDicts");
|
|
25
25
|
const typeGuards_1 = require("./typeGuards");
|
26
26
|
const types_1 = require("./types");
|
27
27
|
const typeUtils_1 = require("./typeUtils");
|
28
|
+
var FlowNodeTypeResult;
|
29
|
+
(function (FlowNodeTypeResult) {
|
30
|
+
function create(type, isIncomplete, generationCount, incompleteSubtypes) {
|
31
|
+
return {
|
32
|
+
type,
|
33
|
+
isIncomplete,
|
34
|
+
generationCount,
|
35
|
+
incompleteSubtypes,
|
36
|
+
};
|
37
|
+
}
|
38
|
+
FlowNodeTypeResult.create = create;
|
39
|
+
})(FlowNodeTypeResult || (exports.FlowNodeTypeResult = FlowNodeTypeResult = {}));
|
28
40
|
// Define a user type guard function for IncompleteType.
|
29
41
|
function isIncompleteType(cachedType) {
|
30
42
|
return !!cachedType.isIncompleteType;
|
@@ -125,12 +137,7 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
125
137
|
: type;
|
126
138
|
flowNodeTypeCache.cache.set(flowNode.id, entry);
|
127
139
|
speculativeTypeTracker.trackEntry(flowNodeTypeCache.cache, flowNode.id);
|
128
|
-
return
|
129
|
-
type,
|
130
|
-
isIncomplete,
|
131
|
-
generationCount: flowIncompleteGeneration,
|
132
|
-
incompleteSubtypes: isIncomplete ? [] : undefined,
|
133
|
-
};
|
140
|
+
return FlowNodeTypeResult.create(type, isIncomplete, flowIncompleteGeneration, isIncomplete ? [] : undefined);
|
134
141
|
}
|
135
142
|
function setIncompleteSubtype(flowNode, index, type, isIncomplete, isPending, evaluationCount) {
|
136
143
|
const cachedEntry = flowNodeTypeCache.cache.get(flowNode.id);
|
@@ -182,17 +189,13 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
182
189
|
}
|
183
190
|
const cachedEntry = flowNodeTypeCache.cache.get(flowNode.id);
|
184
191
|
if (cachedEntry === undefined) {
|
185
|
-
return
|
192
|
+
return FlowNodeTypeResult.create(/* type */ undefined, /* isIncomplete */ false);
|
186
193
|
}
|
187
194
|
if (!isIncompleteType(cachedEntry)) {
|
188
|
-
return
|
195
|
+
return FlowNodeTypeResult.create(cachedEntry, /* isIncomplete */ false);
|
189
196
|
}
|
190
|
-
return
|
191
|
-
|
192
|
-
isIncomplete: true,
|
193
|
-
incompleteSubtypes: cachedEntry.incompleteSubtypes,
|
194
|
-
generationCount: cachedEntry.generationCount,
|
195
|
-
};
|
197
|
+
return FlowNodeTypeResult.create(cachedEntry.type,
|
198
|
+
/* isIncomplete */ true, cachedEntry.generationCount, cachedEntry.incompleteSubtypes);
|
196
199
|
}
|
197
200
|
function deleteCacheEntry(flowNode) {
|
198
201
|
flowNodeTypeCache.cache.delete(flowNode.id);
|
@@ -246,18 +249,14 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
246
249
|
// If the cached entry is incomplete, we can use it only if nothing
|
247
250
|
// has changed that may cause the previously-reported incomplete type to change.
|
248
251
|
if (cachedEntry.generationCount === flowIncompleteGeneration) {
|
249
|
-
return
|
250
|
-
|
251
|
-
isIncomplete: true,
|
252
|
-
};
|
252
|
+
return FlowNodeTypeResult.create(cachedEntry.type ? (0, typeUtils_1.cleanIncompleteUnknown)(cachedEntry.type) : undefined,
|
253
|
+
/* isIncomplete */ true);
|
253
254
|
}
|
254
255
|
}
|
255
256
|
// Check for recursion.
|
256
257
|
if (flowNodeTypeCache.pendingNodes.has(curFlowNode.id)) {
|
257
|
-
return
|
258
|
-
|
259
|
-
isIncomplete: true,
|
260
|
-
};
|
258
|
+
return FlowNodeTypeResult.create((_a = cachedEntry === null || cachedEntry === void 0 ? void 0 : cachedEntry.type) !== null && _a !== void 0 ? _a : types_1.UnknownType.create(/* isIncomplete */ true),
|
259
|
+
/* isIncomplete */ true);
|
261
260
|
}
|
262
261
|
if (curFlowNode.flags & codeFlowTypes_1.FlowFlags.Unreachable) {
|
263
262
|
// We can get here if there are nodes in a compound logical expression
|
@@ -312,10 +311,7 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
312
311
|
if (flowTypeResult) {
|
313
312
|
if ((0, typeUtils_1.isTypeAliasPlaceholder)(flowTypeResult.type)) {
|
314
313
|
// Don't cache a recursive type alias placeholder.
|
315
|
-
return
|
316
|
-
type: flowTypeResult.type,
|
317
|
-
isIncomplete: true,
|
318
|
-
};
|
314
|
+
return FlowNodeTypeResult.create(flowTypeResult.type, /* isIncomplete */ true);
|
319
315
|
}
|
320
316
|
else if (reference.nodeType === 35 /* ParseNodeType.MemberAccess */ &&
|
321
317
|
evaluator.isAsymmetricAccessorAssignment(targetNode)) {
|
@@ -328,16 +324,16 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
328
324
|
// be assigning to a TypedDict, which requires narrowing of the expression's
|
329
325
|
// base type.
|
330
326
|
if (targetNode.nodeType === 27 /* ParseNodeType.Index */ &&
|
331
|
-
(0, parseTreeUtils_1.isMatchingExpression)(reference, targetNode.
|
327
|
+
(0, parseTreeUtils_1.isMatchingExpression)(reference, targetNode.d.leftExpr)) {
|
332
328
|
if (((_b = targetNode.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 3 /* ParseNodeType.Assignment */ &&
|
333
|
-
targetNode.items.length === 1 &&
|
334
|
-
!targetNode.trailingComma &&
|
335
|
-
!targetNode.items[0].name &&
|
336
|
-
targetNode.items[0].
|
337
|
-
targetNode.items[0].
|
338
|
-
targetNode.items[0].
|
339
|
-
targetNode.items[0].
|
340
|
-
const keyValue = targetNode.items[0].
|
329
|
+
targetNode.d.items.length === 1 &&
|
330
|
+
!targetNode.d.trailingComma &&
|
331
|
+
!targetNode.d.items[0].d.name &&
|
332
|
+
targetNode.d.items[0].d.argCategory === 0 /* ArgumentCategory.Simple */ &&
|
333
|
+
targetNode.d.items[0].d.valueExpr.nodeType === 48 /* ParseNodeType.StringList */ &&
|
334
|
+
targetNode.d.items[0].d.valueExpr.d.strings.length === 1 &&
|
335
|
+
targetNode.d.items[0].d.valueExpr.d.strings[0].nodeType === 49 /* ParseNodeType.String */) {
|
336
|
+
const keyValue = targetNode.d.items[0].d.valueExpr.d.strings[0].d.value;
|
341
337
|
const narrowedResult = preventRecursion(assignmentFlowNode, () => {
|
342
338
|
const flowTypeResult = getTypeFromFlowNode(assignmentFlowNode.antecedent);
|
343
339
|
if (flowTypeResult.type) {
|
@@ -360,10 +356,7 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
360
356
|
// a = Foo()
|
361
357
|
// x = a.b
|
362
358
|
// The type of "a.b" can no longer be assumed to be Literal[3].
|
363
|
-
return
|
364
|
-
type: (_c = options === null || options === void 0 ? void 0 : options.typeAtStart) === null || _c === void 0 ? void 0 : _c.type,
|
365
|
-
isIncomplete: !!((_d = options === null || options === void 0 ? void 0 : options.typeAtStart) === null || _d === void 0 ? void 0 : _d.isIncomplete),
|
366
|
-
};
|
359
|
+
return FlowNodeTypeResult.create((_c = options === null || options === void 0 ? void 0 : options.typeAtStart) === null || _c === void 0 ? void 0 : _c.type, !!((_d = options === null || options === void 0 ? void 0 : options.typeAtStart) === null || _d === void 0 ? void 0 : _d.isIncomplete));
|
367
360
|
}
|
368
361
|
}
|
369
362
|
curFlowNode = assignmentFlowNode.antecedent;
|
@@ -451,7 +444,7 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
451
444
|
// Make sure the reference type has a declared type. If not,
|
452
445
|
// don't bother trying to infer its type because that would be
|
453
446
|
// too expensive.
|
454
|
-
const symbolWithScope = evaluator.lookUpSymbolRecursive(conditionalFlowNode.reference, conditionalFlowNode.reference.value,
|
447
|
+
const symbolWithScope = evaluator.lookUpSymbolRecursive(conditionalFlowNode.reference, conditionalFlowNode.reference.d.value,
|
455
448
|
/* honorCodeFlow */ false);
|
456
449
|
if (symbolWithScope && symbolWithScope.symbol.hasTypedDeclarations()) {
|
457
450
|
const result = preventRecursion(curFlowNode, () => {
|
@@ -562,7 +555,7 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
562
555
|
if (curFlowNode.flags & codeFlowTypes_1.FlowFlags.WildcardImport) {
|
563
556
|
const wildcardImportFlowNode = curFlowNode;
|
564
557
|
if (reference && reference.nodeType === 38 /* ParseNodeType.Name */) {
|
565
|
-
const nameValue = reference.value;
|
558
|
+
const nameValue = reference.d.value;
|
566
559
|
if (wildcardImportFlowNode.names.some((name) => name === nameValue)) {
|
567
560
|
return preventRecursion(curFlowNode, () => {
|
568
561
|
const type = getTypeFromWildcardImport(wildcardImportFlowNode, nameValue);
|
@@ -615,10 +608,8 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
615
608
|
// If entries have been added for all antecedents and there are pending entries
|
616
609
|
// that have not been evaluated even once, treat it as incomplete. We clean
|
617
610
|
// any incomplete unknowns from the type here to assist with type convergence.
|
618
|
-
return
|
619
|
-
|
620
|
-
isIncomplete: true,
|
621
|
-
};
|
611
|
+
return FlowNodeTypeResult.create(cacheEntry.type ? (0, typeUtils_1.cleanIncompleteUnknown)(cacheEntry.type) : undefined,
|
612
|
+
/* isIncomplete */ true);
|
622
613
|
}
|
623
614
|
let attemptCount = 0;
|
624
615
|
while (true) {
|
@@ -705,7 +696,7 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
705
696
|
// entry because we'll overwrite a pending evaluation. The type that
|
706
697
|
// we return here doesn't matter as long as it's not undefined.
|
707
698
|
return sawPending
|
708
|
-
?
|
699
|
+
? FlowNodeTypeResult.create(types_1.UnknownType.create(), /* isIncomplete */ false)
|
709
700
|
: setCacheEntry(loopNode, types_1.UnknownType.create(), /* isIncomplete */ false);
|
710
701
|
}
|
711
702
|
let effectiveType = cacheEntry.type;
|
@@ -742,12 +733,12 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
742
733
|
// other incomplete types based on this now-complete type.
|
743
734
|
flowIncompleteGeneration++;
|
744
735
|
}
|
745
|
-
return
|
736
|
+
return FlowNodeTypeResult.create(effectiveType, reportIncomplete);
|
746
737
|
}
|
747
738
|
// If the first antecedent was pending, we skipped all of the other
|
748
739
|
// antecedents, so the type is incomplete.
|
749
740
|
if (firstAntecedentTypeIsPending) {
|
750
|
-
return
|
741
|
+
return FlowNodeTypeResult.create(effectiveType, /* isIncomplete */ true);
|
751
742
|
}
|
752
743
|
return setCacheEntry(loopNode, effectiveType, /* isIncomplete */ false);
|
753
744
|
}
|
@@ -757,15 +748,12 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
757
748
|
function getTypeFromPreFinallyGateFlowNode(preFinallyFlowNode) {
|
758
749
|
// Is the finally gate closed?
|
759
750
|
if (flowNodeTypeCache.closedFinallyGateNodes.has(preFinallyFlowNode.id)) {
|
760
|
-
return
|
751
|
+
return FlowNodeTypeResult.create(/* type */ undefined, /* isIncomplete */ false);
|
761
752
|
}
|
762
753
|
const flowTypeResult = getTypeFromFlowNode(preFinallyFlowNode.antecedent);
|
763
754
|
// We want to cache the type only if we're evaluating the "gate closed" path.
|
764
755
|
deleteCacheEntry(preFinallyFlowNode);
|
765
|
-
return
|
766
|
-
type: flowTypeResult.type,
|
767
|
-
isIncomplete: flowTypeResult.isIncomplete,
|
768
|
-
};
|
756
|
+
return FlowNodeTypeResult.create(flowTypeResult.type, flowTypeResult.isIncomplete);
|
769
757
|
}
|
770
758
|
function getTypeFromPostFinallyFlowNode(postFinallyFlowNode) {
|
771
759
|
const wasGateClosed = flowNodeTypeCache.closedFinallyGateNodes.has(postFinallyFlowNode.preFinallyGate.id);
|
@@ -794,10 +782,7 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
794
782
|
// parse nodes that are created after the initial parse
|
795
783
|
// (namely, string literals that are used for forward
|
796
784
|
// referenced types).
|
797
|
-
return
|
798
|
-
type: (_a = options === null || options === void 0 ? void 0 : options.typeAtStart) === null || _a === void 0 ? void 0 : _a.type,
|
799
|
-
isIncomplete: !!((_b = options === null || options === void 0 ? void 0 : options.typeAtStart) === null || _b === void 0 ? void 0 : _b.isIncomplete),
|
800
|
-
};
|
785
|
+
return FlowNodeTypeResult.create((_a = options === null || options === void 0 ? void 0 : options.typeAtStart) === null || _a === void 0 ? void 0 : _a.type, !!((_b = options === null || options === void 0 ? void 0 : options.typeAtStart) === null || _b === void 0 ? void 0 : _b.isIncomplete));
|
801
786
|
}
|
802
787
|
return getTypeFromFlowNode(flowNode);
|
803
788
|
}
|
@@ -892,7 +877,7 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
892
877
|
// Make sure the reference type has a declared type. If not,
|
893
878
|
// don't bother trying to infer its type because that would be
|
894
879
|
// too expensive.
|
895
|
-
const symbolWithScope = evaluator.lookUpSymbolRecursive(conditionalFlowNode.reference, conditionalFlowNode.reference.value,
|
880
|
+
const symbolWithScope = evaluator.lookUpSymbolRecursive(conditionalFlowNode.reference, conditionalFlowNode.reference.d.value,
|
896
881
|
/* honorCodeFlow */ false);
|
897
882
|
if (symbolWithScope && symbolWithScope.symbol.hasTypedDeclarations()) {
|
898
883
|
let isUnreachable = false;
|
@@ -988,13 +973,13 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
988
973
|
// can be narrowed to one of its constrained types based on isinstance type
|
989
974
|
// guard checks.
|
990
975
|
function narrowConstrainedTypeVar(flowNode, typeVar) {
|
991
|
-
(0, debug_1.assert)(!typeVar.
|
992
|
-
(0, debug_1.assert)(!typeVar.
|
993
|
-
(0, debug_1.assert)(!typeVar.
|
994
|
-
(0, debug_1.assert)(typeVar.
|
976
|
+
(0, debug_1.assert)(!typeVar.shared.isParamSpec);
|
977
|
+
(0, debug_1.assert)(!typeVar.shared.isVariadic);
|
978
|
+
(0, debug_1.assert)(!typeVar.shared.boundType);
|
979
|
+
(0, debug_1.assert)(typeVar.shared.constraints.length > 0);
|
995
980
|
const visitedFlowNodeMap = new Set();
|
996
981
|
const startingConstraints = [];
|
997
|
-
for (const constraint of typeVar.
|
982
|
+
for (const constraint of typeVar.shared.constraints) {
|
998
983
|
if ((0, types_1.isClassInstance)(constraint)) {
|
999
984
|
startingConstraints.push(constraint);
|
1000
985
|
}
|
@@ -1033,12 +1018,12 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
1033
1018
|
if (narrowForPatternFlowNode.statement.nodeType === 64 /* ParseNodeType.Case */) {
|
1034
1019
|
const subjectType = evaluator.getTypeOfExpression(narrowForPatternFlowNode.subjectExpression).type;
|
1035
1020
|
if (isCompatibleWithConstrainedTypeVar(subjectType, typeVar)) {
|
1036
|
-
const patternNode = narrowForPatternFlowNode.statement.pattern;
|
1021
|
+
const patternNode = narrowForPatternFlowNode.statement.d.pattern;
|
1037
1022
|
if (patternNode.nodeType === 66 /* ParseNodeType.PatternAs */ &&
|
1038
|
-
patternNode.orPatterns.length === 1 &&
|
1039
|
-
patternNode.orPatterns[0].nodeType === 68 /* ParseNodeType.PatternClass */) {
|
1040
|
-
const classPatternNode = patternNode.orPatterns[0];
|
1041
|
-
const classType = evaluator.getTypeOfExpression(classPatternNode.className, 2 /* EvalFlags.CallBaseDefaults */).type;
|
1023
|
+
patternNode.d.orPatterns.length === 1 &&
|
1024
|
+
patternNode.d.orPatterns[0].nodeType === 68 /* ParseNodeType.PatternClass */) {
|
1025
|
+
const classPatternNode = patternNode.d.orPatterns[0];
|
1026
|
+
const classType = evaluator.getTypeOfExpression(classPatternNode.d.className, 2 /* EvalFlags.CallBaseDefaults */).type;
|
1042
1027
|
if ((0, types_1.isInstantiableClass)(classType)) {
|
1043
1028
|
const priorRemainingConstraints = narrowConstrainedTypeVarRecursive(narrowForPatternFlowNode.antecedent, typeVar);
|
1044
1029
|
return priorRemainingConstraints.filter((subtype) => types_1.ClassType.isSameGenericClass(subtype, classType));
|
@@ -1055,17 +1040,17 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
1055
1040
|
const testExpression = conditionFlowNode.expression;
|
1056
1041
|
const isPositiveTest = (curFlowNode.flags & codeFlowTypes_1.FlowFlags.TrueCondition) !== 0;
|
1057
1042
|
if (testExpression.nodeType === 9 /* ParseNodeType.Call */ &&
|
1058
|
-
testExpression.
|
1059
|
-
testExpression.
|
1060
|
-
testExpression.
|
1061
|
-
const arg0Expr = testExpression.
|
1043
|
+
testExpression.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ &&
|
1044
|
+
testExpression.d.leftExpr.d.value === 'isinstance' &&
|
1045
|
+
testExpression.d.args.length === 2) {
|
1046
|
+
const arg0Expr = testExpression.d.args[0].d.valueExpr;
|
1062
1047
|
const arg0Type = evaluator.getTypeOfExpression(arg0Expr).type;
|
1063
1048
|
if (isCompatibleWithConstrainedTypeVar(arg0Type, typeVar)) {
|
1064
1049
|
// Prevent infinite recursion by noting that we've been here before.
|
1065
1050
|
visitedFlowNodeMap.add(curFlowNode.id);
|
1066
1051
|
const priorRemainingConstraints = narrowConstrainedTypeVarRecursive(conditionFlowNode.antecedent, typeVar);
|
1067
1052
|
visitedFlowNodeMap.delete(curFlowNode.id);
|
1068
|
-
const arg1Expr = testExpression.
|
1053
|
+
const arg1Expr = testExpression.d.args[1].d.valueExpr;
|
1069
1054
|
const arg1Type = evaluator.getTypeOfExpression(arg1Expr, 512 /* EvalFlags.AllowMissingTypeArgs */ |
|
1070
1055
|
8 /* EvalFlags.StrLiteralAsType */ |
|
1071
1056
|
32 /* EvalFlags.NoParamSpec */ |
|
@@ -1118,14 +1103,15 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
1118
1103
|
function isCompatibleWithConstrainedTypeVar(type, typeVar) {
|
1119
1104
|
let isCompatible = true;
|
1120
1105
|
(0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
|
1106
|
+
var _a;
|
1121
1107
|
if ((0, types_1.isTypeVar)(subtype)) {
|
1122
1108
|
if (!(0, types_1.isTypeSame)(subtype, typeVar)) {
|
1123
1109
|
isCompatible = false;
|
1124
1110
|
}
|
1125
1111
|
}
|
1126
|
-
else if (subtype.condition) {
|
1127
|
-
if (!subtype.condition.some((condition) => condition.typeVar.
|
1128
|
-
condition.typeVar.nameWithScope === typeVar.nameWithScope)) {
|
1112
|
+
else if ((_a = subtype.props) === null || _a === void 0 ? void 0 : _a.condition) {
|
1113
|
+
if (!subtype.props.condition.some((condition) => condition.typeVar.shared.constraints.length > 0 &&
|
1114
|
+
condition.typeVar.priv.nameWithScope === typeVar.priv.nameWithScope)) {
|
1129
1115
|
isCompatible = false;
|
1130
1116
|
}
|
1131
1117
|
}
|
@@ -1156,7 +1142,7 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
1156
1142
|
}
|
1157
1143
|
// Don't attempt to evaluate a lambda call. We need to evaluate these in the
|
1158
1144
|
// context of its arguments.
|
1159
|
-
if (node.
|
1145
|
+
if (node.d.leftExpr.nodeType === 33 /* ParseNodeType.Lambda */) {
|
1160
1146
|
return false;
|
1161
1147
|
}
|
1162
1148
|
// Initially set to false to avoid recursion.
|
@@ -1166,7 +1152,7 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
1166
1152
|
let noReturnTypeCount = 0;
|
1167
1153
|
let subtypeCount = 0;
|
1168
1154
|
// Evaluate the call base type.
|
1169
|
-
const callTypeResult = evaluator.getTypeOfExpression(node.
|
1155
|
+
const callTypeResult = evaluator.getTypeOfExpression(node.d.leftExpr, 2 /* EvalFlags.CallBaseDefaults */);
|
1170
1156
|
const callType = callTypeResult.type;
|
1171
1157
|
(0, typeUtils_1.doForEachSubtype)(callType, (callSubtype) => {
|
1172
1158
|
var _a;
|
@@ -1217,7 +1203,7 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
1217
1203
|
else {
|
1218
1204
|
// Perform a more complete evaluation to determine whether
|
1219
1205
|
// the applicable overload returns a NoReturn.
|
1220
|
-
const callResult = evaluator.validateOverloadedFunctionArguments(node, node.
|
1206
|
+
const callResult = evaluator.validateOverloadedFunctionArguments(node, node.d.args.map((arg) => (0, typeUtils_1.convertArgumentNodeToFunctionArgument)(arg)), { type: callSubtype, isIncomplete: callTypeResult.isIncomplete },
|
1221
1207
|
/* typeVarContext */ undefined,
|
1222
1208
|
/* skipUnknownArgCheck */ false,
|
1223
1209
|
/* inferenceContext */ undefined,
|
@@ -1243,13 +1229,13 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
1243
1229
|
}
|
1244
1230
|
}
|
1245
1231
|
function isFunctionNoReturn(functionType, isCallAwaited) {
|
1246
|
-
const returnType = functionType.
|
1232
|
+
const returnType = functionType.shared.declaredReturnType;
|
1247
1233
|
if (returnType) {
|
1248
1234
|
if ((0, types_1.isClassInstance)(returnType) &&
|
1249
1235
|
types_1.ClassType.isBuiltIn(returnType, 'Coroutine') &&
|
1250
|
-
returnType.typeArguments &&
|
1251
|
-
returnType.typeArguments.length >= 3) {
|
1252
|
-
if ((0, types_1.isNever)(returnType.typeArguments[2]) && isCallAwaited) {
|
1236
|
+
returnType.priv.typeArguments &&
|
1237
|
+
returnType.priv.typeArguments.length >= 3) {
|
1238
|
+
if ((0, types_1.isNever)(returnType.priv.typeArguments[2]) && isCallAwaited) {
|
1253
1239
|
return true;
|
1254
1240
|
}
|
1255
1241
|
}
|
@@ -1258,29 +1244,29 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
1258
1244
|
else if (!inferNoReturnForUnannotatedFunctions) {
|
1259
1245
|
return false;
|
1260
1246
|
}
|
1261
|
-
else if (functionType.
|
1247
|
+
else if (functionType.shared.declaration) {
|
1262
1248
|
// If the function is a generator (i.e. it has yield statements)
|
1263
1249
|
// then it is not a "no return" call. Also, don't infer a "no
|
1264
1250
|
// return" type for abstract methods.
|
1265
|
-
if (!functionType.
|
1251
|
+
if (!functionType.shared.declaration.isGenerator &&
|
1266
1252
|
!types_1.FunctionType.isAbstractMethod(functionType) &&
|
1267
1253
|
!types_1.FunctionType.isStubDefinition(functionType) &&
|
1268
1254
|
!types_1.FunctionType.isPyTypedDefinition(functionType)) {
|
1269
1255
|
// Check specifically for a common idiom where the only statement
|
1270
1256
|
// (other than a possible docstring) is a "raise NotImplementedError".
|
1271
|
-
const functionStatements = functionType.
|
1257
|
+
const functionStatements = functionType.shared.declaration.node.d.suite.d.statements;
|
1272
1258
|
let foundRaiseNotImplemented = false;
|
1273
1259
|
for (const statement of functionStatements) {
|
1274
|
-
if (statement.nodeType !== 47 /* ParseNodeType.StatementList */ || statement.statements.length !== 1) {
|
1260
|
+
if (statement.nodeType !== 47 /* ParseNodeType.StatementList */ || statement.d.statements.length !== 1) {
|
1275
1261
|
break;
|
1276
1262
|
}
|
1277
|
-
const simpleStatement = statement.statements[0];
|
1263
|
+
const simpleStatement = statement.d.statements[0];
|
1278
1264
|
if (simpleStatement.nodeType === 48 /* ParseNodeType.StringList */) {
|
1279
1265
|
continue;
|
1280
1266
|
}
|
1281
|
-
if (simpleStatement.nodeType === 43 /* ParseNodeType.Raise */ && simpleStatement.typeExpression) {
|
1267
|
+
if (simpleStatement.nodeType === 43 /* ParseNodeType.Raise */ && simpleStatement.d.typeExpression) {
|
1282
1268
|
// Check for a raising about 'NotImplementedError' or a subtype thereof.
|
1283
|
-
const exceptionType = evaluator.getType(simpleStatement.typeExpression);
|
1269
|
+
const exceptionType = evaluator.getType(simpleStatement.d.typeExpression);
|
1284
1270
|
if (exceptionType &&
|
1285
1271
|
(0, types_1.isClass)(exceptionType) &&
|
1286
1272
|
(0, typeUtils_1.derivesFromStdlibClass)(exceptionType, 'NotImplementedError')) {
|
@@ -1297,10 +1283,10 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
1297
1283
|
return false;
|
1298
1284
|
}
|
1299
1285
|
function isAfterNodeReachable(evaluator, functionType) {
|
1300
|
-
if (!functionType.
|
1286
|
+
if (!functionType.shared.declaration) {
|
1301
1287
|
return true;
|
1302
1288
|
}
|
1303
|
-
return evaluator.isAfterNodeReachable(functionType.
|
1289
|
+
return evaluator.isAfterNodeReachable(functionType.shared.declaration.node);
|
1304
1290
|
}
|
1305
1291
|
// Performs a cursory analysis to determine whether the expression
|
1306
1292
|
// corresponds to a context manager object that supports the swallowing
|
@@ -1326,22 +1312,22 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
1326
1312
|
if (cmType && (0, types_1.isClassInstance)(cmType)) {
|
1327
1313
|
const exitMethodName = isAsync ? '__aexit__' : '__exit__';
|
1328
1314
|
const exitType = evaluator.getBoundMagicMethod(cmType, exitMethodName);
|
1329
|
-
if (exitType && (0, types_1.isFunction)(exitType) && exitType.
|
1330
|
-
let returnType = exitType.
|
1315
|
+
if (exitType && (0, types_1.isFunction)(exitType) && exitType.shared.declaredReturnType) {
|
1316
|
+
let returnType = exitType.shared.declaredReturnType;
|
1331
1317
|
// If it's an __aexit__ method, its return type will typically be wrapped
|
1332
1318
|
// in a Coroutine, so we need to extract the return type from the third
|
1333
1319
|
// type argument.
|
1334
1320
|
if (isAsync) {
|
1335
1321
|
if ((0, types_1.isClassInstance)(returnType) &&
|
1336
1322
|
types_1.ClassType.isBuiltIn(returnType, 'Coroutine') &&
|
1337
|
-
returnType.typeArguments &&
|
1338
|
-
returnType.typeArguments.length >= 3) {
|
1339
|
-
returnType = returnType.typeArguments[2];
|
1323
|
+
returnType.priv.typeArguments &&
|
1324
|
+
returnType.priv.typeArguments.length >= 3) {
|
1325
|
+
returnType = returnType.priv.typeArguments[2];
|
1340
1326
|
}
|
1341
1327
|
}
|
1342
1328
|
cmSwallowsExceptions = false;
|
1343
1329
|
if ((0, types_1.isClassInstance)(returnType) && types_1.ClassType.isBuiltIn(returnType, 'bool')) {
|
1344
|
-
if (returnType.literalValue === undefined || returnType.literalValue === true) {
|
1330
|
+
if (returnType.priv.literalValue === undefined || returnType.priv.literalValue === true) {
|
1345
1331
|
cmSwallowsExceptions = true;
|
1346
1332
|
}
|
1347
1333
|
}
|
@@ -1356,9 +1342,9 @@ function getCodeFlowEngine(evaluator, speculativeTypeTracker) {
|
|
1356
1342
|
return cmSwallowsExceptions;
|
1357
1343
|
}
|
1358
1344
|
function getTypeFromWildcardImport(flowNode, name) {
|
1359
|
-
const importInfo = (0, analyzerNodeInfo_1.getImportInfo)(flowNode.node.module);
|
1345
|
+
const importInfo = (0, analyzerNodeInfo_1.getImportInfo)(flowNode.node.d.module);
|
1360
1346
|
(0, debug_1.assert)(importInfo !== undefined && importInfo.isImportFound);
|
1361
|
-
(0, debug_1.assert)(flowNode.node.isWildcardImport);
|
1347
|
+
(0, debug_1.assert)(flowNode.node.d.isWildcardImport);
|
1362
1348
|
const symbolWithScope = evaluator.lookUpSymbolRecursive(flowNode.node, name, /* honorCodeFlow */ false);
|
1363
1349
|
(0, debug_1.assert)(symbolWithScope !== undefined);
|
1364
1350
|
const decls = symbolWithScope.symbol.getDeclarations();
|