@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
package/dist/analyzer/binder.js
CHANGED
@@ -128,14 +128,10 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
128
128
|
this._addImplicitSymbolToCurrentScope('__dict__', node, 'Dict[str, Any]');
|
129
129
|
this._addImplicitSymbolToCurrentScope('__annotations__', node, 'Dict[str, Any]');
|
130
130
|
this._addImplicitSymbolToCurrentScope('__builtins__', node, 'Any');
|
131
|
-
|
132
|
-
// that the type of `__doc__` is `str` rather than `str | None`. This
|
133
|
-
// doesn't apply to stub files.
|
134
|
-
const moduleDocString = ParseTreeUtils.getDocString(node.statements);
|
135
|
-
this._addImplicitSymbolToCurrentScope('__doc__', node, !this._fileInfo.isStubFile && moduleDocString ? 'str' : 'str | None');
|
131
|
+
this._addImplicitSymbolToCurrentScope('__doc__', node, 'str | None');
|
136
132
|
// Create a start node for the module.
|
137
133
|
this._currentFlowNode = this._createStartFlowNode();
|
138
|
-
this._walkStatementsAndReportUnreachable(node.statements);
|
134
|
+
this._walkStatementsAndReportUnreachable(node.d.statements);
|
139
135
|
// Associate the code flow node at the end of the module with the module.
|
140
136
|
AnalyzerNodeInfo.setAfterFlowNode(node, this._currentFlowNode);
|
141
137
|
AnalyzerNodeInfo.setCodeFlowExpressions(node, this._currentScopeCodeFlowExpressions);
|
@@ -187,7 +183,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
187
183
|
return false;
|
188
184
|
}
|
189
185
|
visitSuite(node) {
|
190
|
-
this._walkStatementsAndReportUnreachable(node.statements);
|
186
|
+
this._walkStatementsAndReportUnreachable(node.d.statements);
|
191
187
|
return false;
|
192
188
|
}
|
193
189
|
visitModuleName(node) {
|
@@ -220,27 +216,27 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
220
216
|
return true;
|
221
217
|
}
|
222
218
|
visitClass(node) {
|
223
|
-
this.walkMultiple(node.decorators);
|
219
|
+
this.walkMultiple(node.d.decorators);
|
224
220
|
const classDeclaration = {
|
225
221
|
type: 6 /* DeclarationType.Class */,
|
226
222
|
node,
|
227
223
|
uri: this._fileInfo.fileUri,
|
228
|
-
range: (0, positionUtils_1.convertTextRangeToRange)(node.name, this._fileInfo.lines),
|
224
|
+
range: (0, positionUtils_1.convertTextRangeToRange)(node.d.name, this._fileInfo.lines),
|
229
225
|
moduleName: this._fileInfo.moduleName,
|
230
226
|
isInExceptSuite: this._isInExceptSuite,
|
231
227
|
};
|
232
|
-
const symbol = this._bindNameToScope(this._currentScope, node.name);
|
228
|
+
const symbol = this._bindNameToScope(this._currentScope, node.d.name);
|
233
229
|
if (symbol) {
|
234
230
|
symbol.addDeclaration(classDeclaration);
|
235
231
|
}
|
236
232
|
// Stash the declaration in the parse node for later access.
|
237
233
|
AnalyzerNodeInfo.setDeclaration(node, classDeclaration);
|
238
234
|
let typeParamScope;
|
239
|
-
if (node.
|
240
|
-
this.walk(node.
|
241
|
-
typeParamScope = AnalyzerNodeInfo.getScope(node.
|
235
|
+
if (node.d.typeParams) {
|
236
|
+
this.walk(node.d.typeParams);
|
237
|
+
typeParamScope = AnalyzerNodeInfo.getScope(node.d.typeParams);
|
242
238
|
}
|
243
|
-
this.walkMultiple(node.arguments);
|
239
|
+
this.walkMultiple(node.d.arguments);
|
244
240
|
this._createNewScope(3 /* ScopeType.Class */, typeParamScope !== null && typeParamScope !== void 0 ? typeParamScope : this._getNonClassParentScope(),
|
245
241
|
/* proxyScope */ undefined, () => {
|
246
242
|
AnalyzerNodeInfo.setScope(node, this._currentScope);
|
@@ -250,20 +246,20 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
250
246
|
this._dunderSlotsEntries = undefined;
|
251
247
|
if (!this._moduleSymbolOnly) {
|
252
248
|
// Analyze the suite.
|
253
|
-
this.walk(node.suite);
|
249
|
+
this.walk(node.d.suite);
|
254
250
|
}
|
255
251
|
if (this._dunderSlotsEntries) {
|
256
252
|
this._addSlotsToCurrentScope(this._dunderSlotsEntries);
|
257
253
|
}
|
258
254
|
this._dunderSlotsEntries = undefined;
|
259
255
|
});
|
260
|
-
this._createAssignmentTargetFlowNodes(node.name, /* walkTargets */ false, /* unbound */ false);
|
256
|
+
this._createAssignmentTargetFlowNodes(node.d.name, /* walkTargets */ false, /* unbound */ false);
|
261
257
|
return false;
|
262
258
|
}
|
263
259
|
visitFunction(node) {
|
264
260
|
this._createVariableAnnotationFlowNode();
|
265
261
|
AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode);
|
266
|
-
const symbol = this._bindNameToScope(this._currentScope, node.name);
|
262
|
+
const symbol = this._bindNameToScope(this._currentScope, node.d.name);
|
267
263
|
const containingClassNode = ParseTreeUtils.getEnclosingClass(node, /* stopAtFunction */ true);
|
268
264
|
const functionDeclaration = {
|
269
265
|
type: 5 /* DeclarationType.Function */,
|
@@ -271,7 +267,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
271
267
|
isMethod: !!containingClassNode,
|
272
268
|
isGenerator: false,
|
273
269
|
uri: this._fileInfo.fileUri,
|
274
|
-
range: (0, positionUtils_1.convertTextRangeToRange)(node.name, this._fileInfo.lines),
|
270
|
+
range: (0, positionUtils_1.convertTextRangeToRange)(node.d.name, this._fileInfo.lines),
|
275
271
|
moduleName: this._fileInfo.moduleName,
|
276
272
|
isInExceptSuite: this._isInExceptSuite,
|
277
273
|
};
|
@@ -281,30 +277,30 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
281
277
|
// Stash the declaration in the parse node for later access.
|
282
278
|
AnalyzerNodeInfo.setDeclaration(node, functionDeclaration);
|
283
279
|
// Walk the default values prior to the type parameters.
|
284
|
-
node.
|
285
|
-
if (param.defaultValue) {
|
286
|
-
this.walk(param.defaultValue);
|
280
|
+
node.d.params.forEach((param) => {
|
281
|
+
if (param.d.defaultValue) {
|
282
|
+
this.walk(param.d.defaultValue);
|
287
283
|
}
|
288
284
|
});
|
289
285
|
let typeParamScope;
|
290
|
-
if (node.
|
291
|
-
this.walk(node.
|
292
|
-
typeParamScope = AnalyzerNodeInfo.getScope(node.
|
286
|
+
if (node.d.typeParams) {
|
287
|
+
this.walk(node.d.typeParams);
|
288
|
+
typeParamScope = AnalyzerNodeInfo.getScope(node.d.typeParams);
|
293
289
|
}
|
294
|
-
this.walkMultiple(node.decorators);
|
295
|
-
node.
|
296
|
-
if (param.
|
297
|
-
this.walk(param.
|
290
|
+
this.walkMultiple(node.d.decorators);
|
291
|
+
node.d.params.forEach((param) => {
|
292
|
+
if (param.d.annotation) {
|
293
|
+
this.walk(param.d.annotation);
|
298
294
|
}
|
299
|
-
if (param.
|
300
|
-
this.walk(param.
|
295
|
+
if (param.d.annotationComment) {
|
296
|
+
this.walk(param.d.annotationComment);
|
301
297
|
}
|
302
298
|
});
|
303
|
-
if (node.
|
304
|
-
this.walk(node.
|
299
|
+
if (node.d.returnAnnotation) {
|
300
|
+
this.walk(node.d.returnAnnotation);
|
305
301
|
}
|
306
|
-
if (node.
|
307
|
-
this.walk(node.
|
302
|
+
if (node.d.funcAnnotationComment) {
|
303
|
+
this.walk(node.d.funcAnnotationComment);
|
308
304
|
}
|
309
305
|
// Don't walk the body of the function until we're done analyzing
|
310
306
|
// the current scope.
|
@@ -320,14 +316,14 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
320
316
|
// Create a start node for the function.
|
321
317
|
this._currentFlowNode = this._createStartFlowNode();
|
322
318
|
this._codeFlowComplexity = 0;
|
323
|
-
node.
|
319
|
+
node.d.params.forEach((paramNode) => {
|
324
320
|
var _a, _b;
|
325
|
-
if (paramNode.name) {
|
326
|
-
const symbol = this._bindNameToScope(this._currentScope, paramNode.name);
|
321
|
+
if (paramNode.d.name) {
|
322
|
+
const symbol = this._bindNameToScope(this._currentScope, paramNode.d.name);
|
327
323
|
// Extract the parameter docString from the function docString
|
328
|
-
let docString = ParseTreeUtils.getDocString((_b = (_a = node === null || node === void 0 ? void 0 : node.suite) === null || _a === void 0 ? void 0 : _a.statements) !== null && _b !== void 0 ? _b : []);
|
324
|
+
let docString = ParseTreeUtils.getDocString((_b = (_a = node === null || node === void 0 ? void 0 : node.d.suite) === null || _a === void 0 ? void 0 : _a.d.statements) !== null && _b !== void 0 ? _b : []);
|
329
325
|
if (docString !== undefined) {
|
330
|
-
docString = (0, docStringUtils_1.extractParameterDocumentation)(docString, paramNode.name.value);
|
326
|
+
docString = (0, docStringUtils_1.extractParameterDocumentation)(docString, paramNode.d.name.d.value);
|
331
327
|
}
|
332
328
|
if (symbol) {
|
333
329
|
const paramDeclaration = {
|
@@ -340,19 +336,19 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
340
336
|
docString: docString,
|
341
337
|
};
|
342
338
|
symbol.addDeclaration(paramDeclaration);
|
343
|
-
AnalyzerNodeInfo.setDeclaration(paramNode.name, paramDeclaration);
|
339
|
+
AnalyzerNodeInfo.setDeclaration(paramNode.d.name, paramDeclaration);
|
344
340
|
}
|
345
|
-
this._createFlowAssignment(paramNode.name);
|
341
|
+
this._createFlowAssignment(paramNode.d.name);
|
346
342
|
}
|
347
343
|
});
|
348
344
|
this._targetFunctionDeclaration = functionDeclaration;
|
349
345
|
this._currentReturnTarget = this._createBranchLabel();
|
350
346
|
// Walk the statements that make up the function.
|
351
|
-
this.walk(node.suite);
|
347
|
+
this.walk(node.d.suite);
|
352
348
|
this._targetFunctionDeclaration = undefined;
|
353
349
|
// Associate the code flow node at the end of the suite with
|
354
350
|
// the suite.
|
355
|
-
AnalyzerNodeInfo.setAfterFlowNode(node.suite, this._currentFlowNode);
|
351
|
+
AnalyzerNodeInfo.setAfterFlowNode(node.d.suite, this._currentFlowNode);
|
356
352
|
// Compute the final return flow node and associate it with
|
357
353
|
// the function's parse node. If this node is unreachable, then
|
358
354
|
// the function never returns.
|
@@ -363,7 +359,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
363
359
|
AnalyzerNodeInfo.setCodeFlowComplexity(node, this._codeFlowComplexity);
|
364
360
|
});
|
365
361
|
});
|
366
|
-
this._createAssignmentTargetFlowNodes(node.name, /* walkTargets */ false, /* unbound */ false);
|
362
|
+
this._createAssignmentTargetFlowNodes(node.d.name, /* walkTargets */ false, /* unbound */ false);
|
367
363
|
// We'll walk the child nodes in a deferred manner, so don't walk them now.
|
368
364
|
return false;
|
369
365
|
}
|
@@ -372,9 +368,9 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
372
368
|
AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode);
|
373
369
|
// Analyze the parameter defaults in the context of the parent's scope
|
374
370
|
// before we add any names from the function's scope.
|
375
|
-
node.
|
376
|
-
if (param.defaultValue) {
|
377
|
-
this.walk(param.defaultValue);
|
371
|
+
node.d.params.forEach((param) => {
|
372
|
+
if (param.d.defaultValue) {
|
373
|
+
this.walk(param.d.defaultValue);
|
378
374
|
}
|
379
375
|
});
|
380
376
|
this._createNewScope(2 /* ScopeType.Function */, this._getNonClassParentScope(), /* proxyScope */ undefined, () => {
|
@@ -382,9 +378,9 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
382
378
|
this._deferBinding(() => {
|
383
379
|
// Create a start node for the lambda.
|
384
380
|
this._currentFlowNode = this._createStartFlowNode();
|
385
|
-
node.
|
386
|
-
if (paramNode.name) {
|
387
|
-
const symbol = this._bindNameToScope(this._currentScope, paramNode.name);
|
381
|
+
node.d.params.forEach((paramNode) => {
|
382
|
+
if (paramNode.d.name) {
|
383
|
+
const symbol = this._bindNameToScope(this._currentScope, paramNode.d.name);
|
388
384
|
if (symbol) {
|
389
385
|
const paramDeclaration = {
|
390
386
|
type: 2 /* DeclarationType.Parameter */,
|
@@ -395,15 +391,15 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
395
391
|
isInExceptSuite: this._isInExceptSuite,
|
396
392
|
};
|
397
393
|
symbol.addDeclaration(paramDeclaration);
|
398
|
-
AnalyzerNodeInfo.setDeclaration(paramNode.name, paramDeclaration);
|
394
|
+
AnalyzerNodeInfo.setDeclaration(paramNode.d.name, paramDeclaration);
|
399
395
|
}
|
400
|
-
this._createFlowAssignment(paramNode.name);
|
401
|
-
this.walk(paramNode.name);
|
396
|
+
this._createFlowAssignment(paramNode.d.name);
|
397
|
+
this.walk(paramNode.d.name);
|
402
398
|
AnalyzerNodeInfo.setFlowNode(paramNode, this._currentFlowNode);
|
403
399
|
}
|
404
400
|
});
|
405
401
|
// Walk the expression that make up the lambda body.
|
406
|
-
this.walk(node.
|
402
|
+
this.walk(node.d.expr);
|
407
403
|
AnalyzerNodeInfo.setCodeFlowExpressions(node, this._currentScopeCodeFlowExpressions);
|
408
404
|
});
|
409
405
|
});
|
@@ -413,7 +409,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
413
409
|
visitCall(node) {
|
414
410
|
var _a, _b;
|
415
411
|
this._disableTrueFalseTargets(() => {
|
416
|
-
this.walk(node.
|
412
|
+
this.walk(node.d.leftExpr);
|
417
413
|
const sortedArgs = ParseTreeUtils.getArgumentsByRuntimeOrder(node);
|
418
414
|
sortedArgs.forEach((argNode) => {
|
419
415
|
if (this._currentFlowNode) {
|
@@ -437,31 +433,31 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
437
433
|
}
|
438
434
|
// Is this an manipulation of dunder all?
|
439
435
|
if (this._currentScope.type === 4 /* ScopeType.Module */ &&
|
440
|
-
node.
|
441
|
-
node.
|
442
|
-
node.
|
436
|
+
node.d.leftExpr.nodeType === 35 /* ParseNodeType.MemberAccess */ &&
|
437
|
+
node.d.leftExpr.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ &&
|
438
|
+
node.d.leftExpr.d.leftExpr.d.value === '__all__') {
|
443
439
|
let emitDunderAllWarning = true;
|
444
440
|
// Is this a call to "__all__.extend()"?
|
445
|
-
if (node.
|
446
|
-
const argExpr = node.
|
441
|
+
if (node.d.leftExpr.d.member.d.value === 'extend' && node.d.args.length === 1) {
|
442
|
+
const argExpr = node.d.args[0].d.valueExpr;
|
447
443
|
// Is this a call to "__all__.extend([<list>])"?
|
448
444
|
if (argExpr.nodeType === 34 /* ParseNodeType.List */) {
|
449
|
-
argExpr.
|
445
|
+
argExpr.d.items.forEach((listEntryNode) => {
|
450
446
|
var _a, _b;
|
451
447
|
if (listEntryNode.nodeType === 48 /* ParseNodeType.StringList */ &&
|
452
|
-
listEntryNode.strings.length === 1 &&
|
453
|
-
listEntryNode.strings[0].nodeType === 49 /* ParseNodeType.String */) {
|
454
|
-
(_a = this._dunderAllNames) === null || _a === void 0 ? void 0 : _a.push(listEntryNode.strings[0].value);
|
455
|
-
(_b = this._dunderAllStringNodes) === null || _b === void 0 ? void 0 : _b.push(listEntryNode.strings[0]);
|
448
|
+
listEntryNode.d.strings.length === 1 &&
|
449
|
+
listEntryNode.d.strings[0].nodeType === 49 /* ParseNodeType.String */) {
|
450
|
+
(_a = this._dunderAllNames) === null || _a === void 0 ? void 0 : _a.push(listEntryNode.d.strings[0].d.value);
|
451
|
+
(_b = this._dunderAllStringNodes) === null || _b === void 0 ? void 0 : _b.push(listEntryNode.d.strings[0]);
|
456
452
|
emitDunderAllWarning = false;
|
457
453
|
}
|
458
454
|
});
|
459
455
|
}
|
460
456
|
else if (argExpr.nodeType === 35 /* ParseNodeType.MemberAccess */ &&
|
461
|
-
argExpr.
|
462
|
-
argExpr.
|
457
|
+
argExpr.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ &&
|
458
|
+
argExpr.d.member.d.value === '__all__') {
|
463
459
|
// Is this a call to "__all__.extend(<mod>.__all__)"?
|
464
|
-
const namesToAdd = this._getDunderAllNamesFromImport(argExpr.
|
460
|
+
const namesToAdd = this._getDunderAllNamesFromImport(argExpr.d.leftExpr.d.value);
|
465
461
|
if (namesToAdd && namesToAdd.length > 0) {
|
466
462
|
namesToAdd.forEach((name) => {
|
467
463
|
var _a;
|
@@ -471,26 +467,26 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
471
467
|
}
|
472
468
|
}
|
473
469
|
}
|
474
|
-
else if (node.
|
470
|
+
else if (node.d.leftExpr.d.member.d.value === 'remove' && node.d.args.length === 1) {
|
475
471
|
// Is this a call to "__all__.remove()"?
|
476
|
-
const argExpr = node.
|
472
|
+
const argExpr = node.d.args[0].d.valueExpr;
|
477
473
|
if (argExpr.nodeType === 48 /* ParseNodeType.StringList */ &&
|
478
|
-
argExpr.strings.length === 1 &&
|
479
|
-
argExpr.strings[0].nodeType === 49 /* ParseNodeType.String */ &&
|
474
|
+
argExpr.d.strings.length === 1 &&
|
475
|
+
argExpr.d.strings[0].nodeType === 49 /* ParseNodeType.String */ &&
|
480
476
|
this._dunderAllNames) {
|
481
|
-
this._dunderAllNames = this._dunderAllNames.filter((name) => name !== argExpr.strings[0].value);
|
482
|
-
this._dunderAllStringNodes = this._dunderAllStringNodes.filter((node) => node.value !== argExpr.strings[0].value);
|
477
|
+
this._dunderAllNames = this._dunderAllNames.filter((name) => name !== argExpr.d.strings[0].d.value);
|
478
|
+
this._dunderAllStringNodes = this._dunderAllStringNodes.filter((node) => node.d.value !== argExpr.d.strings[0].d.value);
|
483
479
|
emitDunderAllWarning = false;
|
484
480
|
}
|
485
481
|
}
|
486
|
-
else if (node.
|
482
|
+
else if (node.d.leftExpr.d.member.d.value === 'append' && node.d.args.length === 1) {
|
487
483
|
// Is this a call to "__all__.append()"?
|
488
|
-
const argExpr = node.
|
484
|
+
const argExpr = node.d.args[0].d.valueExpr;
|
489
485
|
if (argExpr.nodeType === 48 /* ParseNodeType.StringList */ &&
|
490
|
-
argExpr.strings.length === 1 &&
|
491
|
-
argExpr.strings[0].nodeType === 49 /* ParseNodeType.String */) {
|
492
|
-
(_a = this._dunderAllNames) === null || _a === void 0 ? void 0 : _a.push(argExpr.strings[0].value);
|
493
|
-
(_b = this._dunderAllStringNodes) === null || _b === void 0 ? void 0 : _b.push(argExpr.strings[0]);
|
486
|
+
argExpr.d.strings.length === 1 &&
|
487
|
+
argExpr.d.strings[0].nodeType === 49 /* ParseNodeType.String */) {
|
488
|
+
(_a = this._dunderAllNames) === null || _a === void 0 ? void 0 : _a.push(argExpr.d.strings[0].d.value);
|
489
|
+
(_b = this._dunderAllStringNodes) === null || _b === void 0 ? void 0 : _b.push(argExpr.d.strings[0]);
|
494
490
|
emitDunderAllWarning = false;
|
495
491
|
}
|
496
492
|
}
|
@@ -503,15 +499,15 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
503
499
|
}
|
504
500
|
visitTypeParameterList(node) {
|
505
501
|
const typeParamScope = new scope_1.Scope(0 /* ScopeType.TypeParameter */, this._getNonClassParentScope(), this._currentScope);
|
506
|
-
node.
|
507
|
-
if (param.
|
508
|
-
this.walk(param.
|
502
|
+
node.d.params.forEach((param) => {
|
503
|
+
if (param.d.boundExpr) {
|
504
|
+
this.walk(param.d.boundExpr);
|
509
505
|
}
|
510
506
|
});
|
511
507
|
const typeParamsSeen = new Set();
|
512
|
-
node.
|
513
|
-
const name = param.name;
|
514
|
-
const symbol = typeParamScope.addSymbol(name.value, 0 /* SymbolFlags.None */);
|
508
|
+
node.d.params.forEach((param) => {
|
509
|
+
const name = param.d.name;
|
510
|
+
const symbol = typeParamScope.addSymbol(name.d.value, 0 /* SymbolFlags.None */);
|
515
511
|
const paramDeclaration = {
|
516
512
|
type: 3 /* DeclarationType.TypeParameter */,
|
517
513
|
node: param,
|
@@ -522,48 +518,48 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
522
518
|
};
|
523
519
|
symbol.addDeclaration(paramDeclaration);
|
524
520
|
AnalyzerNodeInfo.setDeclaration(name, paramDeclaration);
|
525
|
-
if (typeParamsSeen.has(name.value)) {
|
526
|
-
this._addSyntaxError(localize_1.LocMessage.typeParameterExistingTypeParameter().format({ name: name.value }), name);
|
521
|
+
if (typeParamsSeen.has(name.d.value)) {
|
522
|
+
this._addSyntaxError(localize_1.LocMessage.typeParameterExistingTypeParameter().format({ name: name.d.value }), name);
|
527
523
|
}
|
528
524
|
else {
|
529
|
-
typeParamsSeen.add(name.value);
|
525
|
+
typeParamsSeen.add(name.d.value);
|
530
526
|
}
|
531
527
|
});
|
532
|
-
node.
|
533
|
-
if (param.
|
534
|
-
this.walk(param.
|
528
|
+
node.d.params.forEach((param) => {
|
529
|
+
if (param.d.defaultExpr) {
|
530
|
+
this.walk(param.d.defaultExpr);
|
535
531
|
}
|
536
532
|
});
|
537
533
|
AnalyzerNodeInfo.setScope(node, typeParamScope);
|
538
534
|
return false;
|
539
535
|
}
|
540
536
|
visitTypeAlias(node) {
|
541
|
-
this._bindNameToScope(this._currentScope, node.name);
|
542
|
-
this.walk(node.name);
|
537
|
+
this._bindNameToScope(this._currentScope, node.d.name);
|
538
|
+
this.walk(node.d.name);
|
543
539
|
let typeParamScope;
|
544
|
-
if (node.
|
545
|
-
this.walk(node.
|
546
|
-
typeParamScope = AnalyzerNodeInfo.getScope(node.
|
540
|
+
if (node.d.typeParams) {
|
541
|
+
this.walk(node.d.typeParams);
|
542
|
+
typeParamScope = AnalyzerNodeInfo.getScope(node.d.typeParams);
|
547
543
|
}
|
548
544
|
const typeAliasDeclaration = {
|
549
545
|
type: 4 /* DeclarationType.TypeAlias */,
|
550
546
|
node,
|
551
547
|
uri: this._fileInfo.fileUri,
|
552
|
-
range: (0, positionUtils_1.convertTextRangeToRange)(node.name, this._fileInfo.lines),
|
548
|
+
range: (0, positionUtils_1.convertTextRangeToRange)(node.d.name, this._fileInfo.lines),
|
553
549
|
moduleName: this._fileInfo.moduleName,
|
554
550
|
isInExceptSuite: this._isInExceptSuite,
|
555
|
-
docString: this._getVariableDocString(node.
|
551
|
+
docString: this._getVariableDocString(node.d.expr),
|
556
552
|
};
|
557
|
-
const symbol = this._bindNameToScope(this._currentScope, node.name);
|
553
|
+
const symbol = this._bindNameToScope(this._currentScope, node.d.name);
|
558
554
|
if (symbol) {
|
559
555
|
symbol.addDeclaration(typeAliasDeclaration);
|
560
556
|
}
|
561
557
|
// Stash the declaration in the parse node for later access.
|
562
558
|
AnalyzerNodeInfo.setDeclaration(node, typeAliasDeclaration);
|
563
|
-
this._createAssignmentTargetFlowNodes(node.name, /* walkTargets */ true, /* unbound */ false);
|
559
|
+
this._createAssignmentTargetFlowNodes(node.d.name, /* walkTargets */ true, /* unbound */ false);
|
564
560
|
const prevScope = this._currentScope;
|
565
561
|
this._currentScope = typeParamScope !== null && typeParamScope !== void 0 ? typeParamScope : this._currentScope;
|
566
|
-
this.walk(node.
|
562
|
+
this.walk(node.d.expr);
|
567
563
|
this._currentScope = prevScope;
|
568
564
|
return false;
|
569
565
|
}
|
@@ -571,36 +567,36 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
571
567
|
if (this._handleTypingStubAssignmentOrAnnotation(node)) {
|
572
568
|
return false;
|
573
569
|
}
|
574
|
-
this._bindPossibleTupleNamedTarget(node.
|
575
|
-
if (node.
|
576
|
-
this.walk(node.
|
577
|
-
this._addTypeDeclarationForVariable(node.
|
570
|
+
this._bindPossibleTupleNamedTarget(node.d.leftExpr);
|
571
|
+
if (node.d.annotationComment) {
|
572
|
+
this.walk(node.d.annotationComment);
|
573
|
+
this._addTypeDeclarationForVariable(node.d.leftExpr, node.d.annotationComment);
|
578
574
|
}
|
579
|
-
if (node.
|
580
|
-
this._addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.annotationNotSupported(), node.
|
575
|
+
if (node.d.chainedAnnotationComment) {
|
576
|
+
this._addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.annotationNotSupported(), node.d.chainedAnnotationComment);
|
581
577
|
}
|
582
578
|
// If the assignment target base expression is potentially a
|
583
579
|
// TypedDict, add the base expression to the flow expressions set
|
584
580
|
// to accommodate TypedDict type narrowing.
|
585
|
-
if (node.
|
586
|
-
const target = node.
|
587
|
-
if (target.items.length === 1 &&
|
588
|
-
!target.trailingComma &&
|
589
|
-
target.items[0].
|
590
|
-
if ((0, codeFlowTypes_1.isCodeFlowSupportedForReference)(target.
|
591
|
-
const baseExprReferenceKey = (0, codeFlowTypes_1.createKeyForReference)(target.
|
581
|
+
if (node.d.leftExpr.nodeType === 27 /* ParseNodeType.Index */) {
|
582
|
+
const target = node.d.leftExpr;
|
583
|
+
if (target.d.items.length === 1 &&
|
584
|
+
!target.d.trailingComma &&
|
585
|
+
target.d.items[0].d.valueExpr.nodeType === 48 /* ParseNodeType.StringList */) {
|
586
|
+
if ((0, codeFlowTypes_1.isCodeFlowSupportedForReference)(target.d.leftExpr)) {
|
587
|
+
const baseExprReferenceKey = (0, codeFlowTypes_1.createKeyForReference)(target.d.leftExpr);
|
592
588
|
this._currentScopeCodeFlowExpressions.add(baseExprReferenceKey);
|
593
589
|
}
|
594
590
|
}
|
595
591
|
}
|
596
|
-
this.walk(node.
|
592
|
+
this.walk(node.d.rightExpr);
|
597
593
|
let isPossibleTypeAlias = true;
|
598
594
|
if (ParseTreeUtils.getEnclosingFunction(node)) {
|
599
595
|
// We will assume that type aliases are defined only at the module level
|
600
596
|
// or as class variables, not as local variables within a function.
|
601
597
|
isPossibleTypeAlias = false;
|
602
598
|
}
|
603
|
-
else if (node.
|
599
|
+
else if (node.d.rightExpr.nodeType === 9 /* ParseNodeType.Call */ && this._fileInfo.isTypingStubFile) {
|
604
600
|
// Some special built-in types defined in typing.pyi use
|
605
601
|
// assignments of the form List = _Alias(). We don't want to
|
606
602
|
// treat these as type aliases.
|
@@ -610,25 +606,25 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
610
606
|
// Assume that it's not a type alias if it's within a loop.
|
611
607
|
isPossibleTypeAlias = false;
|
612
608
|
}
|
613
|
-
this._addInferredTypeAssignmentForVariable(node.
|
609
|
+
this._addInferredTypeAssignmentForVariable(node.d.leftExpr, node.d.rightExpr, isPossibleTypeAlias);
|
614
610
|
// If we didn't create assignment target flow nodes above, do so now.
|
615
|
-
this._createAssignmentTargetFlowNodes(node.
|
611
|
+
this._createAssignmentTargetFlowNodes(node.d.leftExpr, /* walkTargets */ true, /* unbound */ false);
|
616
612
|
// Is this an assignment to dunder all?
|
617
613
|
if (this._currentScope.type === 4 /* ScopeType.Module */) {
|
618
|
-
if ((node.
|
619
|
-
(node.
|
620
|
-
node.
|
621
|
-
node.
|
622
|
-
const expr = node.
|
614
|
+
if ((node.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ && node.d.leftExpr.d.value === '__all__') ||
|
615
|
+
(node.d.leftExpr.nodeType === 54 /* ParseNodeType.TypeAnnotation */ &&
|
616
|
+
node.d.leftExpr.d.valueExpr.nodeType === 38 /* ParseNodeType.Name */ &&
|
617
|
+
node.d.leftExpr.d.valueExpr.d.value === '__all__')) {
|
618
|
+
const expr = node.d.rightExpr;
|
623
619
|
this._dunderAllNames = [];
|
624
620
|
let emitDunderAllWarning = false;
|
625
621
|
if (expr.nodeType === 34 /* ParseNodeType.List */) {
|
626
|
-
expr.
|
622
|
+
expr.d.items.forEach((listEntryNode) => {
|
627
623
|
if (listEntryNode.nodeType === 48 /* ParseNodeType.StringList */ &&
|
628
|
-
listEntryNode.strings.length === 1 &&
|
629
|
-
listEntryNode.strings[0].nodeType === 49 /* ParseNodeType.String */) {
|
630
|
-
this._dunderAllNames.push(listEntryNode.strings[0].value);
|
631
|
-
this._dunderAllStringNodes.push(listEntryNode.strings[0]);
|
624
|
+
listEntryNode.d.strings.length === 1 &&
|
625
|
+
listEntryNode.d.strings[0].nodeType === 49 /* ParseNodeType.String */) {
|
626
|
+
this._dunderAllNames.push(listEntryNode.d.strings[0].d.value);
|
627
|
+
this._dunderAllStringNodes.push(listEntryNode.d.strings[0]);
|
632
628
|
}
|
633
629
|
else {
|
634
630
|
emitDunderAllWarning = true;
|
@@ -636,12 +632,12 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
636
632
|
});
|
637
633
|
}
|
638
634
|
else if (expr.nodeType === 52 /* ParseNodeType.Tuple */) {
|
639
|
-
expr.
|
635
|
+
expr.d.items.forEach((tupleEntryNode) => {
|
640
636
|
if (tupleEntryNode.nodeType === 48 /* ParseNodeType.StringList */ &&
|
641
|
-
tupleEntryNode.strings.length === 1 &&
|
642
|
-
tupleEntryNode.strings[0].nodeType === 49 /* ParseNodeType.String */) {
|
643
|
-
this._dunderAllNames.push(tupleEntryNode.strings[0].value);
|
644
|
-
this._dunderAllStringNodes.push(tupleEntryNode.strings[0]);
|
637
|
+
tupleEntryNode.d.strings.length === 1 &&
|
638
|
+
tupleEntryNode.d.strings[0].nodeType === 49 /* ParseNodeType.String */) {
|
639
|
+
this._dunderAllNames.push(tupleEntryNode.d.strings[0].d.value);
|
640
|
+
this._dunderAllStringNodes.push(tupleEntryNode.d.strings[0]);
|
645
641
|
}
|
646
642
|
else {
|
647
643
|
emitDunderAllWarning = true;
|
@@ -659,21 +655,21 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
659
655
|
}
|
660
656
|
// Is this an assignment to dunder slots?
|
661
657
|
if (this._currentScope.type === 3 /* ScopeType.Class */) {
|
662
|
-
if ((node.
|
663
|
-
(node.
|
664
|
-
node.
|
665
|
-
node.
|
666
|
-
const expr = node.
|
658
|
+
if ((node.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ && node.d.leftExpr.d.value === '__slots__') ||
|
659
|
+
(node.d.leftExpr.nodeType === 54 /* ParseNodeType.TypeAnnotation */ &&
|
660
|
+
node.d.leftExpr.d.valueExpr.nodeType === 38 /* ParseNodeType.Name */ &&
|
661
|
+
node.d.leftExpr.d.valueExpr.d.value === '__slots__')) {
|
662
|
+
const expr = node.d.rightExpr;
|
667
663
|
this._dunderSlotsEntries = [];
|
668
664
|
let isExpressionUnderstood = true;
|
669
665
|
if (expr.nodeType === 48 /* ParseNodeType.StringList */) {
|
670
666
|
this._dunderSlotsEntries.push(expr);
|
671
667
|
}
|
672
668
|
else if (expr.nodeType === 34 /* ParseNodeType.List */) {
|
673
|
-
expr.
|
669
|
+
expr.d.items.forEach((listEntryNode) => {
|
674
670
|
if (listEntryNode.nodeType === 48 /* ParseNodeType.StringList */ &&
|
675
|
-
listEntryNode.strings.length === 1 &&
|
676
|
-
listEntryNode.strings[0].nodeType === 49 /* ParseNodeType.String */) {
|
671
|
+
listEntryNode.d.strings.length === 1 &&
|
672
|
+
listEntryNode.d.strings[0].nodeType === 49 /* ParseNodeType.String */) {
|
677
673
|
this._dunderSlotsEntries.push(listEntryNode);
|
678
674
|
}
|
679
675
|
else {
|
@@ -682,10 +678,10 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
682
678
|
});
|
683
679
|
}
|
684
680
|
else if (expr.nodeType === 52 /* ParseNodeType.Tuple */) {
|
685
|
-
expr.
|
681
|
+
expr.d.items.forEach((tupleEntryNode) => {
|
686
682
|
if (tupleEntryNode.nodeType === 48 /* ParseNodeType.StringList */ &&
|
687
|
-
tupleEntryNode.strings.length === 1 &&
|
688
|
-
tupleEntryNode.strings[0].nodeType === 49 /* ParseNodeType.String */) {
|
683
|
+
tupleEntryNode.d.strings.length === 1 &&
|
684
|
+
tupleEntryNode.d.strings[0].nodeType === 49 /* ParseNodeType.String */) {
|
689
685
|
this._dunderSlotsEntries.push(tupleEntryNode);
|
690
686
|
}
|
691
687
|
else {
|
@@ -708,12 +704,12 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
708
704
|
// expression is located within an if/else conditional.
|
709
705
|
this._disableTrueFalseTargets(() => {
|
710
706
|
// Evaluate the operand expression.
|
711
|
-
this.walk(node.
|
707
|
+
this.walk(node.d.rightExpr);
|
712
708
|
});
|
713
709
|
const evaluationNode = ParseTreeUtils.getEvaluationNodeForAssignmentExpression(node);
|
714
710
|
if (!evaluationNode) {
|
715
711
|
this._addSyntaxError(localize_1.LocMessage.assignmentExprContext(), node);
|
716
|
-
this.walk(node.name);
|
712
|
+
this.walk(node.d.name);
|
717
713
|
}
|
718
714
|
else {
|
719
715
|
// Bind the name to the containing scope. This special logic is required
|
@@ -726,50 +722,50 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
726
722
|
// expression.
|
727
723
|
let curScope = this._currentScope;
|
728
724
|
while (curScope && curScope !== containerScope) {
|
729
|
-
const localSymbol = curScope.lookUpSymbol(node.name.value);
|
725
|
+
const localSymbol = curScope.lookUpSymbol(node.d.name.d.value);
|
730
726
|
if (localSymbol) {
|
731
|
-
this._addSyntaxError(localize_1.LocMessage.assignmentExprComprehension().format({ name: node.name.value }), node.name);
|
727
|
+
this._addSyntaxError(localize_1.LocMessage.assignmentExprComprehension().format({ name: node.d.name.d.value }), node.d.name);
|
732
728
|
break;
|
733
729
|
}
|
734
730
|
curScope = curScope.parent;
|
735
731
|
}
|
736
|
-
this._bindNameToScope(containerScope, node.name);
|
737
|
-
this._addInferredTypeAssignmentForVariable(node.name, node.
|
738
|
-
this._createAssignmentTargetFlowNodes(node.name, /* walkTargets */ true, /* unbound */ false);
|
732
|
+
this._bindNameToScope(containerScope, node.d.name);
|
733
|
+
this._addInferredTypeAssignmentForVariable(node.d.name, node.d.rightExpr);
|
734
|
+
this._createAssignmentTargetFlowNodes(node.d.name, /* walkTargets */ true, /* unbound */ false);
|
739
735
|
}
|
740
736
|
return false;
|
741
737
|
}
|
742
738
|
visitAugmentedAssignment(node) {
|
743
|
-
this.walk(node.
|
744
|
-
this.walk(node.
|
745
|
-
this._bindPossibleTupleNamedTarget(node.
|
746
|
-
this._createAssignmentTargetFlowNodes(node.
|
739
|
+
this.walk(node.d.leftExpr);
|
740
|
+
this.walk(node.d.rightExpr);
|
741
|
+
this._bindPossibleTupleNamedTarget(node.d.destExpr);
|
742
|
+
this._createAssignmentTargetFlowNodes(node.d.destExpr, /* walkTargets */ false, /* unbound */ false);
|
747
743
|
// Is this an assignment to dunder all of the form
|
748
744
|
// __all__ += <expression>?
|
749
|
-
if (node.operator === 1 /* OperatorType.AddEqual */ &&
|
745
|
+
if (node.d.operator === 1 /* OperatorType.AddEqual */ &&
|
750
746
|
this._currentScope.type === 4 /* ScopeType.Module */ &&
|
751
|
-
node.
|
752
|
-
node.
|
753
|
-
const expr = node.
|
747
|
+
node.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ &&
|
748
|
+
node.d.leftExpr.d.value === '__all__') {
|
749
|
+
const expr = node.d.rightExpr;
|
754
750
|
let emitDunderAllWarning = true;
|
755
751
|
if (expr.nodeType === 34 /* ParseNodeType.List */) {
|
756
752
|
// Is this the form __all__ += ["a", "b"]?
|
757
|
-
expr.
|
753
|
+
expr.d.items.forEach((listEntryNode) => {
|
758
754
|
var _a;
|
759
755
|
if (listEntryNode.nodeType === 48 /* ParseNodeType.StringList */ &&
|
760
|
-
listEntryNode.strings.length === 1 &&
|
761
|
-
listEntryNode.strings[0].nodeType === 49 /* ParseNodeType.String */) {
|
762
|
-
(_a = this._dunderAllNames) === null || _a === void 0 ? void 0 : _a.push(listEntryNode.strings[0].value);
|
763
|
-
this._dunderAllStringNodes.push(listEntryNode.strings[0]);
|
756
|
+
listEntryNode.d.strings.length === 1 &&
|
757
|
+
listEntryNode.d.strings[0].nodeType === 49 /* ParseNodeType.String */) {
|
758
|
+
(_a = this._dunderAllNames) === null || _a === void 0 ? void 0 : _a.push(listEntryNode.d.strings[0].d.value);
|
759
|
+
this._dunderAllStringNodes.push(listEntryNode.d.strings[0]);
|
764
760
|
}
|
765
761
|
});
|
766
762
|
emitDunderAllWarning = false;
|
767
763
|
}
|
768
764
|
else if (expr.nodeType === 35 /* ParseNodeType.MemberAccess */ &&
|
769
|
-
expr.
|
770
|
-
expr.
|
765
|
+
expr.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ &&
|
766
|
+
expr.d.member.d.value === '__all__') {
|
771
767
|
// Is this using the form "__all__ += <mod>.__all__"?
|
772
|
-
const namesToAdd = this._getDunderAllNamesFromImport(expr.
|
768
|
+
const namesToAdd = this._getDunderAllNamesFromImport(expr.d.leftExpr.d.value);
|
773
769
|
if (namesToAdd) {
|
774
770
|
namesToAdd.forEach((name) => {
|
775
771
|
var _a;
|
@@ -786,7 +782,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
786
782
|
return false;
|
787
783
|
}
|
788
784
|
visitDel(node) {
|
789
|
-
node.
|
785
|
+
node.d.targets.forEach((expr) => {
|
790
786
|
this._bindPossibleTupleNamedTarget(expr);
|
791
787
|
this.walk(expr);
|
792
788
|
this._createAssignmentTargetFlowNodes(expr, /* walkTargets */ false, /* unbound */ true);
|
@@ -803,32 +799,32 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
803
799
|
const bindVariableBeforeAnnotationEvaluation = ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 3 /* ParseNodeType.Assignment */ &&
|
804
800
|
ParseTreeUtils.getEnclosingClass(node, /* stopAtFunction */ true) !== undefined;
|
805
801
|
if (!bindVariableBeforeAnnotationEvaluation) {
|
806
|
-
this.walk(node.
|
802
|
+
this.walk(node.d.annotation);
|
807
803
|
}
|
808
804
|
this._createVariableAnnotationFlowNode();
|
809
|
-
this._bindPossibleTupleNamedTarget(node.
|
810
|
-
this._addTypeDeclarationForVariable(node.
|
805
|
+
this._bindPossibleTupleNamedTarget(node.d.valueExpr);
|
806
|
+
this._addTypeDeclarationForVariable(node.d.valueExpr, node.d.annotation);
|
811
807
|
if (bindVariableBeforeAnnotationEvaluation) {
|
812
|
-
this.walk(node.
|
808
|
+
this.walk(node.d.annotation);
|
813
809
|
}
|
814
810
|
// For type annotations that are not part of assignments (e.g. simple variable
|
815
811
|
// annotations), we need to populate the reference map. Otherwise the type
|
816
812
|
// analyzer's code flow engine won't run and detect cases where the variable
|
817
813
|
// is unbound.
|
818
814
|
const expressionList = [];
|
819
|
-
if (this._isNarrowingExpression(node.
|
815
|
+
if (this._isNarrowingExpression(node.d.valueExpr, expressionList)) {
|
820
816
|
expressionList.forEach((expr) => {
|
821
817
|
const referenceKey = (0, codeFlowTypes_1.createKeyForReference)(expr);
|
822
818
|
this._currentScopeCodeFlowExpressions.add(referenceKey);
|
823
819
|
});
|
824
820
|
}
|
825
|
-
this.walk(node.
|
821
|
+
this.walk(node.d.valueExpr);
|
826
822
|
return false;
|
827
823
|
}
|
828
824
|
visitFor(node) {
|
829
|
-
this._bindPossibleTupleNamedTarget(node.
|
830
|
-
this._addInferredTypeAssignmentForVariable(node.
|
831
|
-
this.walk(node.
|
825
|
+
this._bindPossibleTupleNamedTarget(node.d.targetExpr);
|
826
|
+
this._addInferredTypeAssignmentForVariable(node.d.targetExpr, node);
|
827
|
+
this.walk(node.d.iterableExpr);
|
832
828
|
const preForLabel = this._createLoopLabel();
|
833
829
|
const preElseLabel = this._createBranchLabel();
|
834
830
|
const postForLabel = this._createBranchLabel();
|
@@ -836,10 +832,10 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
836
832
|
this._currentFlowNode = preForLabel;
|
837
833
|
this._addAntecedent(preElseLabel, this._currentFlowNode);
|
838
834
|
const targetExpressions = this._trackCodeFlowExpressions(() => {
|
839
|
-
this._createAssignmentTargetFlowNodes(node.
|
835
|
+
this._createAssignmentTargetFlowNodes(node.d.targetExpr, /* walkTargets */ true, /* unbound */ false);
|
840
836
|
});
|
841
837
|
this._bindLoopStatement(preForLabel, postForLabel, () => {
|
842
|
-
this.walk(node.forSuite);
|
838
|
+
this.walk(node.d.forSuite);
|
843
839
|
this._addAntecedent(preForLabel, this._currentFlowNode);
|
844
840
|
// Add any target expressions since they are modified in the loop.
|
845
841
|
targetExpressions.forEach((value) => {
|
@@ -848,17 +844,17 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
848
844
|
});
|
849
845
|
});
|
850
846
|
this._currentFlowNode = this._finishFlowLabel(preElseLabel);
|
851
|
-
if (node.elseSuite) {
|
852
|
-
this.walk(node.elseSuite);
|
847
|
+
if (node.d.elseSuite) {
|
848
|
+
this.walk(node.d.elseSuite);
|
853
849
|
}
|
854
850
|
this._addAntecedent(postForLabel, this._currentFlowNode);
|
855
851
|
this._currentFlowNode = this._finishFlowLabel(postForLabel);
|
856
852
|
// Async for is not allowed outside of an async function
|
857
853
|
// unless we're in ipython mode.
|
858
|
-
if (node.asyncToken && !this._fileInfo.ipythonMode) {
|
854
|
+
if (node.d.asyncToken && !this._fileInfo.ipythonMode) {
|
859
855
|
const enclosingFunction = ParseTreeUtils.getEnclosingFunction(node);
|
860
|
-
if (!enclosingFunction || !enclosingFunction.isAsync) {
|
861
|
-
this._addSyntaxError(localize_1.LocMessage.asyncNotInAsyncFunction(), node.asyncToken);
|
856
|
+
if (!enclosingFunction || !enclosingFunction.d.isAsync) {
|
857
|
+
this._addSyntaxError(localize_1.LocMessage.asyncNotInAsyncFunction(), node.d.asyncToken);
|
862
858
|
}
|
863
859
|
}
|
864
860
|
return false;
|
@@ -886,8 +882,8 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
886
882
|
}
|
887
883
|
this._targetFunctionDeclaration.returnStatements.push(node);
|
888
884
|
}
|
889
|
-
if (node.
|
890
|
-
this.walk(node.
|
885
|
+
if (node.d.expr) {
|
886
|
+
this.walk(node.d.expr);
|
891
887
|
}
|
892
888
|
AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode);
|
893
889
|
if (this._currentReturnTarget) {
|
@@ -914,7 +910,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
914
910
|
return false;
|
915
911
|
}
|
916
912
|
visitMemberAccess(node) {
|
917
|
-
this.walk(node.
|
913
|
+
this.walk(node.d.leftExpr);
|
918
914
|
AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode);
|
919
915
|
return false;
|
920
916
|
}
|
@@ -924,13 +920,13 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
924
920
|
}
|
925
921
|
visitIndex(node) {
|
926
922
|
AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode);
|
927
|
-
this.walk(node.
|
923
|
+
this.walk(node.d.leftExpr);
|
928
924
|
// If we're within an 'Annotated' type annotation, set the flag.
|
929
925
|
const wasInAnnotatedAnnotation = this._isInAnnotatedAnnotation;
|
930
|
-
if (this._isTypingAnnotation(node.
|
926
|
+
if (this._isTypingAnnotation(node.d.leftExpr, 'Annotated')) {
|
931
927
|
this._isInAnnotatedAnnotation = true;
|
932
928
|
}
|
933
|
-
node.items.forEach((argNode) => {
|
929
|
+
node.d.items.forEach((argNode) => {
|
934
930
|
this.walk(argNode);
|
935
931
|
});
|
936
932
|
this._isInAnnotatedAnnotation = wasInAnnotatedAnnotation;
|
@@ -944,23 +940,23 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
944
940
|
postIfLabel.affectedExpressions = this._trackCodeFlowExpressions(() => {
|
945
941
|
// Determine if the test condition is always true or always false. If so,
|
946
942
|
// we can treat either the then or the else clause as unconditional.
|
947
|
-
const constExprValue = StaticExpressions.evaluateStaticBoolLikeExpression(node.
|
948
|
-
this._bindConditional(node.
|
943
|
+
const constExprValue = StaticExpressions.evaluateStaticBoolLikeExpression(node.d.testExpr, this._fileInfo.executionEnvironment, this._fileInfo.definedConstants, this._typingImportAliases, this._sysImportAliases);
|
944
|
+
this._bindConditional(node.d.testExpr, thenLabel, elseLabel);
|
949
945
|
// Handle the if clause.
|
950
946
|
this._currentFlowNode =
|
951
947
|
constExprValue === false ? Binder._unreachableFlowNode : this._finishFlowLabel(thenLabel);
|
952
|
-
this.walk(node.ifSuite);
|
948
|
+
this.walk(node.d.ifSuite);
|
953
949
|
this._addAntecedent(postIfLabel, this._currentFlowNode);
|
954
950
|
// Now handle the else clause if it's present. If there
|
955
951
|
// are chained "else if" statements, they'll be handled
|
956
952
|
// recursively here.
|
957
953
|
this._currentFlowNode =
|
958
954
|
constExprValue === true ? Binder._unreachableFlowNode : this._finishFlowLabel(elseLabel);
|
959
|
-
if (node.elseSuite) {
|
960
|
-
this.walk(node.elseSuite);
|
955
|
+
if (node.d.elseSuite) {
|
956
|
+
this.walk(node.d.elseSuite);
|
961
957
|
}
|
962
958
|
else {
|
963
|
-
this._bindNeverCondition(node.
|
959
|
+
this._bindNeverCondition(node.d.testExpr, postIfLabel, /* isPositiveTest */ false);
|
964
960
|
}
|
965
961
|
this._addAntecedent(postIfLabel, this._currentFlowNode);
|
966
962
|
this._currentFlowNode = this._finishFlowLabel(postIfLabel);
|
@@ -973,22 +969,22 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
973
969
|
const postWhileLabel = this._createBranchLabel();
|
974
970
|
// Determine if the test condition is always true or always false. If so,
|
975
971
|
// we can treat either the while or the else clause as unconditional.
|
976
|
-
const constExprValue = StaticExpressions.evaluateStaticBoolLikeExpression(node.
|
972
|
+
const constExprValue = StaticExpressions.evaluateStaticBoolLikeExpression(node.d.testExpr, this._fileInfo.executionEnvironment, this._fileInfo.definedConstants, this._typingImportAliases, this._sysImportAliases);
|
977
973
|
const preLoopLabel = this._createLoopLabel();
|
978
974
|
this._addAntecedent(preLoopLabel, this._currentFlowNode);
|
979
975
|
this._currentFlowNode = preLoopLabel;
|
980
|
-
this._bindConditional(node.
|
976
|
+
this._bindConditional(node.d.testExpr, thenLabel, elseLabel);
|
981
977
|
// Handle the while clause.
|
982
978
|
this._currentFlowNode =
|
983
979
|
constExprValue === false ? Binder._unreachableFlowNode : this._finishFlowLabel(thenLabel);
|
984
980
|
this._bindLoopStatement(preLoopLabel, postWhileLabel, () => {
|
985
|
-
this.walk(node.whileSuite);
|
981
|
+
this.walk(node.d.whileSuite);
|
986
982
|
});
|
987
983
|
this._addAntecedent(preLoopLabel, this._currentFlowNode);
|
988
984
|
this._currentFlowNode =
|
989
985
|
constExprValue === true ? Binder._unreachableFlowNode : this._finishFlowLabel(elseLabel);
|
990
|
-
if (node.elseSuite) {
|
991
|
-
this.walk(node.elseSuite);
|
986
|
+
if (node.d.elseSuite) {
|
987
|
+
this.walk(node.d.elseSuite);
|
992
988
|
}
|
993
989
|
this._addAntecedent(postWhileLabel, this._currentFlowNode);
|
994
990
|
this._currentFlowNode = this._finishFlowLabel(postWhileLabel);
|
@@ -997,45 +993,45 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
997
993
|
visitAssert(node) {
|
998
994
|
const assertTrueLabel = this._createBranchLabel();
|
999
995
|
const assertFalseLabel = this._createBranchLabel();
|
1000
|
-
this._bindConditional(node.
|
1001
|
-
if (node.
|
996
|
+
this._bindConditional(node.d.testExpr, assertTrueLabel, assertFalseLabel);
|
997
|
+
if (node.d.exceptionExpr) {
|
1002
998
|
this._currentFlowNode = this._finishFlowLabel(assertFalseLabel);
|
1003
|
-
this.walk(node.
|
999
|
+
this.walk(node.d.exceptionExpr);
|
1004
1000
|
}
|
1005
1001
|
this._currentFlowNode = this._finishFlowLabel(assertTrueLabel);
|
1006
1002
|
return false;
|
1007
1003
|
}
|
1008
1004
|
visitExcept(node) {
|
1009
|
-
if (node.
|
1010
|
-
this.walk(node.
|
1005
|
+
if (node.d.typeExpr) {
|
1006
|
+
this.walk(node.d.typeExpr);
|
1011
1007
|
}
|
1012
|
-
if (node.name) {
|
1013
|
-
this.walk(node.name);
|
1014
|
-
const symbol = this._bindNameToScope(this._currentScope, node.name);
|
1015
|
-
this._createAssignmentTargetFlowNodes(node.name, /* walkTargets */ true, /* unbound */ false);
|
1008
|
+
if (node.d.name) {
|
1009
|
+
this.walk(node.d.name);
|
1010
|
+
const symbol = this._bindNameToScope(this._currentScope, node.d.name);
|
1011
|
+
this._createAssignmentTargetFlowNodes(node.d.name, /* walkTargets */ true, /* unbound */ false);
|
1016
1012
|
if (symbol) {
|
1017
1013
|
const declaration = {
|
1018
1014
|
type: 1 /* DeclarationType.Variable */,
|
1019
|
-
node: node.name,
|
1020
|
-
isConstant: (0, symbolNameUtils_1.isConstantName)(node.name.value),
|
1015
|
+
node: node.d.name,
|
1016
|
+
isConstant: (0, symbolNameUtils_1.isConstantName)(node.d.name.d.value),
|
1021
1017
|
inferredTypeSource: node,
|
1022
1018
|
uri: this._fileInfo.fileUri,
|
1023
|
-
range: (0, positionUtils_1.convertTextRangeToRange)(node.name, this._fileInfo.lines),
|
1019
|
+
range: (0, positionUtils_1.convertTextRangeToRange)(node.d.name, this._fileInfo.lines),
|
1024
1020
|
moduleName: this._fileInfo.moduleName,
|
1025
1021
|
isInExceptSuite: this._isInExceptSuite,
|
1026
|
-
isExplicitBinding: this._currentScope.getBindingType(node.name.value) !== undefined,
|
1022
|
+
isExplicitBinding: this._currentScope.getBindingType(node.d.name.d.value) !== undefined,
|
1027
1023
|
};
|
1028
1024
|
symbol.addDeclaration(declaration);
|
1029
1025
|
}
|
1030
1026
|
}
|
1031
1027
|
const wasInExceptSuite = this._isInExceptSuite;
|
1032
1028
|
this._isInExceptSuite = true;
|
1033
|
-
this.walk(node.exceptSuite);
|
1029
|
+
this.walk(node.d.exceptSuite);
|
1034
1030
|
this._isInExceptSuite = wasInExceptSuite;
|
1035
|
-
if (node.name) {
|
1031
|
+
if (node.d.name) {
|
1036
1032
|
// The exception name is implicitly unbound at the end of
|
1037
1033
|
// the except block.
|
1038
|
-
this._createFlowAssignment(node.name, /* unbound */ true);
|
1034
|
+
this._createFlowAssignment(node.d.name, /* unbound */ true);
|
1039
1035
|
}
|
1040
1036
|
return false;
|
1041
1037
|
}
|
@@ -1049,14 +1045,14 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1049
1045
|
}
|
1050
1046
|
this._targetFunctionDeclaration.raiseStatements.push(node);
|
1051
1047
|
}
|
1052
|
-
if (node.typeExpression) {
|
1053
|
-
this.walk(node.typeExpression);
|
1048
|
+
if (node.d.typeExpression) {
|
1049
|
+
this.walk(node.d.typeExpression);
|
1054
1050
|
}
|
1055
|
-
if (node.valueExpression) {
|
1056
|
-
this.walk(node.valueExpression);
|
1051
|
+
if (node.d.valueExpression) {
|
1052
|
+
this.walk(node.d.valueExpression);
|
1057
1053
|
}
|
1058
|
-
if (node.tracebackExpression) {
|
1059
|
-
this.walk(node.tracebackExpression);
|
1054
|
+
if (node.d.tracebackExpression) {
|
1055
|
+
this.walk(node.d.tracebackExpression);
|
1060
1056
|
}
|
1061
1057
|
this._finallyTargets.forEach((target) => {
|
1062
1058
|
this._addAntecedent(target, this._currentFlowNode);
|
@@ -1101,7 +1097,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1101
1097
|
// (after finally)
|
1102
1098
|
// Create one flow label for every except clause.
|
1103
1099
|
const preTryFlowNode = this._currentFlowNode;
|
1104
|
-
const curExceptTargets = node.exceptClauses.map(() => this._createBranchLabel());
|
1100
|
+
const curExceptTargets = node.d.exceptClauses.map(() => this._createBranchLabel());
|
1105
1101
|
const preFinallyLabel = this._createBranchLabel(preTryFlowNode);
|
1106
1102
|
let isAfterElseAndExceptsReachable = false;
|
1107
1103
|
// Create a label for all of the return or raise labels that are
|
@@ -1114,12 +1110,12 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1114
1110
|
antecedent: preFinallyReturnOrRaiseLabel,
|
1115
1111
|
};
|
1116
1112
|
preFinallyLabel.affectedExpressions = this._trackCodeFlowExpressions(() => {
|
1117
|
-
if (node.finallySuite) {
|
1113
|
+
if (node.d.finallySuite) {
|
1118
1114
|
this._addAntecedent(preFinallyLabel, preFinallyGate);
|
1119
1115
|
}
|
1120
1116
|
// Add the finally target as an exception target unless there is
|
1121
1117
|
// a "bare" except clause that accepts all exception types.
|
1122
|
-
const hasBareExceptClause = node.exceptClauses.some((except) => !except.
|
1118
|
+
const hasBareExceptClause = node.d.exceptClauses.some((except) => !except.d.typeExpr);
|
1123
1119
|
if (!hasBareExceptClause) {
|
1124
1120
|
curExceptTargets.push(preFinallyReturnOrRaiseLabel);
|
1125
1121
|
}
|
@@ -1134,24 +1130,24 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1134
1130
|
// a single level of finally statements, and we handle most cases
|
1135
1131
|
// involving nesting. Returns or raises within the try/except/raise
|
1136
1132
|
// block will execute the finally target(s).
|
1137
|
-
if (node.finallySuite) {
|
1133
|
+
if (node.d.finallySuite) {
|
1138
1134
|
this._finallyTargets.push(preFinallyReturnOrRaiseLabel);
|
1139
1135
|
}
|
1140
1136
|
// Handle the try block.
|
1141
1137
|
this._useExceptTargets(curExceptTargets, () => {
|
1142
|
-
this.walk(node.trySuite);
|
1138
|
+
this.walk(node.d.trySuite);
|
1143
1139
|
});
|
1144
1140
|
// Handle the else block, which is executed only if
|
1145
1141
|
// execution falls through the try block.
|
1146
|
-
if (node.elseSuite) {
|
1147
|
-
this.walk(node.elseSuite);
|
1142
|
+
if (node.d.elseSuite) {
|
1143
|
+
this.walk(node.d.elseSuite);
|
1148
1144
|
}
|
1149
1145
|
this._addAntecedent(preFinallyLabel, this._currentFlowNode);
|
1150
1146
|
if (!this._isCodeUnreachable()) {
|
1151
1147
|
isAfterElseAndExceptsReachable = true;
|
1152
1148
|
}
|
1153
1149
|
// Handle the except blocks.
|
1154
|
-
node.exceptClauses.forEach((exceptNode, index) => {
|
1150
|
+
node.d.exceptClauses.forEach((exceptNode, index) => {
|
1155
1151
|
this._currentFlowNode = this._finishFlowLabel(curExceptTargets[index]);
|
1156
1152
|
this.walk(exceptNode);
|
1157
1153
|
this._addAntecedent(preFinallyLabel, this._currentFlowNode);
|
@@ -1159,20 +1155,20 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1159
1155
|
isAfterElseAndExceptsReachable = true;
|
1160
1156
|
}
|
1161
1157
|
});
|
1162
|
-
if (node.finallySuite) {
|
1158
|
+
if (node.d.finallySuite) {
|
1163
1159
|
this._finallyTargets.pop();
|
1164
1160
|
}
|
1165
1161
|
// Handle the finally block.
|
1166
1162
|
this._currentFlowNode = this._finishFlowLabel(preFinallyLabel);
|
1167
1163
|
});
|
1168
|
-
if (node.finallySuite) {
|
1169
|
-
this.walk(node.finallySuite);
|
1164
|
+
if (node.d.finallySuite) {
|
1165
|
+
this.walk(node.d.finallySuite);
|
1170
1166
|
// Add a post-finally node at the end. If we traverse this node,
|
1171
1167
|
// we'll set the "ignore" flag in the pre-finally node.
|
1172
1168
|
const postFinallyNode = {
|
1173
1169
|
flags: codeFlowTypes_1.FlowFlags.PostFinally,
|
1174
1170
|
id: this._getUniqueFlowNodeId(),
|
1175
|
-
finallyNode: node.finallySuite,
|
1171
|
+
finallyNode: node.d.finallySuite,
|
1176
1172
|
antecedent: this._currentFlowNode,
|
1177
1173
|
preFinallyGate,
|
1178
1174
|
};
|
@@ -1184,7 +1180,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1184
1180
|
var _a;
|
1185
1181
|
// Make sure this is within an async lambda or function.
|
1186
1182
|
const enclosingFunction = ParseTreeUtils.getEnclosingFunction(node);
|
1187
|
-
if (enclosingFunction === undefined || !enclosingFunction.isAsync) {
|
1183
|
+
if (enclosingFunction === undefined || !enclosingFunction.d.isAsync) {
|
1188
1184
|
if (this._fileInfo.ipythonMode && enclosingFunction === undefined) {
|
1189
1185
|
// Top level await is allowed in ipython mode.
|
1190
1186
|
return true;
|
@@ -1200,8 +1196,8 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1200
1196
|
}
|
1201
1197
|
visitGlobal(node) {
|
1202
1198
|
const globalScope = this._currentScope.getGlobalScope().scope;
|
1203
|
-
node.
|
1204
|
-
const nameValue = name.value;
|
1199
|
+
node.d.targets.forEach((name) => {
|
1200
|
+
const nameValue = name.d.value;
|
1205
1201
|
// Is the binding inconsistent?
|
1206
1202
|
if (this._currentScope.getBindingType(nameValue) === 0 /* NameBindingType.Nonlocal */) {
|
1207
1203
|
this._addSyntaxError(localize_1.LocMessage.nonLocalRedefinition().format({ name: nameValue }), name);
|
@@ -1225,8 +1221,8 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1225
1221
|
this._addSyntaxError(localize_1.LocMessage.nonLocalInModule(), node);
|
1226
1222
|
}
|
1227
1223
|
else {
|
1228
|
-
node.
|
1229
|
-
const nameValue = name.value;
|
1224
|
+
node.d.targets.forEach((name) => {
|
1225
|
+
const nameValue = name.d.value;
|
1230
1226
|
// Is the binding inconsistent?
|
1231
1227
|
if (this._currentScope.getBindingType(nameValue) === 1 /* NameBindingType.Global */) {
|
1232
1228
|
this._addSyntaxError(localize_1.LocMessage.globalRedefinition().format({ name: nameValue }), name);
|
@@ -1248,27 +1244,27 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1248
1244
|
}
|
1249
1245
|
visitImportAs(node) {
|
1250
1246
|
var _a, _b, _c, _d, _e, _f;
|
1251
|
-
if (node.module.nameParts.length > 0) {
|
1252
|
-
const firstNamePartValue = node.module.nameParts[0].value;
|
1247
|
+
if (node.d.module.d.nameParts.length > 0) {
|
1248
|
+
const firstNamePartValue = node.d.module.d.nameParts[0].d.value;
|
1253
1249
|
let symbolName;
|
1254
1250
|
let symbolNameNode;
|
1255
|
-
if (node.alias) {
|
1251
|
+
if (node.d.alias) {
|
1256
1252
|
// The symbol name is defined by the alias.
|
1257
|
-
symbolName = node.alias.value;
|
1258
|
-
symbolNameNode = node.alias;
|
1253
|
+
symbolName = node.d.alias.d.value;
|
1254
|
+
symbolNameNode = node.d.alias;
|
1259
1255
|
}
|
1260
1256
|
else {
|
1261
1257
|
// There was no alias, so we need to use the first element of
|
1262
1258
|
// the name parts as the symbol.
|
1263
1259
|
symbolName = firstNamePartValue;
|
1264
|
-
symbolNameNode = node.module.nameParts[0];
|
1260
|
+
symbolNameNode = node.d.module.d.nameParts[0];
|
1265
1261
|
}
|
1266
1262
|
const symbol = this._bindNameToScope(this._currentScope, symbolNameNode);
|
1267
1263
|
if (symbol &&
|
1268
1264
|
(this._currentScope.type === 4 /* ScopeType.Module */ || this._currentScope.type === 5 /* ScopeType.Builtin */) &&
|
1269
|
-
(!node.alias ||
|
1270
|
-
node.module.nameParts.length !== 1 ||
|
1271
|
-
node.module.nameParts[0].value !== node.alias.value)) {
|
1265
|
+
(!node.d.alias ||
|
1266
|
+
node.d.module.d.nameParts.length !== 1 ||
|
1267
|
+
node.d.module.d.nameParts[0].d.value !== node.d.alias.d.value)) {
|
1272
1268
|
if (this._fileInfo.isStubFile || this._fileInfo.isInPyTypedPackage) {
|
1273
1269
|
// PEP 484 indicates that imported symbols should not be
|
1274
1270
|
// considered "reexported" from a type stub file unless
|
@@ -1277,21 +1273,21 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1277
1273
|
this._potentialHiddenSymbols.set(symbolName, symbol);
|
1278
1274
|
}
|
1279
1275
|
}
|
1280
|
-
const importInfo = AnalyzerNodeInfo.getImportInfo(node.module);
|
1276
|
+
const importInfo = AnalyzerNodeInfo.getImportInfo(node.d.module);
|
1281
1277
|
(0, debug_1.assert)(importInfo !== undefined);
|
1282
1278
|
if (symbol) {
|
1283
|
-
this._createAliasDeclarationForMultipartImportName(node, node.alias, importInfo, symbol);
|
1279
|
+
this._createAliasDeclarationForMultipartImportName(node, node.d.alias, importInfo, symbol);
|
1284
1280
|
}
|
1285
|
-
this._createFlowAssignment(node.alias ? node.alias : node.module.nameParts[0]);
|
1286
|
-
if (node.module.nameParts.length === 1) {
|
1281
|
+
this._createFlowAssignment(node.d.alias ? node.d.alias : node.d.module.d.nameParts[0]);
|
1282
|
+
if (node.d.module.d.nameParts.length === 1) {
|
1287
1283
|
if (firstNamePartValue === 'typing' || firstNamePartValue === 'typing_extensions') {
|
1288
|
-
this._typingImportAliases.push((_b = (_a = node.alias) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : firstNamePartValue);
|
1284
|
+
this._typingImportAliases.push((_b = (_a = node.d.alias) === null || _a === void 0 ? void 0 : _a.d.value) !== null && _b !== void 0 ? _b : firstNamePartValue);
|
1289
1285
|
}
|
1290
1286
|
else if (firstNamePartValue === 'sys') {
|
1291
|
-
this._sysImportAliases.push((_d = (_c = node.alias) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : firstNamePartValue);
|
1287
|
+
this._sysImportAliases.push((_d = (_c = node.d.alias) === null || _c === void 0 ? void 0 : _c.d.value) !== null && _d !== void 0 ? _d : firstNamePartValue);
|
1292
1288
|
}
|
1293
1289
|
else if (firstNamePartValue === 'dataclasses') {
|
1294
|
-
this._dataclassesImportAliases.push((_f = (_e = node.alias) === null || _e === void 0 ? void 0 : _e.value) !== null && _f !== void 0 ? _f : firstNamePartValue);
|
1290
|
+
this._dataclassesImportAliases.push((_f = (_e = node.d.alias) === null || _e === void 0 ? void 0 : _e.d.value) !== null && _f !== void 0 ? _f : firstNamePartValue);
|
1295
1291
|
}
|
1296
1292
|
}
|
1297
1293
|
}
|
@@ -1301,7 +1297,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1301
1297
|
var _a;
|
1302
1298
|
const typingSymbolsOfInterest = ['Final', 'ClassVar', 'Annotated'];
|
1303
1299
|
const dataclassesSymbolsOfInterest = ['InitVar'];
|
1304
|
-
const importInfo = AnalyzerNodeInfo.getImportInfo(node.module);
|
1300
|
+
const importInfo = AnalyzerNodeInfo.getImportInfo(node.d.module);
|
1305
1301
|
AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode);
|
1306
1302
|
let resolvedPath = uri_1.Uri.empty();
|
1307
1303
|
if (importInfo && importInfo.isImportFound && !importInfo.isNativeLib) {
|
@@ -1314,11 +1310,11 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1314
1310
|
// submodule. In that case, we want to the symbol to appear later in the
|
1315
1311
|
// declaration list because it should "win" when resolving the alias.
|
1316
1312
|
const fileName = (0, pathUtils_1.stripFileExtension)(this._fileInfo.fileUri.fileName);
|
1317
|
-
const isModuleInitFile = fileName === '__init__' && node.module.leadingDots === 1 && node.module.nameParts.length === 1;
|
1313
|
+
const isModuleInitFile = fileName === '__init__' && node.d.module.d.leadingDots === 1 && node.d.module.d.nameParts.length === 1;
|
1318
1314
|
let isTypingImport = false;
|
1319
1315
|
let isDataclassesImport = false;
|
1320
|
-
if (node.module.nameParts.length === 1) {
|
1321
|
-
const firstNamePartValue = node.module.nameParts[0].value;
|
1316
|
+
if (node.d.module.d.nameParts.length === 1) {
|
1317
|
+
const firstNamePartValue = node.d.module.d.nameParts[0].d.value;
|
1322
1318
|
if (firstNamePartValue === 'typing' || firstNamePartValue === 'typing_extensions') {
|
1323
1319
|
isTypingImport = true;
|
1324
1320
|
}
|
@@ -1326,7 +1322,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1326
1322
|
isDataclassesImport = true;
|
1327
1323
|
}
|
1328
1324
|
}
|
1329
|
-
if (node.isWildcardImport) {
|
1325
|
+
if (node.d.isWildcardImport) {
|
1330
1326
|
if (ParseTreeUtils.getEnclosingClass(node) || ParseTreeUtils.getEnclosingFunction(node)) {
|
1331
1327
|
this._addSyntaxError(localize_1.LocMessage.wildcardInFunction(), node);
|
1332
1328
|
}
|
@@ -1342,7 +1338,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1342
1338
|
// If the symbol is going to be immediately replaced with a same-named
|
1343
1339
|
// imported symbol, skip this.
|
1344
1340
|
const isImmediatelyReplaced = wildcardNames.some((name) => {
|
1345
|
-
return name === node.module.nameParts[0].value;
|
1341
|
+
return name === node.d.module.d.nameParts[0].d.value;
|
1346
1342
|
});
|
1347
1343
|
if (!isImmediatelyReplaced) {
|
1348
1344
|
this._addImplicitFromImport(node, importInfo);
|
@@ -1422,25 +1418,25 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1422
1418
|
if (isModuleInitFile) {
|
1423
1419
|
this._addImplicitFromImport(node, importInfo);
|
1424
1420
|
}
|
1425
|
-
node.imports.forEach((importSymbolNode) => {
|
1426
|
-
const importedName = importSymbolNode.name.value;
|
1427
|
-
const nameNode = importSymbolNode.alias || importSymbolNode.name;
|
1421
|
+
node.d.imports.forEach((importSymbolNode) => {
|
1422
|
+
const importedName = importSymbolNode.d.name.d.value;
|
1423
|
+
const nameNode = importSymbolNode.d.alias || importSymbolNode.d.name;
|
1428
1424
|
AnalyzerNodeInfo.setFlowNode(importSymbolNode, this._currentFlowNode);
|
1429
1425
|
const symbol = this._bindNameToScope(this._currentScope, nameNode);
|
1430
1426
|
if (symbol) {
|
1431
1427
|
// All import statements of the form `from . import x` treat x
|
1432
1428
|
// as an externally-visible (not hidden) symbol.
|
1433
|
-
if (node.module.nameParts.length > 0) {
|
1429
|
+
if (node.d.module.d.nameParts.length > 0) {
|
1434
1430
|
if (this._currentScope.type === 4 /* ScopeType.Module */ ||
|
1435
1431
|
this._currentScope.type === 5 /* ScopeType.Builtin */) {
|
1436
|
-
if (!importSymbolNode.alias ||
|
1437
|
-
importSymbolNode.alias.value !== importSymbolNode.name.value) {
|
1432
|
+
if (!importSymbolNode.d.alias ||
|
1433
|
+
importSymbolNode.d.alias.d.value !== importSymbolNode.d.name.d.value) {
|
1438
1434
|
if (this._fileInfo.isStubFile || this._fileInfo.isInPyTypedPackage) {
|
1439
1435
|
// PEP 484 indicates that imported symbols should not be
|
1440
1436
|
// considered "reexported" from a type stub file unless
|
1441
1437
|
// they are imported using the "as" form using a redundant form.
|
1442
1438
|
// Py.typed packages follow the same rule as PEP 484.
|
1443
|
-
this._potentialHiddenSymbols.set(nameNode.value, symbol);
|
1439
|
+
this._potentialHiddenSymbols.set(nameNode.d.value, symbol);
|
1444
1440
|
}
|
1445
1441
|
}
|
1446
1442
|
}
|
@@ -1460,7 +1456,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1460
1456
|
loadSymbolsFromPath: true,
|
1461
1457
|
range: (0, textRange_1.getEmptyRange)(),
|
1462
1458
|
usesLocalName: false,
|
1463
|
-
moduleName: this._formatModuleName(node.module),
|
1459
|
+
moduleName: this._formatModuleName(node.d.module),
|
1464
1460
|
isInExceptSuite: this._isInExceptSuite,
|
1465
1461
|
};
|
1466
1462
|
// Handle the case where this is an __init__.py file and the imported
|
@@ -1469,7 +1465,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1469
1465
|
// an absolute import (e.g. "from A.B.C import X"). In this case, we want to
|
1470
1466
|
// always resolve to the submodule rather than the resolved path.
|
1471
1467
|
if (fileName === '__init__') {
|
1472
|
-
if (node.module.leadingDots === 1 && node.module.nameParts.length === 0) {
|
1468
|
+
if (node.d.module.d.leadingDots === 1 && node.d.module.d.nameParts.length === 0) {
|
1473
1469
|
loadSymbolsFromPath = false;
|
1474
1470
|
}
|
1475
1471
|
else if (resolvedPath.equals(this._fileInfo.fileUri)) {
|
@@ -1482,24 +1478,24 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1482
1478
|
node: importSymbolNode,
|
1483
1479
|
uri: resolvedPath,
|
1484
1480
|
loadSymbolsFromPath,
|
1485
|
-
usesLocalName: !!importSymbolNode.alias,
|
1481
|
+
usesLocalName: !!importSymbolNode.d.alias,
|
1486
1482
|
symbolName: importedName,
|
1487
1483
|
submoduleFallback,
|
1488
1484
|
range: (0, positionUtils_1.convertTextRangeToRange)(nameNode, this._fileInfo.lines),
|
1489
|
-
moduleName: this._formatModuleName(node.module),
|
1485
|
+
moduleName: this._formatModuleName(node.d.module),
|
1490
1486
|
isInExceptSuite: this._isInExceptSuite,
|
1491
1487
|
isNativeLib: importInfo === null || importInfo === void 0 ? void 0 : importInfo.isNativeLib,
|
1492
1488
|
};
|
1493
1489
|
symbol.addDeclaration(aliasDecl);
|
1494
|
-
this._createFlowAssignment(importSymbolNode.alias || importSymbolNode.name);
|
1490
|
+
this._createFlowAssignment(importSymbolNode.d.alias || importSymbolNode.d.name);
|
1495
1491
|
if (isTypingImport) {
|
1496
|
-
if (typingSymbolsOfInterest.some((s) => s === importSymbolNode.name.value)) {
|
1497
|
-
this._typingSymbolAliases.set(nameNode.value, importSymbolNode.name.value);
|
1492
|
+
if (typingSymbolsOfInterest.some((s) => s === importSymbolNode.d.name.d.value)) {
|
1493
|
+
this._typingSymbolAliases.set(nameNode.d.value, importSymbolNode.d.name.d.value);
|
1498
1494
|
}
|
1499
1495
|
}
|
1500
1496
|
if (isDataclassesImport) {
|
1501
|
-
if (dataclassesSymbolsOfInterest.some((s) => s === importSymbolNode.name.value)) {
|
1502
|
-
this._dataclassesSymbolAliases.set(nameNode.value, importSymbolNode.name.value);
|
1497
|
+
if (dataclassesSymbolsOfInterest.some((s) => s === importSymbolNode.d.name.d.value)) {
|
1498
|
+
this._dataclassesSymbolAliases.set(nameNode.d.value, importSymbolNode.d.name.d.value);
|
1503
1499
|
}
|
1504
1500
|
}
|
1505
1501
|
}
|
@@ -1508,12 +1504,12 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1508
1504
|
return true;
|
1509
1505
|
}
|
1510
1506
|
visitWith(node) {
|
1511
|
-
node.withItems.forEach((item) => {
|
1512
|
-
this.walk(item.
|
1513
|
-
if (item.target) {
|
1514
|
-
this._bindPossibleTupleNamedTarget(item.target);
|
1515
|
-
this._addInferredTypeAssignmentForVariable(item.target, item);
|
1516
|
-
this._createAssignmentTargetFlowNodes(item.target, /* walkTargets */ true, /* unbound */ false);
|
1507
|
+
node.d.withItems.forEach((item) => {
|
1508
|
+
this.walk(item.d.expr);
|
1509
|
+
if (item.d.target) {
|
1510
|
+
this._bindPossibleTupleNamedTarget(item.d.target);
|
1511
|
+
this._addInferredTypeAssignmentForVariable(item.d.target, item);
|
1512
|
+
this._createAssignmentTargetFlowNodes(item.d.target, /* walkTargets */ true, /* unbound */ false);
|
1517
1513
|
}
|
1518
1514
|
});
|
1519
1515
|
// We need to treat the "with" body as though it is wrapped in a try/except
|
@@ -1540,10 +1536,10 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1540
1536
|
// In addition to the ContextManagerSwallowExceptionTarget, we'll create
|
1541
1537
|
// a second target called ContextManagerForwardExceptionTarget that forwards
|
1542
1538
|
// exceptions to existing exception targets if they exist.
|
1543
|
-
const contextManagerSwallowExceptionTarget = this._createContextManagerLabel(node.withItems.map((item) => item.
|
1539
|
+
const contextManagerSwallowExceptionTarget = this._createContextManagerLabel(node.d.withItems.map((item) => item.d.expr), !!node.d.isAsync,
|
1544
1540
|
/* blockIfSwallowsExceptions */ false);
|
1545
1541
|
this._addAntecedent(contextManagerSwallowExceptionTarget, this._currentFlowNode);
|
1546
|
-
const contextManagerForwardExceptionTarget = this._createContextManagerLabel(node.withItems.map((item) => item.
|
1542
|
+
const contextManagerForwardExceptionTarget = this._createContextManagerLabel(node.d.withItems.map((item) => item.d.expr), !!node.d.isAsync,
|
1547
1543
|
/* blockIfSwallowsExceptions */ true);
|
1548
1544
|
this._currentExceptTargets.forEach((exceptionTarget) => {
|
1549
1545
|
this._addAntecedent(exceptionTarget, contextManagerForwardExceptionTarget);
|
@@ -1553,7 +1549,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1553
1549
|
this._addAntecedent(postContextManagerLabel, contextManagerSwallowExceptionTarget);
|
1554
1550
|
postContextManagerLabel.affectedExpressions = this._trackCodeFlowExpressions(() => {
|
1555
1551
|
this._useExceptTargets([contextManagerSwallowExceptionTarget, contextManagerForwardExceptionTarget], () => {
|
1556
|
-
this.walk(node.suite);
|
1552
|
+
this.walk(node.d.suite);
|
1557
1553
|
});
|
1558
1554
|
this._addAntecedent(postContextManagerLabel, this._currentFlowNode);
|
1559
1555
|
this._currentFlowNode = postContextManagerLabel;
|
@@ -1561,11 +1557,11 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1561
1557
|
if (!this._isCodeUnreachable()) {
|
1562
1558
|
this._addExceptTargets(this._currentFlowNode);
|
1563
1559
|
}
|
1564
|
-
if (node.asyncToken && !this._fileInfo.ipythonMode) {
|
1560
|
+
if (node.d.asyncToken && !this._fileInfo.ipythonMode) {
|
1565
1561
|
// Top level async with is allowed in ipython mode.
|
1566
1562
|
const enclosingFunction = ParseTreeUtils.getEnclosingFunction(node);
|
1567
|
-
if (!enclosingFunction || !enclosingFunction.isAsync) {
|
1568
|
-
this._addSyntaxError(localize_1.LocMessage.asyncNotInAsyncFunction(), node.asyncToken);
|
1563
|
+
if (!enclosingFunction || !enclosingFunction.d.isAsync) {
|
1564
|
+
this._addSyntaxError(localize_1.LocMessage.asyncNotInAsyncFunction(), node.d.asyncToken);
|
1569
1565
|
}
|
1570
1566
|
}
|
1571
1567
|
});
|
@@ -1578,23 +1574,23 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1578
1574
|
const postExpressionLabel = this._createBranchLabel(preTernaryFlowNode);
|
1579
1575
|
postExpressionLabel.affectedExpressions = this._trackCodeFlowExpressions(() => {
|
1580
1576
|
// Handle the test expression.
|
1581
|
-
this._bindConditional(node.
|
1577
|
+
this._bindConditional(node.d.testExpr, trueLabel, falseLabel);
|
1582
1578
|
// Handle the "true" portion (the "if" expression).
|
1583
1579
|
this._currentFlowNode = this._finishFlowLabel(trueLabel);
|
1584
|
-
this.walk(node.
|
1580
|
+
this.walk(node.d.ifExpr);
|
1585
1581
|
this._addAntecedent(postExpressionLabel, this._currentFlowNode);
|
1586
1582
|
// Handle the "false" portion (the "else" expression).
|
1587
1583
|
this._currentFlowNode = this._finishFlowLabel(falseLabel);
|
1588
|
-
this.walk(node.
|
1584
|
+
this.walk(node.d.elseExpr);
|
1589
1585
|
this._addAntecedent(postExpressionLabel, this._currentFlowNode);
|
1590
1586
|
this._currentFlowNode = this._finishFlowLabel(postExpressionLabel);
|
1591
1587
|
});
|
1592
1588
|
return false;
|
1593
1589
|
}
|
1594
1590
|
visitUnaryOperation(node) {
|
1595
|
-
if (node.operator === 38 /* OperatorType.Not */ && this._currentFalseTarget && this._currentTrueTarget) {
|
1591
|
+
if (node.d.operator === 38 /* OperatorType.Not */ && this._currentFalseTarget && this._currentTrueTarget) {
|
1596
1592
|
// Swap the existing true/false targets.
|
1597
|
-
this._bindConditional(node.
|
1593
|
+
this._bindConditional(node.d.expr, this._currentFalseTarget, this._currentTrueTarget);
|
1598
1594
|
}
|
1599
1595
|
else {
|
1600
1596
|
// Temporarily set the true/false targets to undefined because
|
@@ -1602,13 +1598,13 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1602
1598
|
// (AND/OR/NOT subexpressions).
|
1603
1599
|
this._disableTrueFalseTargets(() => {
|
1604
1600
|
// Evaluate the operand expression.
|
1605
|
-
this.walk(node.
|
1601
|
+
this.walk(node.d.expr);
|
1606
1602
|
});
|
1607
1603
|
}
|
1608
1604
|
return false;
|
1609
1605
|
}
|
1610
1606
|
visitBinaryOperation(node) {
|
1611
|
-
if (node.operator === 36 /* OperatorType.And */ || node.operator === 37 /* OperatorType.Or */) {
|
1607
|
+
if (node.d.operator === 36 /* OperatorType.And */ || node.d.operator === 37 /* OperatorType.Or */) {
|
1612
1608
|
let trueTarget = this._currentTrueTarget;
|
1613
1609
|
let falseTarget = this._currentFalseTarget;
|
1614
1610
|
let postRightLabel;
|
@@ -1617,14 +1613,14 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1617
1613
|
trueTarget = falseTarget = postRightLabel;
|
1618
1614
|
}
|
1619
1615
|
const preRightLabel = this._createBranchLabel();
|
1620
|
-
if (node.operator === 36 /* OperatorType.And */) {
|
1621
|
-
this._bindConditional(node.
|
1616
|
+
if (node.d.operator === 36 /* OperatorType.And */) {
|
1617
|
+
this._bindConditional(node.d.leftExpr, preRightLabel, falseTarget);
|
1622
1618
|
}
|
1623
1619
|
else {
|
1624
|
-
this._bindConditional(node.
|
1620
|
+
this._bindConditional(node.d.leftExpr, trueTarget, preRightLabel);
|
1625
1621
|
}
|
1626
1622
|
this._currentFlowNode = this._finishFlowLabel(preRightLabel);
|
1627
|
-
this._bindConditional(node.
|
1623
|
+
this._bindConditional(node.d.rightExpr, trueTarget, falseTarget);
|
1628
1624
|
if (postRightLabel) {
|
1629
1625
|
this._currentFlowNode = this._finishFlowLabel(postRightLabel);
|
1630
1626
|
}
|
@@ -1634,8 +1630,8 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1634
1630
|
// this binary operation is not part of a chain of logical expressions
|
1635
1631
|
// (AND/OR/NOT subexpressions).
|
1636
1632
|
this._disableTrueFalseTargets(() => {
|
1637
|
-
this.walk(node.
|
1638
|
-
this.walk(node.
|
1633
|
+
this.walk(node.d.leftExpr);
|
1634
|
+
this.walk(node.d.rightExpr);
|
1639
1635
|
});
|
1640
1636
|
}
|
1641
1637
|
return false;
|
@@ -1643,8 +1639,8 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1643
1639
|
visitComprehension(node) {
|
1644
1640
|
const enclosingFunction = ParseTreeUtils.getEnclosingFunction(node);
|
1645
1641
|
// The first iterable is executed outside of the comprehension scope.
|
1646
|
-
if (node.forIfNodes.length > 0 && node.forIfNodes[0].nodeType === 12 /* ParseNodeType.ComprehensionFor */) {
|
1647
|
-
this.walk(node.forIfNodes[0].
|
1642
|
+
if (node.d.forIfNodes.length > 0 && node.d.forIfNodes[0].nodeType === 12 /* ParseNodeType.ComprehensionFor */) {
|
1643
|
+
this.walk(node.d.forIfNodes[0].d.iterableExpr);
|
1648
1644
|
}
|
1649
1645
|
this._createNewScope(1 /* ScopeType.Comprehension */, this._getNonClassParentScope(),
|
1650
1646
|
/* proxyScope */ undefined, () => {
|
@@ -1654,45 +1650,45 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1654
1650
|
// We'll walk the forIfNodes list twice. The first time we'll
|
1655
1651
|
// bind targets of for statements. The second time we'll walk
|
1656
1652
|
// expressions and create the control flow graph.
|
1657
|
-
for (let i = 0; i < node.forIfNodes.length; i++) {
|
1658
|
-
const compr = node.forIfNodes[i];
|
1653
|
+
for (let i = 0; i < node.d.forIfNodes.length; i++) {
|
1654
|
+
const compr = node.d.forIfNodes[i];
|
1659
1655
|
const addedSymbols = new Map();
|
1660
1656
|
if (compr.nodeType === 12 /* ParseNodeType.ComprehensionFor */) {
|
1661
|
-
this._bindPossibleTupleNamedTarget(compr.
|
1662
|
-
this._addInferredTypeAssignmentForVariable(compr.
|
1657
|
+
this._bindPossibleTupleNamedTarget(compr.d.targetExpr, addedSymbols);
|
1658
|
+
this._addInferredTypeAssignmentForVariable(compr.d.targetExpr, compr);
|
1663
1659
|
// Async for is not allowed outside of an async function
|
1664
1660
|
// unless we're in ipython mode.
|
1665
|
-
if (compr.asyncToken && !this._fileInfo.ipythonMode) {
|
1666
|
-
if (!enclosingFunction || !enclosingFunction.isAsync) {
|
1661
|
+
if (compr.d.asyncToken && !this._fileInfo.ipythonMode) {
|
1662
|
+
if (!enclosingFunction || !enclosingFunction.d.isAsync) {
|
1667
1663
|
// Allow if it's within a generator expression. Execution of
|
1668
1664
|
// generator expressions is deferred and therefore can be
|
1669
1665
|
// run within the context of an async function later.
|
1670
1666
|
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 34 /* ParseNodeType.List */) {
|
1671
|
-
this._addSyntaxError(localize_1.LocMessage.asyncNotInAsyncFunction(), compr.asyncToken);
|
1667
|
+
this._addSyntaxError(localize_1.LocMessage.asyncNotInAsyncFunction(), compr.d.asyncToken);
|
1672
1668
|
}
|
1673
1669
|
}
|
1674
1670
|
}
|
1675
1671
|
}
|
1676
1672
|
}
|
1677
|
-
for (let i = 0; i < node.forIfNodes.length; i++) {
|
1678
|
-
const compr = node.forIfNodes[i];
|
1673
|
+
for (let i = 0; i < node.d.forIfNodes.length; i++) {
|
1674
|
+
const compr = node.d.forIfNodes[i];
|
1679
1675
|
if (compr.nodeType === 12 /* ParseNodeType.ComprehensionFor */) {
|
1680
1676
|
// We already walked the first iterable expression above,
|
1681
1677
|
// so skip it here.
|
1682
1678
|
if (i !== 0) {
|
1683
|
-
this.walk(compr.
|
1679
|
+
this.walk(compr.d.iterableExpr);
|
1684
1680
|
}
|
1685
|
-
this._createAssignmentTargetFlowNodes(compr.
|
1681
|
+
this._createAssignmentTargetFlowNodes(compr.d.targetExpr,
|
1686
1682
|
/* walkTargets */ true,
|
1687
1683
|
/* unbound */ false);
|
1688
1684
|
}
|
1689
1685
|
else {
|
1690
1686
|
const trueLabel = this._createBranchLabel();
|
1691
|
-
this._bindConditional(compr.
|
1687
|
+
this._bindConditional(compr.d.testExpr, trueLabel, falseLabel);
|
1692
1688
|
this._currentFlowNode = this._finishFlowLabel(trueLabel);
|
1693
1689
|
}
|
1694
1690
|
}
|
1695
|
-
this.walk(node.
|
1691
|
+
this.walk(node.d.expr);
|
1696
1692
|
this._addAntecedent(falseLabel, this._currentFlowNode);
|
1697
1693
|
this._currentFlowNode = this._finishFlowLabel(falseLabel);
|
1698
1694
|
});
|
@@ -1700,9 +1696,9 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1700
1696
|
}
|
1701
1697
|
visitMatch(node) {
|
1702
1698
|
// Evaluate the subject expression.
|
1703
|
-
this.walk(node.
|
1699
|
+
this.walk(node.d.expr);
|
1704
1700
|
const expressionList = [];
|
1705
|
-
const isSubjectNarrowable = this._isNarrowingExpression(node.
|
1701
|
+
const isSubjectNarrowable = this._isNarrowingExpression(node.d.expr, expressionList);
|
1706
1702
|
if (isSubjectNarrowable) {
|
1707
1703
|
expressionList.forEach((expr) => {
|
1708
1704
|
const referenceKey = (0, codeFlowTypes_1.createKeyForReference)(expr);
|
@@ -1714,32 +1710,32 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1714
1710
|
// Model the match statement as a series of if/elif clauses
|
1715
1711
|
// each of which tests for the specified pattern (and optionally
|
1716
1712
|
// for the guard condition).
|
1717
|
-
node.cases.forEach((caseStatement) => {
|
1713
|
+
node.d.cases.forEach((caseStatement) => {
|
1718
1714
|
const postCaseLabel = this._createBranchLabel();
|
1719
1715
|
const preGuardLabel = this._createBranchLabel();
|
1720
1716
|
const preSuiteLabel = this._createBranchLabel();
|
1721
1717
|
// Evaluate the pattern.
|
1722
1718
|
this._addAntecedent(preGuardLabel, this._currentFlowNode);
|
1723
|
-
if (!caseStatement.isIrrefutable) {
|
1719
|
+
if (!caseStatement.d.isIrrefutable) {
|
1724
1720
|
this._addAntecedent(postCaseLabel, this._currentFlowNode);
|
1725
1721
|
}
|
1726
|
-
else if (!caseStatement.
|
1722
|
+
else if (!caseStatement.d.guardExpr) {
|
1727
1723
|
foundIrrefutableCase = true;
|
1728
1724
|
}
|
1729
1725
|
this._currentFlowNode = this._finishFlowLabel(preGuardLabel);
|
1730
1726
|
// Bind the pattern.
|
1731
|
-
this.walk(caseStatement.pattern);
|
1732
|
-
this._createFlowNarrowForPattern(node.
|
1727
|
+
this.walk(caseStatement.d.pattern);
|
1728
|
+
this._createFlowNarrowForPattern(node.d.expr, caseStatement);
|
1733
1729
|
// Apply the guard expression.
|
1734
|
-
if (caseStatement.
|
1735
|
-
this._bindConditional(caseStatement.
|
1730
|
+
if (caseStatement.d.guardExpr) {
|
1731
|
+
this._bindConditional(caseStatement.d.guardExpr, preSuiteLabel, postCaseLabel);
|
1736
1732
|
}
|
1737
1733
|
else {
|
1738
1734
|
this._addAntecedent(preSuiteLabel, this._currentFlowNode);
|
1739
1735
|
}
|
1740
1736
|
this._currentFlowNode = this._finishFlowLabel(preSuiteLabel);
|
1741
1737
|
// Bind the body of the case statement.
|
1742
|
-
this.walk(caseStatement.suite);
|
1738
|
+
this.walk(caseStatement.d.suite);
|
1743
1739
|
this._addAntecedent(postMatchLabel, this._currentFlowNode);
|
1744
1740
|
this._currentFlowNode = this._finishFlowLabel(postCaseLabel);
|
1745
1741
|
});
|
@@ -1747,7 +1743,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1747
1743
|
// match statement. This will compute the narrowed type if no case
|
1748
1744
|
// statements are matched.
|
1749
1745
|
if (isSubjectNarrowable) {
|
1750
|
-
this._createFlowNarrowForPattern(node.
|
1746
|
+
this._createFlowNarrowForPattern(node.d.expr, node);
|
1751
1747
|
}
|
1752
1748
|
// Create an "implied else" to conditionally gate code flow based on
|
1753
1749
|
// whether the narrowed type of the subject expression is Never at this point.
|
@@ -1760,26 +1756,26 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1760
1756
|
}
|
1761
1757
|
visitPatternAs(node) {
|
1762
1758
|
const postOrLabel = this._createBranchLabel();
|
1763
|
-
node.orPatterns.forEach((orPattern) => {
|
1759
|
+
node.d.orPatterns.forEach((orPattern) => {
|
1764
1760
|
this.walk(orPattern);
|
1765
1761
|
this._addAntecedent(postOrLabel, this._currentFlowNode);
|
1766
1762
|
});
|
1767
1763
|
this._currentFlowNode = this._finishFlowLabel(postOrLabel);
|
1768
|
-
if (node.target) {
|
1769
|
-
this.walk(node.target);
|
1770
|
-
const symbol = this._bindNameToScope(this._currentScope, node.target);
|
1771
|
-
this._createAssignmentTargetFlowNodes(node.target, /* walkTargets */ false, /* unbound */ false);
|
1764
|
+
if (node.d.target) {
|
1765
|
+
this.walk(node.d.target);
|
1766
|
+
const symbol = this._bindNameToScope(this._currentScope, node.d.target);
|
1767
|
+
this._createAssignmentTargetFlowNodes(node.d.target, /* walkTargets */ false, /* unbound */ false);
|
1772
1768
|
if (symbol) {
|
1773
1769
|
const declaration = {
|
1774
1770
|
type: 1 /* DeclarationType.Variable */,
|
1775
|
-
node: node.target,
|
1776
|
-
isConstant: (0, symbolNameUtils_1.isConstantName)(node.target.value),
|
1771
|
+
node: node.d.target,
|
1772
|
+
isConstant: (0, symbolNameUtils_1.isConstantName)(node.d.target.d.value),
|
1777
1773
|
inferredTypeSource: node,
|
1778
1774
|
uri: this._fileInfo.fileUri,
|
1779
|
-
range: (0, positionUtils_1.convertTextRangeToRange)(node.target, this._fileInfo.lines),
|
1775
|
+
range: (0, positionUtils_1.convertTextRangeToRange)(node.d.target, this._fileInfo.lines),
|
1780
1776
|
moduleName: this._fileInfo.moduleName,
|
1781
1777
|
isInExceptSuite: this._isInExceptSuite,
|
1782
|
-
isExplicitBinding: this._currentScope.getBindingType(node.target.value) !== undefined,
|
1778
|
+
isExplicitBinding: this._currentScope.getBindingType(node.d.target.d.value) !== undefined,
|
1783
1779
|
};
|
1784
1780
|
symbol.addDeclaration(declaration);
|
1785
1781
|
}
|
@@ -1787,19 +1783,19 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1787
1783
|
return false;
|
1788
1784
|
}
|
1789
1785
|
visitPatternCapture(node) {
|
1790
|
-
if (!node.isWildcard) {
|
1791
|
-
this._addPatternCaptureTarget(node.target);
|
1786
|
+
if (!node.d.isWildcard) {
|
1787
|
+
this._addPatternCaptureTarget(node.d.target);
|
1792
1788
|
}
|
1793
1789
|
return true;
|
1794
1790
|
}
|
1795
1791
|
visitPatternMappingExpandEntry(node) {
|
1796
|
-
if (node.target.value !== '_') {
|
1797
|
-
this._addPatternCaptureTarget(node.target);
|
1792
|
+
if (node.d.target.d.value !== '_') {
|
1793
|
+
this._addPatternCaptureTarget(node.d.target);
|
1798
1794
|
}
|
1799
1795
|
return true;
|
1800
1796
|
}
|
1801
1797
|
_formatModuleName(node) {
|
1802
|
-
return '.'.repeat(node.leadingDots) + node.nameParts.map((part) => part.value).join('.');
|
1798
|
+
return '.'.repeat(node.d.leadingDots) + node.d.nameParts.map((part) => part.d.value).join('.');
|
1803
1799
|
}
|
1804
1800
|
_getNonClassParentScope() {
|
1805
1801
|
// We may not be able to use the current scope if it's a class scope.
|
@@ -1814,7 +1810,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1814
1810
|
(0, debug_1.assert)(this._currentScope.type === 3 /* ScopeType.Class */);
|
1815
1811
|
let slotsContainsDict = false;
|
1816
1812
|
for (const slotNameNode of slotNameNodes) {
|
1817
|
-
const slotName = slotNameNode.strings[0].value;
|
1813
|
+
const slotName = slotNameNode.d.strings[0].d.value;
|
1818
1814
|
if (slotName === '__dict__') {
|
1819
1815
|
slotsContainsDict = true;
|
1820
1816
|
continue;
|
@@ -1841,7 +1837,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1841
1837
|
symbol.addDeclaration(declaration);
|
1842
1838
|
}
|
1843
1839
|
if (!slotsContainsDict) {
|
1844
|
-
this._currentScope.setSlotsNames(slotNameNodes.map((node) => node.strings[0].value));
|
1840
|
+
this._currentScope.setSlotsNames(slotNameNodes.map((node) => node.d.strings[0].d.value));
|
1845
1841
|
}
|
1846
1842
|
}
|
1847
1843
|
_isInComprehension(node, ignoreOutermostIterable = false) {
|
@@ -1850,10 +1846,10 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1850
1846
|
let prevPrevNode;
|
1851
1847
|
while (curNode) {
|
1852
1848
|
if (curNode.nodeType === 11 /* ParseNodeType.Comprehension */) {
|
1853
|
-
if (ignoreOutermostIterable && curNode.forIfNodes.length > 0) {
|
1854
|
-
const outermostCompr = curNode.forIfNodes[0];
|
1849
|
+
if (ignoreOutermostIterable && curNode.d.forIfNodes.length > 0) {
|
1850
|
+
const outermostCompr = curNode.d.forIfNodes[0];
|
1855
1851
|
if (prevNode === outermostCompr && outermostCompr.nodeType === 12 /* ParseNodeType.ComprehensionFor */) {
|
1856
|
-
if (prevPrevNode === outermostCompr.
|
1852
|
+
if (prevPrevNode === outermostCompr.d.iterableExpr) {
|
1857
1853
|
return false;
|
1858
1854
|
}
|
1859
1855
|
}
|
@@ -1873,13 +1869,13 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1873
1869
|
const declaration = {
|
1874
1870
|
type: 1 /* DeclarationType.Variable */,
|
1875
1871
|
node: target,
|
1876
|
-
isConstant: (0, symbolNameUtils_1.isConstantName)(target.value),
|
1872
|
+
isConstant: (0, symbolNameUtils_1.isConstantName)(target.d.value),
|
1877
1873
|
inferredTypeSource: target.parent,
|
1878
1874
|
uri: this._fileInfo.fileUri,
|
1879
1875
|
range: (0, positionUtils_1.convertTextRangeToRange)(target, this._fileInfo.lines),
|
1880
1876
|
moduleName: this._fileInfo.moduleName,
|
1881
1877
|
isInExceptSuite: this._isInExceptSuite,
|
1882
|
-
isExplicitBinding: this._currentScope.getBindingType(target.value) !== undefined,
|
1878
|
+
isExplicitBinding: this._currentScope.getBindingType(target.d.value) !== undefined,
|
1883
1879
|
};
|
1884
1880
|
symbol.addDeclaration(declaration);
|
1885
1881
|
}
|
@@ -1921,16 +1917,16 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1921
1917
|
return undefined;
|
1922
1918
|
}
|
1923
1919
|
_addImplicitFromImport(node, importInfo) {
|
1924
|
-
const symbolName = node.module.nameParts[0].value;
|
1920
|
+
const symbolName = node.d.module.d.nameParts[0].d.value;
|
1925
1921
|
const symbol = this._bindNameValueToScope(this._currentScope, symbolName);
|
1926
1922
|
if (symbol) {
|
1927
1923
|
this._createAliasDeclarationForMultipartImportName(node, /* importAlias */ undefined, importInfo, symbol);
|
1928
1924
|
}
|
1929
|
-
this._createFlowAssignment(node.module.nameParts[0]);
|
1925
|
+
this._createFlowAssignment(node.d.module.d.nameParts[0]);
|
1930
1926
|
}
|
1931
1927
|
_createAliasDeclarationForMultipartImportName(node, importAlias, importInfo, symbol) {
|
1932
1928
|
var _a;
|
1933
|
-
const firstNamePartValue = node.module.nameParts[0].value;
|
1929
|
+
const firstNamePartValue = node.d.module.d.nameParts[0].d.value;
|
1934
1930
|
AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode);
|
1935
1931
|
// See if there's already a matching alias declaration for this import.
|
1936
1932
|
// if so, we'll update it rather than creating a new one. This is required
|
@@ -1963,8 +1959,8 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1963
1959
|
range: (0, textRange_1.getEmptyRange)(),
|
1964
1960
|
usesLocalName: !!importAlias,
|
1965
1961
|
moduleName: importAlias
|
1966
|
-
? this._formatModuleName(node.module)
|
1967
|
-
: '.'.repeat(node.module.leadingDots) + firstNamePartValue,
|
1962
|
+
? this._formatModuleName(node.d.module)
|
1963
|
+
: '.'.repeat(node.d.module.d.leadingDots) + firstNamePartValue,
|
1968
1964
|
firstNamePart: firstNamePartValue,
|
1969
1965
|
isInExceptSuite: this._isInExceptSuite,
|
1970
1966
|
};
|
@@ -1982,15 +1978,15 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1982
1978
|
usesLocalName: !!importAlias,
|
1983
1979
|
moduleName: (_a = importInfo === null || importInfo === void 0 ? void 0 : importInfo.importName) !== null && _a !== void 0 ? _a : '',
|
1984
1980
|
firstNamePart: importAlias
|
1985
|
-
? this._formatModuleName(node.module)
|
1986
|
-
: '.'.repeat(node.module.leadingDots) + firstNamePartValue,
|
1981
|
+
? this._formatModuleName(node.d.module)
|
1982
|
+
: '.'.repeat(node.d.module.d.leadingDots) + firstNamePartValue,
|
1987
1983
|
isUnresolved: true,
|
1988
1984
|
isInExceptSuite: this._isInExceptSuite,
|
1989
1985
|
};
|
1990
1986
|
}
|
1991
1987
|
// See if there is import info for this part of the path. This allows us
|
1992
1988
|
// to implicitly import all of the modules in a multi-part module name.
|
1993
|
-
const implicitImportInfo = AnalyzerNodeInfo.getImportInfo(node.module.nameParts[0]);
|
1989
|
+
const implicitImportInfo = AnalyzerNodeInfo.getImportInfo(node.d.module.d.nameParts[0]);
|
1994
1990
|
if (implicitImportInfo && implicitImportInfo.resolvedUris.length) {
|
1995
1991
|
newDecl.uri = implicitImportInfo.resolvedUris[0];
|
1996
1992
|
newDecl.loadSymbolsFromPath = true;
|
@@ -1998,7 +1994,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1998
1994
|
}
|
1999
1995
|
// Add the implicit imports for this module if it's the last
|
2000
1996
|
// name part we're resolving.
|
2001
|
-
if (importAlias || node.module.nameParts.length === 1) {
|
1997
|
+
if (importAlias || node.d.module.d.nameParts.length === 1) {
|
2002
1998
|
newDecl.uri = uriOfLastSubmodule;
|
2003
1999
|
newDecl.loadSymbolsFromPath = true;
|
2004
2000
|
newDecl.isUnresolved = false;
|
@@ -2009,8 +2005,8 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2009
2005
|
else {
|
2010
2006
|
// Fill in the remaining name parts.
|
2011
2007
|
let curLoaderActions = newDecl;
|
2012
|
-
for (let i = 1; i < node.module.nameParts.length; i++) {
|
2013
|
-
const namePartValue = node.module.nameParts[i].value;
|
2008
|
+
for (let i = 1; i < node.d.module.d.nameParts.length; i++) {
|
2009
|
+
const namePartValue = node.d.module.d.nameParts[i].d.value;
|
2014
2010
|
// Is there an existing loader action for this name?
|
2015
2011
|
let loaderActions = curLoaderActions.implicitImports
|
2016
2012
|
? curLoaderActions.implicitImports.get(namePartValue)
|
@@ -2031,7 +2027,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2031
2027
|
}
|
2032
2028
|
curLoaderActions.implicitImports.set(namePartValue, loaderActions);
|
2033
2029
|
}
|
2034
|
-
if (i === node.module.nameParts.length - 1) {
|
2030
|
+
if (i === node.d.module.d.nameParts.length - 1) {
|
2035
2031
|
// If this is the last name part we're resolving, add in the
|
2036
2032
|
// implicit imports as well.
|
2037
2033
|
if (importInfo && i < importInfo.resolvedUris.length) {
|
@@ -2045,7 +2041,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2045
2041
|
// is import info for this part of the path. This allows us to implicitly
|
2046
2042
|
// import all of the modules in a multi-part module name (e.g. "import a.b.c"
|
2047
2043
|
// imports "a" and "a.b" and "a.b.c").
|
2048
|
-
const implicitImportInfo = AnalyzerNodeInfo.getImportInfo(node.module.nameParts[i]);
|
2044
|
+
const implicitImportInfo = AnalyzerNodeInfo.getImportInfo(node.d.module.d.nameParts[i]);
|
2049
2045
|
if (implicitImportInfo && implicitImportInfo.resolvedUris.length) {
|
2050
2046
|
loaderActions.uri = implicitImportInfo.resolvedUris[i];
|
2051
2047
|
loaderActions.loadSymbolsFromPath = true;
|
@@ -2178,12 +2174,12 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2178
2174
|
// positive or negative case).
|
2179
2175
|
_bindNeverCondition(node, target, isPositiveTest) {
|
2180
2176
|
const expressionList = [];
|
2181
|
-
if (node.nodeType === 55 /* ParseNodeType.UnaryOperation */ && node.operator === 38 /* OperatorType.Not */) {
|
2182
|
-
this._bindNeverCondition(node.
|
2177
|
+
if (node.nodeType === 55 /* ParseNodeType.UnaryOperation */ && node.d.operator === 38 /* OperatorType.Not */) {
|
2178
|
+
this._bindNeverCondition(node.d.expr, target, !isPositiveTest);
|
2183
2179
|
}
|
2184
2180
|
else if (node.nodeType === 7 /* ParseNodeType.BinaryOperation */ &&
|
2185
|
-
(node.operator === 36 /* OperatorType.And */ || node.operator === 37 /* OperatorType.Or */)) {
|
2186
|
-
let isAnd = node.operator === 36 /* OperatorType.And */;
|
2181
|
+
(node.d.operator === 36 /* OperatorType.And */ || node.d.operator === 37 /* OperatorType.Or */)) {
|
2182
|
+
let isAnd = node.d.operator === 36 /* OperatorType.And */;
|
2187
2183
|
if (isPositiveTest) {
|
2188
2184
|
isAnd = !isAnd;
|
2189
2185
|
}
|
@@ -2191,22 +2187,22 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2191
2187
|
// In the And case, we need to gate the synthesized else clause if both
|
2192
2188
|
// of the operands evaluate to never once they are narrowed.
|
2193
2189
|
const savedCurrentFlowNode = this._currentFlowNode;
|
2194
|
-
this._bindNeverCondition(node.
|
2190
|
+
this._bindNeverCondition(node.d.leftExpr, target, isPositiveTest);
|
2195
2191
|
this._currentFlowNode = savedCurrentFlowNode;
|
2196
|
-
this._bindNeverCondition(node.
|
2192
|
+
this._bindNeverCondition(node.d.rightExpr, target, isPositiveTest);
|
2197
2193
|
}
|
2198
2194
|
else {
|
2199
2195
|
const initialCurrentFlowNode = this._currentFlowNode;
|
2200
2196
|
// In the Or case, we need to gate the synthesized else clause if either
|
2201
2197
|
// of the operands evaluate to never.
|
2202
2198
|
const afterLabel = this._createBranchLabel();
|
2203
|
-
this._bindNeverCondition(node.
|
2199
|
+
this._bindNeverCondition(node.d.leftExpr, afterLabel, isPositiveTest);
|
2204
2200
|
// If the condition didn't result in any new flow nodes, we can skip
|
2205
2201
|
// checking the other condition.
|
2206
2202
|
if (initialCurrentFlowNode !== this._currentFlowNode) {
|
2207
2203
|
this._currentFlowNode = this._finishFlowLabel(afterLabel);
|
2208
2204
|
const prevCurrentNode = this._currentFlowNode;
|
2209
|
-
this._bindNeverCondition(node.
|
2205
|
+
this._bindNeverCondition(node.d.rightExpr, target, isPositiveTest);
|
2210
2206
|
// If the second condition resulted in no new control flow node, we can
|
2211
2207
|
// eliminate this entire subgraph.
|
2212
2208
|
if (prevCurrentNode === this._currentFlowNode) {
|
@@ -2285,10 +2281,10 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2285
2281
|
_isLogicalExpression(expression) {
|
2286
2282
|
switch (expression.nodeType) {
|
2287
2283
|
case 55 /* ParseNodeType.UnaryOperation */: {
|
2288
|
-
return expression.operator === 38 /* OperatorType.Not */;
|
2284
|
+
return expression.d.operator === 38 /* OperatorType.Not */;
|
2289
2285
|
}
|
2290
2286
|
case 7 /* ParseNodeType.BinaryOperation */: {
|
2291
|
-
return expression.operator === 36 /* OperatorType.And */ || expression.operator === 37 /* OperatorType.Or */;
|
2287
|
+
return expression.d.operator === 36 /* OperatorType.And */ || expression.d.operator === 37 /* OperatorType.Or */;
|
2292
2288
|
}
|
2293
2289
|
}
|
2294
2290
|
return false;
|
@@ -2326,19 +2322,19 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2326
2322
|
// leftExpression to the expression list because that expression
|
2327
2323
|
// can be narrowed based on the attribute type.
|
2328
2324
|
if (expression.nodeType === 35 /* ParseNodeType.MemberAccess */) {
|
2329
|
-
if ((0, codeFlowTypes_1.isCodeFlowSupportedForReference)(expression.
|
2330
|
-
expressionList.push(expression.
|
2325
|
+
if ((0, codeFlowTypes_1.isCodeFlowSupportedForReference)(expression.d.leftExpr)) {
|
2326
|
+
expressionList.push(expression.d.leftExpr);
|
2331
2327
|
}
|
2332
2328
|
}
|
2333
2329
|
// If the expression is an index expression with a supported
|
2334
2330
|
// subscript, add its baseExpression to the expression list because
|
2335
2331
|
// that expression can be narrowed.
|
2336
2332
|
if (expression.nodeType === 27 /* ParseNodeType.Index */ &&
|
2337
|
-
expression.items.length === 1 &&
|
2338
|
-
!expression.trailingComma &&
|
2339
|
-
expression.items[0].
|
2340
|
-
if ((0, codeFlowTypes_1.isCodeFlowSupportedForReference)(expression.
|
2341
|
-
expressionList.push(expression.
|
2333
|
+
expression.d.items.length === 1 &&
|
2334
|
+
!expression.d.trailingComma &&
|
2335
|
+
expression.d.items[0].d.argCategory === 0 /* ArgumentCategory.Simple */) {
|
2336
|
+
if ((0, codeFlowTypes_1.isCodeFlowSupportedForReference)(expression.d.leftExpr)) {
|
2337
|
+
expressionList.push(expression.d.leftExpr);
|
2342
2338
|
}
|
2343
2339
|
}
|
2344
2340
|
}
|
@@ -2347,33 +2343,33 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2347
2343
|
return false;
|
2348
2344
|
}
|
2349
2345
|
case 4 /* ParseNodeType.AssignmentExpression */: {
|
2350
|
-
expressionList.push(expression.name);
|
2351
|
-
this._isNarrowingExpression(expression.
|
2346
|
+
expressionList.push(expression.d.name);
|
2347
|
+
this._isNarrowingExpression(expression.d.rightExpr, expressionList, filterForNeverNarrowing,
|
2352
2348
|
/* isComplexExpression */ true);
|
2353
2349
|
return true;
|
2354
2350
|
}
|
2355
2351
|
case 7 /* ParseNodeType.BinaryOperation */: {
|
2356
|
-
const isOrIsNotOperator = expression.operator === 39 /* OperatorType.Is */ || expression.operator === 40 /* OperatorType.IsNot */;
|
2357
|
-
const equalsOrNotEqualsOperator = expression.operator === 12 /* OperatorType.Equals */ || expression.operator === 28 /* OperatorType.NotEquals */;
|
2352
|
+
const isOrIsNotOperator = expression.d.operator === 39 /* OperatorType.Is */ || expression.d.operator === 40 /* OperatorType.IsNot */;
|
2353
|
+
const equalsOrNotEqualsOperator = expression.d.operator === 12 /* OperatorType.Equals */ || expression.d.operator === 28 /* OperatorType.NotEquals */;
|
2358
2354
|
if (isOrIsNotOperator || equalsOrNotEqualsOperator) {
|
2359
2355
|
// Look for "X is None", "X is not None", "X == None", "X != None".
|
2360
2356
|
// These are commonly-used patterns used in control flow.
|
2361
|
-
if (expression.
|
2362
|
-
expression.
|
2363
|
-
return this._isNarrowingExpression(expression.
|
2357
|
+
if (expression.d.rightExpr.nodeType === 14 /* ParseNodeType.Constant */ &&
|
2358
|
+
expression.d.rightExpr.d.constType === 26 /* KeywordType.None */) {
|
2359
|
+
return this._isNarrowingExpression(expression.d.leftExpr, expressionList, filterForNeverNarrowing,
|
2364
2360
|
/* isComplexExpression */ true);
|
2365
2361
|
}
|
2366
2362
|
// Look for "type(X) is Y" or "type(X) is not Y".
|
2367
2363
|
if (isOrIsNotOperator &&
|
2368
|
-
expression.
|
2369
|
-
expression.
|
2370
|
-
expression.
|
2371
|
-
expression.
|
2372
|
-
expression.
|
2373
|
-
return this._isNarrowingExpression(expression.
|
2364
|
+
expression.d.leftExpr.nodeType === 9 /* ParseNodeType.Call */ &&
|
2365
|
+
expression.d.leftExpr.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ &&
|
2366
|
+
expression.d.leftExpr.d.leftExpr.d.value === 'type' &&
|
2367
|
+
expression.d.leftExpr.d.args.length === 1 &&
|
2368
|
+
expression.d.leftExpr.d.args[0].d.argCategory === 0 /* ArgumentCategory.Simple */) {
|
2369
|
+
return this._isNarrowingExpression(expression.d.leftExpr.d.args[0].d.valueExpr, expressionList, filterForNeverNarrowing,
|
2374
2370
|
/* isComplexExpression */ true);
|
2375
2371
|
}
|
2376
|
-
const isLeftNarrowing = this._isNarrowingExpression(expression.
|
2372
|
+
const isLeftNarrowing = this._isNarrowingExpression(expression.d.leftExpr, expressionList, filterForNeverNarrowing,
|
2377
2373
|
/* isComplexExpression */ true);
|
2378
2374
|
// Look for "X is Y" or "X is not Y".
|
2379
2375
|
// Look for X == <literal> or X != <literal>
|
@@ -2381,66 +2377,65 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2381
2377
|
return isLeftNarrowing;
|
2382
2378
|
}
|
2383
2379
|
// Look for len(X) < <literal>, len(X) <= <literal>, len(X) > <literal>, len(X) >= <literal>.
|
2384
|
-
if (expression.
|
2385
|
-
expression.
|
2386
|
-
|
2387
|
-
expression.operator ===
|
2388
|
-
expression.operator ===
|
2389
|
-
|
2390
|
-
const isLeftNarrowing = this._isNarrowingExpression(expression.leftExpression, expressionList, filterForNeverNarrowing,
|
2380
|
+
if (expression.d.rightExpr.nodeType === 40 /* ParseNodeType.Number */ && expression.d.rightExpr.d.isInteger) {
|
2381
|
+
if (expression.d.operator === 20 /* OperatorType.LessThan */ ||
|
2382
|
+
expression.d.operator === 21 /* OperatorType.LessThanOrEqual */ ||
|
2383
|
+
expression.d.operator === 15 /* OperatorType.GreaterThan */ ||
|
2384
|
+
expression.d.operator === 16 /* OperatorType.GreaterThanOrEqual */) {
|
2385
|
+
const isLeftNarrowing = this._isNarrowingExpression(expression.d.leftExpr, expressionList, filterForNeverNarrowing,
|
2391
2386
|
/* isComplexExpression */ true);
|
2392
2387
|
return isLeftNarrowing;
|
2393
2388
|
}
|
2394
2389
|
}
|
2395
2390
|
// Look for "<string> in Y" or "<string> not in Y".
|
2396
|
-
if (expression.operator === 41 /* OperatorType.In */ || expression.operator === 42 /* OperatorType.NotIn */) {
|
2397
|
-
if (expression.
|
2398
|
-
this._isNarrowingExpression(expression.
|
2391
|
+
if (expression.d.operator === 41 /* OperatorType.In */ || expression.d.operator === 42 /* OperatorType.NotIn */) {
|
2392
|
+
if (expression.d.leftExpr.nodeType === 48 /* ParseNodeType.StringList */ &&
|
2393
|
+
this._isNarrowingExpression(expression.d.rightExpr, expressionList, filterForNeverNarrowing,
|
2399
2394
|
/* isComplexExpression */ true)) {
|
2400
2395
|
return true;
|
2401
2396
|
}
|
2402
2397
|
}
|
2403
2398
|
// Look for "X in Y" or "X not in Y".
|
2404
|
-
if (expression.operator === 41 /* OperatorType.In */ || expression.operator === 42 /* OperatorType.NotIn */) {
|
2405
|
-
const isLeftNarrowable = this._isNarrowingExpression(expression.
|
2399
|
+
if (expression.d.operator === 41 /* OperatorType.In */ || expression.d.operator === 42 /* OperatorType.NotIn */) {
|
2400
|
+
const isLeftNarrowable = this._isNarrowingExpression(expression.d.leftExpr, expressionList, filterForNeverNarrowing,
|
2406
2401
|
/* isComplexExpression */ true);
|
2407
|
-
const isRightNarrowable = this._isNarrowingExpression(expression.
|
2402
|
+
const isRightNarrowable = this._isNarrowingExpression(expression.d.rightExpr, expressionList, filterForNeverNarrowing,
|
2408
2403
|
/* isComplexExpression */ true);
|
2409
2404
|
return isLeftNarrowable || isRightNarrowable;
|
2410
2405
|
}
|
2411
2406
|
return false;
|
2412
2407
|
}
|
2413
2408
|
case 55 /* ParseNodeType.UnaryOperation */: {
|
2414
|
-
return (expression.operator === 38 /* OperatorType.Not */ &&
|
2415
|
-
this._isNarrowingExpression(expression.
|
2409
|
+
return (expression.d.operator === 38 /* OperatorType.Not */ &&
|
2410
|
+
this._isNarrowingExpression(expression.d.expr, expressionList, filterForNeverNarrowing,
|
2416
2411
|
/* isComplexExpression */ false));
|
2417
2412
|
}
|
2418
2413
|
case 5 /* ParseNodeType.AugmentedAssignment */: {
|
2419
|
-
return this._isNarrowingExpression(expression.
|
2414
|
+
return this._isNarrowingExpression(expression.d.rightExpr, expressionList, filterForNeverNarrowing,
|
2420
2415
|
/* isComplexExpression */ true);
|
2421
2416
|
}
|
2422
2417
|
case 9 /* ParseNodeType.Call */: {
|
2423
|
-
if (expression.
|
2424
|
-
(expression.
|
2425
|
-
expression.
|
2426
|
-
expression.
|
2427
|
-
return this._isNarrowingExpression(expression.
|
2418
|
+
if (expression.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ &&
|
2419
|
+
(expression.d.leftExpr.d.value === 'isinstance' ||
|
2420
|
+
expression.d.leftExpr.d.value === 'issubclass') &&
|
2421
|
+
expression.d.args.length === 2) {
|
2422
|
+
return this._isNarrowingExpression(expression.d.args[0].d.valueExpr, expressionList, filterForNeverNarrowing,
|
2428
2423
|
/* isComplexExpression */ true);
|
2429
2424
|
}
|
2430
|
-
if (expression.
|
2431
|
-
expression.
|
2432
|
-
expression.
|
2433
|
-
return this._isNarrowingExpression(expression.
|
2425
|
+
if (expression.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ &&
|
2426
|
+
expression.d.leftExpr.d.value === 'callable' &&
|
2427
|
+
expression.d.args.length === 1) {
|
2428
|
+
return this._isNarrowingExpression(expression.d.args[0].d.valueExpr, expressionList, filterForNeverNarrowing,
|
2434
2429
|
/* isComplexExpression */ true);
|
2435
2430
|
}
|
2436
2431
|
// Is this potentially a call to a user-defined type guard function?
|
2437
|
-
if (expression.
|
2432
|
+
if (expression.d.args.length >= 1) {
|
2438
2433
|
// Never narrowing doesn't support type guards because they do not
|
2439
2434
|
// offer negative narrowing.
|
2440
2435
|
if (filterForNeverNarrowing) {
|
2441
2436
|
return false;
|
2442
2437
|
}
|
2443
|
-
return this._isNarrowingExpression(expression.
|
2438
|
+
return this._isNarrowingExpression(expression.d.args[0].d.valueExpr, expressionList, filterForNeverNarrowing,
|
2444
2439
|
/* isComplexExpression */ true);
|
2445
2440
|
}
|
2446
2441
|
}
|
@@ -2465,27 +2460,27 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2465
2460
|
break;
|
2466
2461
|
}
|
2467
2462
|
case 52 /* ParseNodeType.Tuple */: {
|
2468
|
-
target.
|
2463
|
+
target.d.items.forEach((expr) => {
|
2469
2464
|
this._createAssignmentTargetFlowNodes(expr, walkTargets, unbound);
|
2470
2465
|
});
|
2471
2466
|
break;
|
2472
2467
|
}
|
2473
2468
|
case 54 /* ParseNodeType.TypeAnnotation */: {
|
2474
|
-
this._createAssignmentTargetFlowNodes(target.
|
2469
|
+
this._createAssignmentTargetFlowNodes(target.d.valueExpr, /* walkTargets */ false, unbound);
|
2475
2470
|
if (walkTargets) {
|
2476
2471
|
this.walk(target);
|
2477
2472
|
}
|
2478
2473
|
break;
|
2479
2474
|
}
|
2480
2475
|
case 56 /* ParseNodeType.Unpack */: {
|
2481
|
-
this._createAssignmentTargetFlowNodes(target.
|
2476
|
+
this._createAssignmentTargetFlowNodes(target.d.expr, /* walkTargets */ false, unbound);
|
2482
2477
|
if (walkTargets) {
|
2483
2478
|
this.walk(target);
|
2484
2479
|
}
|
2485
2480
|
break;
|
2486
2481
|
}
|
2487
2482
|
case 34 /* ParseNodeType.List */: {
|
2488
|
-
target.
|
2483
|
+
target.d.items.forEach((entry) => {
|
2489
2484
|
this._createAssignmentTargetFlowNodes(entry, walkTargets, unbound);
|
2490
2485
|
});
|
2491
2486
|
break;
|
@@ -2522,7 +2517,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2522
2517
|
_createFlowAssignment(node, unbound = false) {
|
2523
2518
|
let targetSymbolId = symbol_1.indeterminateSymbolId;
|
2524
2519
|
if (node.nodeType === 38 /* ParseNodeType.Name */) {
|
2525
|
-
const symbolWithScope = this._currentScope.lookUpSymbolRecursive(node.value);
|
2520
|
+
const symbolWithScope = this._currentScope.lookUpSymbolRecursive(node.d.value);
|
2526
2521
|
(0, debug_1.assert)(symbolWithScope !== undefined);
|
2527
2522
|
targetSymbolId = symbolWithScope.symbol.id;
|
2528
2523
|
}
|
@@ -2577,7 +2572,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2577
2572
|
id: this._getUniqueFlowNodeId(),
|
2578
2573
|
node,
|
2579
2574
|
antecedent: this._currentFlowNode,
|
2580
|
-
subjectExpression: node.
|
2575
|
+
subjectExpression: node.d.expr,
|
2581
2576
|
};
|
2582
2577
|
this._currentFlowNode = flowNode;
|
2583
2578
|
}
|
@@ -2626,7 +2621,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2626
2621
|
}
|
2627
2622
|
}
|
2628
2623
|
_bindNameToScope(scope, node, addedSymbols) {
|
2629
|
-
return this._bindNameValueToScope(scope, node.value, addedSymbols);
|
2624
|
+
return this._bindNameValueToScope(scope, node.d.value, addedSymbols);
|
2630
2625
|
}
|
2631
2626
|
_bindNameValueToScope(scope, name, addedSymbols) {
|
2632
2627
|
// Is this name already bound to a scope other than the local one?
|
@@ -2685,23 +2680,23 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2685
2680
|
break;
|
2686
2681
|
}
|
2687
2682
|
case 52 /* ParseNodeType.Tuple */: {
|
2688
|
-
target.
|
2683
|
+
target.d.items.forEach((expr) => {
|
2689
2684
|
this._bindPossibleTupleNamedTarget(expr, addedSymbols);
|
2690
2685
|
});
|
2691
2686
|
break;
|
2692
2687
|
}
|
2693
2688
|
case 34 /* ParseNodeType.List */: {
|
2694
|
-
target.
|
2689
|
+
target.d.items.forEach((expr) => {
|
2695
2690
|
this._bindPossibleTupleNamedTarget(expr, addedSymbols);
|
2696
2691
|
});
|
2697
2692
|
break;
|
2698
2693
|
}
|
2699
2694
|
case 54 /* ParseNodeType.TypeAnnotation */: {
|
2700
|
-
this._bindPossibleTupleNamedTarget(target.
|
2695
|
+
this._bindPossibleTupleNamedTarget(target.d.valueExpr, addedSymbols);
|
2701
2696
|
break;
|
2702
2697
|
}
|
2703
2698
|
case 56 /* ParseNodeType.Unpack */: {
|
2704
|
-
this._bindPossibleTupleNamedTarget(target.
|
2699
|
+
this._bindPossibleTupleNamedTarget(target.d.expr, addedSymbols);
|
2705
2700
|
break;
|
2706
2701
|
}
|
2707
2702
|
}
|
@@ -2760,21 +2755,21 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2760
2755
|
switch (target.nodeType) {
|
2761
2756
|
case 38 /* ParseNodeType.Name */: {
|
2762
2757
|
const name = target;
|
2763
|
-
const symbolWithScope = this._currentScope.lookUpSymbolRecursive(name.value);
|
2758
|
+
const symbolWithScope = this._currentScope.lookUpSymbolRecursive(name.d.value);
|
2764
2759
|
if (symbolWithScope && symbolWithScope.symbol) {
|
2765
2760
|
const declaration = {
|
2766
2761
|
type: 1 /* DeclarationType.Variable */,
|
2767
2762
|
node: target,
|
2768
|
-
isConstant: (0, symbolNameUtils_1.isConstantName)(target.value),
|
2763
|
+
isConstant: (0, symbolNameUtils_1.isConstantName)(target.d.value),
|
2769
2764
|
inferredTypeSource: source,
|
2770
|
-
isInferenceAllowedInPyTyped: this._isInferenceAllowedInPyTyped(name.value),
|
2765
|
+
isInferenceAllowedInPyTyped: this._isInferenceAllowedInPyTyped(name.d.value),
|
2771
2766
|
typeAliasName: isPossibleTypeAlias ? target : undefined,
|
2772
2767
|
uri: this._fileInfo.fileUri,
|
2773
2768
|
range: (0, positionUtils_1.convertTextRangeToRange)(name, this._fileInfo.lines),
|
2774
2769
|
moduleName: this._fileInfo.moduleName,
|
2775
2770
|
isInExceptSuite: this._isInExceptSuite,
|
2776
2771
|
docString: this._getVariableDocString(target),
|
2777
|
-
isExplicitBinding: this._currentScope.getBindingType(name.value) !== undefined,
|
2772
|
+
isExplicitBinding: this._currentScope.getBindingType(name.d.value) !== undefined,
|
2778
2773
|
};
|
2779
2774
|
symbolWithScope.symbol.addDeclaration(declaration);
|
2780
2775
|
}
|
@@ -2783,12 +2778,12 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2783
2778
|
case 35 /* ParseNodeType.MemberAccess */: {
|
2784
2779
|
const memberAccessInfo = this._getMemberAccessInfo(target);
|
2785
2780
|
if (memberAccessInfo) {
|
2786
|
-
const name = target.
|
2787
|
-
let symbol = memberAccessInfo.classScope.lookUpSymbol(name.value);
|
2781
|
+
const name = target.d.member;
|
2782
|
+
let symbol = memberAccessInfo.classScope.lookUpSymbol(name.d.value);
|
2788
2783
|
if (!symbol) {
|
2789
|
-
symbol = memberAccessInfo.classScope.addSymbol(name.value, 1 /* SymbolFlags.InitiallyUnbound */);
|
2784
|
+
symbol = memberAccessInfo.classScope.addSymbol(name.d.value, 1 /* SymbolFlags.InitiallyUnbound */);
|
2790
2785
|
const honorPrivateNaming = this._fileInfo.diagnosticRuleSet.reportPrivateUsage !== 'none';
|
2791
|
-
if ((0, symbolNameUtils_1.isPrivateOrProtectedName)(name.value) && honorPrivateNaming) {
|
2786
|
+
if ((0, symbolNameUtils_1.isPrivateOrProtectedName)(name.d.value) && honorPrivateNaming) {
|
2792
2787
|
symbol.setIsPrivateMember();
|
2793
2788
|
}
|
2794
2789
|
}
|
@@ -2809,12 +2804,12 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2809
2804
|
}
|
2810
2805
|
const declaration = {
|
2811
2806
|
type: 1 /* DeclarationType.Variable */,
|
2812
|
-
node: target.
|
2813
|
-
isConstant: (0, symbolNameUtils_1.isConstantName)(name.value),
|
2807
|
+
node: target.d.member,
|
2808
|
+
isConstant: (0, symbolNameUtils_1.isConstantName)(name.d.value),
|
2814
2809
|
inferredTypeSource: source,
|
2815
2810
|
isDefinedByMemberAccess: true,
|
2816
2811
|
uri: this._fileInfo.fileUri,
|
2817
|
-
range: (0, positionUtils_1.convertTextRangeToRange)(target.
|
2812
|
+
range: (0, positionUtils_1.convertTextRangeToRange)(target.d.member, this._fileInfo.lines),
|
2818
2813
|
moduleName: this._fileInfo.moduleName,
|
2819
2814
|
isInExceptSuite: this._isInExceptSuite,
|
2820
2815
|
docString: this._getVariableDocString(target),
|
@@ -2824,21 +2819,21 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2824
2819
|
break;
|
2825
2820
|
}
|
2826
2821
|
case 52 /* ParseNodeType.Tuple */: {
|
2827
|
-
target.
|
2822
|
+
target.d.items.forEach((expr) => {
|
2828
2823
|
this._addInferredTypeAssignmentForVariable(expr, source);
|
2829
2824
|
});
|
2830
2825
|
break;
|
2831
2826
|
}
|
2832
2827
|
case 54 /* ParseNodeType.TypeAnnotation */: {
|
2833
|
-
this._addInferredTypeAssignmentForVariable(target.
|
2828
|
+
this._addInferredTypeAssignmentForVariable(target.d.valueExpr, source);
|
2834
2829
|
break;
|
2835
2830
|
}
|
2836
2831
|
case 56 /* ParseNodeType.Unpack */: {
|
2837
|
-
this._addInferredTypeAssignmentForVariable(target.
|
2832
|
+
this._addInferredTypeAssignmentForVariable(target.d.expr, source);
|
2838
2833
|
break;
|
2839
2834
|
}
|
2840
2835
|
case 34 /* ParseNodeType.List */: {
|
2841
|
-
target.
|
2836
|
+
target.d.items.forEach((entry) => {
|
2842
2837
|
this._addInferredTypeAssignmentForVariable(entry, source);
|
2843
2838
|
});
|
2844
2839
|
break;
|
@@ -2855,7 +2850,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2855
2850
|
switch (target.nodeType) {
|
2856
2851
|
case 38 /* ParseNodeType.Name */: {
|
2857
2852
|
const name = target;
|
2858
|
-
const symbolWithScope = this._currentScope.lookUpSymbolRecursive(name.value);
|
2853
|
+
const symbolWithScope = this._currentScope.lookUpSymbolRecursive(name.d.value);
|
2859
2854
|
if (symbolWithScope && symbolWithScope.symbol) {
|
2860
2855
|
const finalInfo = this._isAnnotationFinal(typeAnnotation);
|
2861
2856
|
let typeAnnotationNode = typeAnnotation;
|
@@ -2889,7 +2884,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2889
2884
|
const declaration = {
|
2890
2885
|
type: 1 /* DeclarationType.Variable */,
|
2891
2886
|
node: target,
|
2892
|
-
isConstant: (0, symbolNameUtils_1.isConstantName)(name.value),
|
2887
|
+
isConstant: (0, symbolNameUtils_1.isConstantName)(name.d.value),
|
2893
2888
|
isFinal: finalInfo.isFinal,
|
2894
2889
|
typeAliasName: target,
|
2895
2890
|
uri: this._fileInfo.fileUri,
|
@@ -2898,7 +2893,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2898
2893
|
moduleName: this._fileInfo.moduleName,
|
2899
2894
|
isInExceptSuite: this._isInExceptSuite,
|
2900
2895
|
docString: this._getVariableDocString(target),
|
2901
|
-
isExplicitBinding: this._currentScope.getBindingType(name.value) !== undefined,
|
2896
|
+
isExplicitBinding: this._currentScope.getBindingType(name.d.value) !== undefined,
|
2902
2897
|
};
|
2903
2898
|
symbolWithScope.symbol.addDeclaration(declaration);
|
2904
2899
|
if (isFinalAssignedInClassBody) {
|
@@ -2912,14 +2907,14 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2912
2907
|
}
|
2913
2908
|
// Look for an 'InitVar' either by itself or wrapped in an 'Annotated'.
|
2914
2909
|
if (typeAnnotation.nodeType === 27 /* ParseNodeType.Index */) {
|
2915
|
-
if (this._isDataclassesAnnotation(typeAnnotation.
|
2910
|
+
if (this._isDataclassesAnnotation(typeAnnotation.d.leftExpr, 'InitVar')) {
|
2916
2911
|
symbolWithScope.symbol.setIsInitVar();
|
2917
2912
|
}
|
2918
|
-
else if (this._isTypingAnnotation(typeAnnotation.
|
2919
|
-
typeAnnotation.items.length > 0) {
|
2920
|
-
const item0Expr = typeAnnotation.items[0].
|
2913
|
+
else if (this._isTypingAnnotation(typeAnnotation.d.leftExpr, 'Annotated') &&
|
2914
|
+
typeAnnotation.d.items.length > 0) {
|
2915
|
+
const item0Expr = typeAnnotation.d.items[0].d.valueExpr;
|
2921
2916
|
if (item0Expr.nodeType === 27 /* ParseNodeType.Index */ &&
|
2922
|
-
this._isDataclassesAnnotation(item0Expr.
|
2917
|
+
this._isDataclassesAnnotation(item0Expr.d.leftExpr, 'InitVar')) {
|
2923
2918
|
symbolWithScope.symbol.setIsInitVar();
|
2924
2919
|
}
|
2925
2920
|
}
|
@@ -2938,12 +2933,12 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2938
2933
|
// or an instance of the current class.
|
2939
2934
|
const memberAccessInfo = this._getMemberAccessInfo(target);
|
2940
2935
|
if (memberAccessInfo) {
|
2941
|
-
const name = target.
|
2942
|
-
let symbol = memberAccessInfo.classScope.lookUpSymbol(name.value);
|
2936
|
+
const name = target.d.member;
|
2937
|
+
let symbol = memberAccessInfo.classScope.lookUpSymbol(name.d.value);
|
2943
2938
|
if (!symbol) {
|
2944
|
-
symbol = memberAccessInfo.classScope.addSymbol(name.value, 1 /* SymbolFlags.InitiallyUnbound */);
|
2939
|
+
symbol = memberAccessInfo.classScope.addSymbol(name.d.value, 1 /* SymbolFlags.InitiallyUnbound */);
|
2945
2940
|
const honorPrivateNaming = this._fileInfo.diagnosticRuleSet.reportPrivateUsage !== 'none';
|
2946
|
-
if ((0, symbolNameUtils_1.isPrivateOrProtectedName)(name.value) && honorPrivateNaming) {
|
2941
|
+
if ((0, symbolNameUtils_1.isPrivateOrProtectedName)(name.d.value) && honorPrivateNaming) {
|
2947
2942
|
symbol.setIsPrivateMember();
|
2948
2943
|
}
|
2949
2944
|
}
|
@@ -2956,13 +2951,13 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2956
2951
|
const finalInfo = this._isAnnotationFinal(typeAnnotation);
|
2957
2952
|
const declaration = {
|
2958
2953
|
type: 1 /* DeclarationType.Variable */,
|
2959
|
-
node: target.
|
2960
|
-
isConstant: (0, symbolNameUtils_1.isConstantName)(name.value),
|
2954
|
+
node: target.d.member,
|
2955
|
+
isConstant: (0, symbolNameUtils_1.isConstantName)(name.d.value),
|
2961
2956
|
isDefinedByMemberAccess: true,
|
2962
2957
|
isFinal: finalInfo.isFinal,
|
2963
2958
|
uri: this._fileInfo.fileUri,
|
2964
2959
|
typeAnnotationNode: finalInfo.isFinal && !finalInfo.finalTypeNode ? undefined : typeAnnotation,
|
2965
|
-
range: (0, positionUtils_1.convertTextRangeToRange)(target.
|
2960
|
+
range: (0, positionUtils_1.convertTextRangeToRange)(target.d.member, this._fileInfo.lines),
|
2966
2961
|
moduleName: this._fileInfo.moduleName,
|
2967
2962
|
isInExceptSuite: this._isInExceptSuite,
|
2968
2963
|
docString: this._getVariableDocString(target),
|
@@ -2990,19 +2985,18 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2990
2985
|
_isKnownAnnotation(typeAnnotation, name, importAliases, symbolAliases) {
|
2991
2986
|
let annotationNode = typeAnnotation;
|
2992
2987
|
// Is this a quoted annotation?
|
2993
|
-
if (annotationNode.nodeType === 48 /* ParseNodeType.StringList */ && annotationNode.
|
2994
|
-
annotationNode = annotationNode.
|
2988
|
+
if (annotationNode.nodeType === 48 /* ParseNodeType.StringList */ && annotationNode.d.annotation) {
|
2989
|
+
annotationNode = annotationNode.d.annotation;
|
2995
2990
|
}
|
2996
2991
|
if (annotationNode.nodeType === 38 /* ParseNodeType.Name */) {
|
2997
|
-
const alias = symbolAliases.get(annotationNode.value);
|
2992
|
+
const alias = symbolAliases.get(annotationNode.d.value);
|
2998
2993
|
if (alias === name) {
|
2999
2994
|
return true;
|
3000
2995
|
}
|
3001
2996
|
}
|
3002
2997
|
else if (annotationNode.nodeType === 35 /* ParseNodeType.MemberAccess */) {
|
3003
|
-
if (annotationNode.
|
3004
|
-
annotationNode.
|
3005
|
-
const baseName = annotationNode.leftExpression.value;
|
2998
|
+
if (annotationNode.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ && annotationNode.d.member.d.value === name) {
|
2999
|
+
const baseName = annotationNode.d.leftExpr.d.value;
|
3006
3000
|
return importAliases.some((alias) => alias === baseName);
|
3007
3001
|
}
|
3008
3002
|
}
|
@@ -3014,12 +3008,12 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
3014
3008
|
return undefined;
|
3015
3009
|
}
|
3016
3010
|
// A docstring can consist of multiple joined strings in a single expression.
|
3017
|
-
const strings = docNode.strings;
|
3011
|
+
const strings = docNode.d.strings;
|
3018
3012
|
if (strings.length === 1) {
|
3019
3013
|
// Common case.
|
3020
|
-
return strings[0].value;
|
3014
|
+
return strings[0].d.value;
|
3021
3015
|
}
|
3022
|
-
return strings.map((s) => s.value).join('');
|
3016
|
+
return strings.map((s) => s.d.value).join('');
|
3023
3017
|
}
|
3024
3018
|
// Determines if the specified type annotation expression is a "Final".
|
3025
3019
|
// It returns a value indicating whether the expression is a "Final"
|
@@ -3038,19 +3032,19 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
3038
3032
|
isFinal = true;
|
3039
3033
|
}
|
3040
3034
|
else if (typeAnnotation.nodeType === 27 /* ParseNodeType.Index */ &&
|
3041
|
-
typeAnnotation.items.length > 0 &&
|
3042
|
-
this._isTypingAnnotation(typeAnnotation.
|
3043
|
-
return this._isAnnotationFinal(typeAnnotation.items[0].
|
3035
|
+
typeAnnotation.d.items.length > 0 &&
|
3036
|
+
this._isTypingAnnotation(typeAnnotation.d.leftExpr, 'Annotated')) {
|
3037
|
+
return this._isAnnotationFinal(typeAnnotation.d.items[0].d.valueExpr);
|
3044
3038
|
}
|
3045
|
-
else if (typeAnnotation.nodeType === 27 /* ParseNodeType.Index */ && typeAnnotation.items.length === 1) {
|
3039
|
+
else if (typeAnnotation.nodeType === 27 /* ParseNodeType.Index */ && typeAnnotation.d.items.length === 1) {
|
3046
3040
|
// Recursively call to see if the base expression is "Final".
|
3047
|
-
const finalInfo = this._isAnnotationFinal(typeAnnotation.
|
3041
|
+
const finalInfo = this._isAnnotationFinal(typeAnnotation.d.leftExpr);
|
3048
3042
|
if (finalInfo.isFinal &&
|
3049
|
-
typeAnnotation.items[0].
|
3050
|
-
!typeAnnotation.items[0].name &&
|
3051
|
-
!typeAnnotation.trailingComma) {
|
3043
|
+
typeAnnotation.d.items[0].d.argCategory === 0 /* ArgumentCategory.Simple */ &&
|
3044
|
+
!typeAnnotation.d.items[0].d.name &&
|
3045
|
+
!typeAnnotation.d.trailingComma) {
|
3052
3046
|
isFinal = true;
|
3053
|
-
finalTypeNode = typeAnnotation.items[0].
|
3047
|
+
finalTypeNode = typeAnnotation.d.items[0].d.valueExpr;
|
3054
3048
|
}
|
3055
3049
|
}
|
3056
3050
|
}
|
@@ -3064,27 +3058,27 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
3064
3058
|
let classVarTypeNode;
|
3065
3059
|
while (typeAnnotation) {
|
3066
3060
|
// Is this a quoted annotation?
|
3067
|
-
if (typeAnnotation.nodeType === 48 /* ParseNodeType.StringList */ && typeAnnotation.
|
3068
|
-
typeAnnotation = typeAnnotation.
|
3061
|
+
if (typeAnnotation.nodeType === 48 /* ParseNodeType.StringList */ && typeAnnotation.d.annotation) {
|
3062
|
+
typeAnnotation = typeAnnotation.d.annotation;
|
3069
3063
|
}
|
3070
3064
|
if (typeAnnotation.nodeType === 27 /* ParseNodeType.Index */ &&
|
3071
|
-
typeAnnotation.items.length > 0 &&
|
3072
|
-
this._isTypingAnnotation(typeAnnotation.
|
3073
|
-
typeAnnotation = typeAnnotation.items[0].
|
3065
|
+
typeAnnotation.d.items.length > 0 &&
|
3066
|
+
this._isTypingAnnotation(typeAnnotation.d.leftExpr, 'Annotated')) {
|
3067
|
+
typeAnnotation = typeAnnotation.d.items[0].d.valueExpr;
|
3074
3068
|
}
|
3075
3069
|
else if (this._isTypingAnnotation(typeAnnotation, 'ClassVar')) {
|
3076
3070
|
isClassVar = true;
|
3077
3071
|
break;
|
3078
3072
|
}
|
3079
|
-
else if (typeAnnotation.nodeType === 27 /* ParseNodeType.Index */ && typeAnnotation.items.length === 1) {
|
3073
|
+
else if (typeAnnotation.nodeType === 27 /* ParseNodeType.Index */ && typeAnnotation.d.items.length === 1) {
|
3080
3074
|
// Recursively call to see if the base expression is "ClassVar".
|
3081
|
-
const finalInfo = this._isAnnotationClassVar(typeAnnotation.
|
3075
|
+
const finalInfo = this._isAnnotationClassVar(typeAnnotation.d.leftExpr);
|
3082
3076
|
if (finalInfo.isClassVar &&
|
3083
|
-
typeAnnotation.items[0].
|
3084
|
-
!typeAnnotation.items[0].name &&
|
3085
|
-
!typeAnnotation.trailingComma) {
|
3077
|
+
typeAnnotation.d.items[0].d.argCategory === 0 /* ArgumentCategory.Simple */ &&
|
3078
|
+
!typeAnnotation.d.items[0].d.name &&
|
3079
|
+
!typeAnnotation.d.trailingComma) {
|
3086
3080
|
isClassVar = true;
|
3087
|
-
classVarTypeNode = typeAnnotation.items[0].
|
3081
|
+
classVarTypeNode = typeAnnotation.d.items[0].d.valueExpr;
|
3088
3082
|
}
|
3089
3083
|
break;
|
3090
3084
|
}
|
@@ -3100,10 +3094,10 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
3100
3094
|
_getMemberAccessInfo(node) {
|
3101
3095
|
// We handle only simple names on the left-hand side of the expression,
|
3102
3096
|
// not calls, nested member accesses, index expressions, etc.
|
3103
|
-
if (node.
|
3097
|
+
if (node.d.leftExpr.nodeType !== 38 /* ParseNodeType.Name */) {
|
3104
3098
|
return undefined;
|
3105
3099
|
}
|
3106
|
-
const leftSymbolName = node.
|
3100
|
+
const leftSymbolName = node.d.leftExpr.d.value;
|
3107
3101
|
// Make sure the expression is within a function (i.e. a method) that's
|
3108
3102
|
// within a class definition.
|
3109
3103
|
const methodNode = ParseTreeUtils.getEnclosingFunction(node);
|
@@ -3117,11 +3111,11 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
3117
3111
|
// Determine whether the left-hand side indicates a class or
|
3118
3112
|
// instance member.
|
3119
3113
|
let isInstanceMember = false;
|
3120
|
-
if (methodNode.
|
3114
|
+
if (methodNode.d.params.length < 1 || !methodNode.d.params[0].d.name) {
|
3121
3115
|
return undefined;
|
3122
3116
|
}
|
3123
|
-
const className = classNode.name.value;
|
3124
|
-
const firstParamName = methodNode.
|
3117
|
+
const className = classNode.d.name.d.value;
|
3118
|
+
const firstParamName = methodNode.d.params[0].d.name.d.value;
|
3125
3119
|
if (leftSymbolName === className) {
|
3126
3120
|
isInstanceMember = false;
|
3127
3121
|
}
|
@@ -3132,7 +3126,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
3132
3126
|
// To determine whether the first parameter of the method
|
3133
3127
|
// refers to the class or the instance, we need to apply
|
3134
3128
|
// some heuristics.
|
3135
|
-
if (methodNode.name.value === '__new__') {
|
3129
|
+
if (methodNode.d.name.d.value === '__new__') {
|
3136
3130
|
// The __new__ method is special. It acts as a classmethod even
|
3137
3131
|
// though it doesn't have a @classmethod decorator.
|
3138
3132
|
isInstanceMember = false;
|
@@ -3141,9 +3135,9 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
3141
3135
|
// Assume that it's an instance member unless we find
|
3142
3136
|
// a decorator that tells us otherwise.
|
3143
3137
|
isInstanceMember = true;
|
3144
|
-
for (const decorator of methodNode.decorators) {
|
3145
|
-
if (decorator.
|
3146
|
-
const decoratorName = decorator.
|
3138
|
+
for (const decorator of methodNode.d.decorators) {
|
3139
|
+
if (decorator.d.expr.nodeType === 38 /* ParseNodeType.Name */) {
|
3140
|
+
const decoratorName = decorator.d.expr.d.value;
|
3147
3141
|
if (decoratorName === 'staticmethod') {
|
3148
3142
|
// A static method doesn't have a "self" or "cls" parameter.
|
3149
3143
|
return undefined;
|
@@ -3198,15 +3192,15 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
3198
3192
|
annotationNode = node;
|
3199
3193
|
}
|
3200
3194
|
else {
|
3201
|
-
if (node.
|
3195
|
+
if (node.d.leftExpr.nodeType !== 54 /* ParseNodeType.TypeAnnotation */) {
|
3202
3196
|
return false;
|
3203
3197
|
}
|
3204
|
-
annotationNode = node.
|
3198
|
+
annotationNode = node.d.leftExpr;
|
3205
3199
|
}
|
3206
|
-
if (annotationNode.
|
3200
|
+
if (annotationNode.d.valueExpr.nodeType !== 38 /* ParseNodeType.Name */) {
|
3207
3201
|
return false;
|
3208
3202
|
}
|
3209
|
-
const assignedNameNode = annotationNode.
|
3203
|
+
const assignedNameNode = annotationNode.d.valueExpr;
|
3210
3204
|
const specialTypes = new Set([
|
3211
3205
|
'Tuple',
|
3212
3206
|
'Generic',
|
@@ -3231,7 +3225,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
3231
3225
|
'OrderedDict',
|
3232
3226
|
'TypeIs',
|
3233
3227
|
]);
|
3234
|
-
const assignedName = assignedNameNode.value;
|
3228
|
+
const assignedName = assignedNameNode.d.value;
|
3235
3229
|
if (!specialTypes.has(assignedName)) {
|
3236
3230
|
return false;
|
3237
3231
|
}
|
@@ -3243,7 +3237,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
3243
3237
|
moduleName: this._fileInfo.moduleName,
|
3244
3238
|
isInExceptSuite: this._isInExceptSuite,
|
3245
3239
|
};
|
3246
|
-
const symbol = this._bindNameToScope(this._currentScope, annotationNode.
|
3240
|
+
const symbol = this._bindNameToScope(this._currentScope, annotationNode.d.valueExpr);
|
3247
3241
|
if (symbol) {
|
3248
3242
|
symbol.addDeclaration(specialBuiltInClassDeclaration);
|
3249
3243
|
}
|
@@ -3276,7 +3270,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
3276
3270
|
this._addSyntaxError(localize_1.LocMessage.yieldOutsideFunction(), node);
|
3277
3271
|
}
|
3278
3272
|
}
|
3279
|
-
else if (functionNode.isAsync && node.nodeType === 61 /* ParseNodeType.YieldFrom */) {
|
3273
|
+
else if (functionNode.d.isAsync && node.nodeType === 61 /* ParseNodeType.YieldFrom */) {
|
3280
3274
|
// PEP 525 indicates that 'yield from' is not allowed in an
|
3281
3275
|
// async function.
|
3282
3276
|
this._addSyntaxError(localize_1.LocMessage.yieldFromOutsideAsync(), node);
|
@@ -3288,8 +3282,8 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
3288
3282
|
this._targetFunctionDeclaration.yieldStatements.push(node);
|
3289
3283
|
this._targetFunctionDeclaration.isGenerator = true;
|
3290
3284
|
}
|
3291
|
-
if (node.
|
3292
|
-
this.walk(node.
|
3285
|
+
if (node.d.expr) {
|
3286
|
+
this.walk(node.d.expr);
|
3293
3287
|
}
|
3294
3288
|
AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode);
|
3295
3289
|
}
|
@@ -3372,7 +3366,7 @@ class DummyScopeGenerator extends parseTreeWalker_1.ParseTreeWalker {
|
|
3372
3366
|
}
|
3373
3367
|
visitClass(node) {
|
3374
3368
|
const newScope = this._createNewScope(3 /* ScopeType.Class */, () => {
|
3375
|
-
this.walk(node.suite);
|
3369
|
+
this.walk(node.d.suite);
|
3376
3370
|
});
|
3377
3371
|
if (!AnalyzerNodeInfo.getScope(node)) {
|
3378
3372
|
AnalyzerNodeInfo.setScope(node, newScope);
|
@@ -3381,7 +3375,7 @@ class DummyScopeGenerator extends parseTreeWalker_1.ParseTreeWalker {
|
|
3381
3375
|
}
|
3382
3376
|
visitFunction(node) {
|
3383
3377
|
const newScope = this._createNewScope(2 /* ScopeType.Function */, () => {
|
3384
|
-
this.walk(node.suite);
|
3378
|
+
this.walk(node.d.suite);
|
3385
3379
|
});
|
3386
3380
|
if (!AnalyzerNodeInfo.getScope(node)) {
|
3387
3381
|
AnalyzerNodeInfo.setScope(node, newScope);
|