@zzzen/pyright-internal 1.2.0-dev.20241020 → 1.2.0-dev.20241027
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/binder.js +61 -37
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +11 -1
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/dataClasses.js +1 -17
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declarationUtils.js +1 -3
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/operations.js +2 -2
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.js +4 -0
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/service.js +5 -5
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/symbol.d.ts +8 -3
- package/dist/analyzer/symbol.js +4 -4
- package/dist/analyzer/symbol.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +101 -64
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +1 -5
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +3 -5
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.d.ts +1 -1
- package/dist/analyzer/typePrinter.js +17 -17
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +2 -1
- package/dist/analyzer/typeUtils.js +17 -6
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +1 -1
- package/dist/analyzer/types.js +3 -1
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/configOptions.d.ts +1 -1
- package/dist/common/configOptions.js +4 -3
- package/dist/common/configOptions.js.map +1 -1
- package/dist/languageService/completionProvider.js +2 -2
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.d.ts +2 -0
- package/dist/languageService/definitionProvider.js +21 -5
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/hoverProvider.js +5 -4
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +4 -0
- package/dist/localization/localize.js +10 -1
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +3 -1
- package/dist/localization/package.nls.de.json +2 -0
- package/dist/localization/package.nls.en-us.json +4 -0
- package/dist/localization/package.nls.es.json +2 -0
- package/dist/localization/package.nls.fr.json +2 -0
- package/dist/localization/package.nls.it.json +3 -1
- package/dist/localization/package.nls.ja.json +2 -0
- package/dist/localization/package.nls.ko.json +2 -0
- package/dist/localization/package.nls.pl.json +2 -0
- package/dist/localization/package.nls.pt-br.json +3 -1
- package/dist/localization/package.nls.qps-ploc.json +3 -1
- package/dist/localization/package.nls.ru.json +3 -1
- package/dist/localization/package.nls.tr.json +2 -0
- package/dist/localization/package.nls.zh-cn.json +2 -0
- package/dist/localization/package.nls.zh-tw.json +3 -1
- package/dist/server.d.ts +1 -2
- package/dist/tests/fourslash/import.multipart2.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/import.multipart2.fourslash.js +20 -0
- package/dist/tests/fourslash/import.multipart2.fourslash.js.map +1 -0
- package/dist/tests/typeEvaluator2.test.js +4 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +4 -0
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +3 -3
- package/dist/tests/typeEvaluator5.test.js +1 -1
- package/package.json +2 -2
package/dist/analyzer/binder.js
CHANGED
@@ -2242,7 +2242,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2242
2242
|
// Limit only to expressions that contain a narrowable subexpression
|
2243
2243
|
// that is a name. This avoids complexities with composite expressions like
|
2244
2244
|
// member access or index expressions.
|
2245
|
-
if (this._isNarrowingExpression(node, expressionList,
|
2245
|
+
if (this._isNarrowingExpression(node, expressionList, { filterForNeverNarrowing: true })) {
|
2246
2246
|
const filteredExprList = expressionList.filter((expr) => expr.nodeType === 38 /* ParseNodeType.Name */);
|
2247
2247
|
if (filteredExprList.length > 0) {
|
2248
2248
|
this._currentFlowNode = this._createFlowConditional(isPositiveTest ? codeFlowTypes_1.FlowFlags.TrueNeverCondition : codeFlowTypes_1.FlowFlags.FalseNeverCondition, this._currentFlowNode, node);
|
@@ -2282,10 +2282,9 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2282
2282
|
return Binder._unreachableFlowNode;
|
2283
2283
|
}
|
2284
2284
|
const expressionList = [];
|
2285
|
-
if (!this._isNarrowingExpression(expression, expressionList,
|
2286
|
-
|
2287
|
-
|
2288
|
-
0)) {
|
2285
|
+
if (!this._isNarrowingExpression(expression, expressionList, {
|
2286
|
+
filterForNeverNarrowing: (flags & (codeFlowTypes_1.FlowFlags.TrueNeverCondition | codeFlowTypes_1.FlowFlags.FalseNeverCondition)) !== 0,
|
2287
|
+
})) {
|
2289
2288
|
return antecedent;
|
2290
2289
|
}
|
2291
2290
|
expressionList.forEach((expr) => {
|
@@ -2324,12 +2323,12 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2324
2323
|
// The isComplexExpression parameter is used internally to determine whether
|
2325
2324
|
// the call is an atom (name, member access, index - plus a "not" form of
|
2326
2325
|
// these) or something more complex (binary operator, call, etc.).
|
2327
|
-
_isNarrowingExpression(expression, expressionList,
|
2326
|
+
_isNarrowingExpression(expression, expressionList, options = {}) {
|
2328
2327
|
switch (expression.nodeType) {
|
2329
2328
|
case 38 /* ParseNodeType.Name */:
|
2330
2329
|
case 35 /* ParseNodeType.MemberAccess */:
|
2331
2330
|
case 27 /* ParseNodeType.Index */: {
|
2332
|
-
if (filterForNeverNarrowing) {
|
2331
|
+
if (options.filterForNeverNarrowing) {
|
2333
2332
|
// Never narrowing doesn't support member access or index
|
2334
2333
|
// expressions.
|
2335
2334
|
if (expression.nodeType !== 38 /* ParseNodeType.Name */) {
|
@@ -2338,17 +2337,17 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2338
2337
|
// Never narrowing doesn't support simple names (falsy
|
2339
2338
|
// or truthy narrowing) because it's too expensive and
|
2340
2339
|
// provides relatively little utility.
|
2341
|
-
if (!isComplexExpression) {
|
2340
|
+
if (!options.isComplexExpression) {
|
2342
2341
|
return false;
|
2343
2342
|
}
|
2344
2343
|
}
|
2345
2344
|
if ((0, codeFlowTypes_1.isCodeFlowSupportedForReference)(expression)) {
|
2346
2345
|
expressionList.push(expression);
|
2347
|
-
if (!filterForNeverNarrowing) {
|
2346
|
+
if (!options.filterForNeverNarrowing) {
|
2348
2347
|
// If the expression is a member access expression, add its
|
2349
2348
|
// leftExpression to the expression list because that expression
|
2350
2349
|
// can be narrowed based on the attribute type.
|
2351
|
-
if (expression.nodeType === 35 /* ParseNodeType.MemberAccess */) {
|
2350
|
+
if (expression.nodeType === 35 /* ParseNodeType.MemberAccess */ && options.allowDiscriminatedNarrowing) {
|
2352
2351
|
if ((0, codeFlowTypes_1.isCodeFlowSupportedForReference)(expression.d.leftExpr)) {
|
2353
2352
|
expressionList.push(expression.d.leftExpr);
|
2354
2353
|
}
|
@@ -2371,8 +2370,10 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2371
2370
|
}
|
2372
2371
|
case 4 /* ParseNodeType.AssignmentExpression */: {
|
2373
2372
|
expressionList.push(expression.d.name);
|
2374
|
-
this._isNarrowingExpression(expression.d.rightExpr, expressionList,
|
2375
|
-
|
2373
|
+
this._isNarrowingExpression(expression.d.rightExpr, expressionList, {
|
2374
|
+
...options,
|
2375
|
+
isComplexExpression: true,
|
2376
|
+
});
|
2376
2377
|
return true;
|
2377
2378
|
}
|
2378
2379
|
case 7 /* ParseNodeType.BinaryOperation */: {
|
@@ -2383,8 +2384,11 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2383
2384
|
// These are commonly-used patterns used in control flow.
|
2384
2385
|
if (expression.d.rightExpr.nodeType === 14 /* ParseNodeType.Constant */ &&
|
2385
2386
|
expression.d.rightExpr.d.constType === 26 /* KeywordType.None */) {
|
2386
|
-
return this._isNarrowingExpression(expression.d.leftExpr, expressionList,
|
2387
|
-
|
2387
|
+
return this._isNarrowingExpression(expression.d.leftExpr, expressionList, {
|
2388
|
+
...options,
|
2389
|
+
isComplexExpression: true,
|
2390
|
+
allowDiscriminatedNarrowing: true,
|
2391
|
+
});
|
2388
2392
|
}
|
2389
2393
|
// Look for "type(X) is Y" or "type(X) is not Y".
|
2390
2394
|
if (isOrIsNotOperator &&
|
@@ -2393,11 +2397,13 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2393
2397
|
expression.d.leftExpr.d.leftExpr.d.value === 'type' &&
|
2394
2398
|
expression.d.leftExpr.d.args.length === 1 &&
|
2395
2399
|
expression.d.leftExpr.d.args[0].d.argCategory === 0 /* ArgCategory.Simple */) {
|
2396
|
-
return this._isNarrowingExpression(expression.d.leftExpr.d.args[0].d.valueExpr, expressionList,
|
2397
|
-
/* isComplexExpression */ true);
|
2400
|
+
return this._isNarrowingExpression(expression.d.leftExpr.d.args[0].d.valueExpr, expressionList, { ...options, isComplexExpression: true });
|
2398
2401
|
}
|
2399
|
-
const isLeftNarrowing = this._isNarrowingExpression(expression.d.leftExpr, expressionList,
|
2400
|
-
|
2402
|
+
const isLeftNarrowing = this._isNarrowingExpression(expression.d.leftExpr, expressionList, {
|
2403
|
+
...options,
|
2404
|
+
isComplexExpression: true,
|
2405
|
+
allowDiscriminatedNarrowing: true,
|
2406
|
+
});
|
2401
2407
|
// Look for "X is Y" or "X is not Y".
|
2402
2408
|
// Look for X == <literal> or X != <literal>
|
2403
2409
|
// Look for len(X) == <literal> or len(X) != <literal>
|
@@ -2409,61 +2415,79 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2409
2415
|
expression.d.operator === 21 /* OperatorType.LessThanOrEqual */ ||
|
2410
2416
|
expression.d.operator === 15 /* OperatorType.GreaterThan */ ||
|
2411
2417
|
expression.d.operator === 16 /* OperatorType.GreaterThanOrEqual */) {
|
2412
|
-
const isLeftNarrowing = this._isNarrowingExpression(expression.d.leftExpr, expressionList,
|
2413
|
-
|
2418
|
+
const isLeftNarrowing = this._isNarrowingExpression(expression.d.leftExpr, expressionList, {
|
2419
|
+
...options,
|
2420
|
+
isComplexExpression: true,
|
2421
|
+
});
|
2414
2422
|
return isLeftNarrowing;
|
2415
2423
|
}
|
2416
2424
|
}
|
2417
2425
|
// Look for "<string> in Y" or "<string> not in Y".
|
2418
2426
|
if (expression.d.operator === 41 /* OperatorType.In */ || expression.d.operator === 42 /* OperatorType.NotIn */) {
|
2419
2427
|
if (expression.d.leftExpr.nodeType === 48 /* ParseNodeType.StringList */ &&
|
2420
|
-
this._isNarrowingExpression(expression.d.rightExpr, expressionList,
|
2421
|
-
|
2428
|
+
this._isNarrowingExpression(expression.d.rightExpr, expressionList, {
|
2429
|
+
...options,
|
2430
|
+
isComplexExpression: true,
|
2431
|
+
})) {
|
2422
2432
|
return true;
|
2423
2433
|
}
|
2424
2434
|
}
|
2425
2435
|
// Look for "X in Y" or "X not in Y".
|
2426
2436
|
if (expression.d.operator === 41 /* OperatorType.In */ || expression.d.operator === 42 /* OperatorType.NotIn */) {
|
2427
|
-
const isLeftNarrowable = this._isNarrowingExpression(expression.d.leftExpr, expressionList,
|
2428
|
-
|
2429
|
-
|
2430
|
-
|
2437
|
+
const isLeftNarrowable = this._isNarrowingExpression(expression.d.leftExpr, expressionList, {
|
2438
|
+
...options,
|
2439
|
+
isComplexExpression: true,
|
2440
|
+
});
|
2441
|
+
const isRightNarrowable = this._isNarrowingExpression(expression.d.rightExpr, expressionList, {
|
2442
|
+
...options,
|
2443
|
+
isComplexExpression: true,
|
2444
|
+
});
|
2431
2445
|
return isLeftNarrowable || isRightNarrowable;
|
2432
2446
|
}
|
2433
2447
|
return false;
|
2434
2448
|
}
|
2435
2449
|
case 55 /* ParseNodeType.UnaryOperation */: {
|
2436
2450
|
return (expression.d.operator === 38 /* OperatorType.Not */ &&
|
2437
|
-
this._isNarrowingExpression(expression.d.expr, expressionList,
|
2438
|
-
|
2451
|
+
this._isNarrowingExpression(expression.d.expr, expressionList, {
|
2452
|
+
...options,
|
2453
|
+
isComplexExpression: false,
|
2454
|
+
}));
|
2439
2455
|
}
|
2440
2456
|
case 5 /* ParseNodeType.AugmentedAssignment */: {
|
2441
|
-
return this._isNarrowingExpression(expression.d.rightExpr, expressionList,
|
2442
|
-
|
2457
|
+
return this._isNarrowingExpression(expression.d.rightExpr, expressionList, {
|
2458
|
+
...options,
|
2459
|
+
isComplexExpression: true,
|
2460
|
+
});
|
2443
2461
|
}
|
2444
2462
|
case 9 /* ParseNodeType.Call */: {
|
2445
2463
|
if (expression.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ &&
|
2446
2464
|
(expression.d.leftExpr.d.value === 'isinstance' ||
|
2447
2465
|
expression.d.leftExpr.d.value === 'issubclass') &&
|
2448
2466
|
expression.d.args.length === 2) {
|
2449
|
-
return this._isNarrowingExpression(expression.d.args[0].d.valueExpr, expressionList,
|
2450
|
-
|
2467
|
+
return this._isNarrowingExpression(expression.d.args[0].d.valueExpr, expressionList, {
|
2468
|
+
...options,
|
2469
|
+
isComplexExpression: true,
|
2470
|
+
});
|
2451
2471
|
}
|
2452
2472
|
if (expression.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ &&
|
2453
2473
|
expression.d.leftExpr.d.value === 'callable' &&
|
2454
2474
|
expression.d.args.length === 1) {
|
2455
|
-
return this._isNarrowingExpression(expression.d.args[0].d.valueExpr, expressionList,
|
2456
|
-
|
2475
|
+
return this._isNarrowingExpression(expression.d.args[0].d.valueExpr, expressionList, {
|
2476
|
+
...options,
|
2477
|
+
isComplexExpression: true,
|
2478
|
+
});
|
2457
2479
|
}
|
2458
2480
|
// Is this potentially a call to a user-defined type guard function?
|
2459
2481
|
if (expression.d.args.length >= 1) {
|
2460
2482
|
// Never narrowing doesn't support type guards because they do not
|
2461
2483
|
// offer negative narrowing.
|
2462
|
-
if (filterForNeverNarrowing) {
|
2484
|
+
if (options.filterForNeverNarrowing) {
|
2463
2485
|
return false;
|
2464
2486
|
}
|
2465
|
-
return this._isNarrowingExpression(expression.d.args[0].d.valueExpr, expressionList,
|
2466
|
-
|
2487
|
+
return this._isNarrowingExpression(expression.d.args[0].d.valueExpr, expressionList, {
|
2488
|
+
...options,
|
2489
|
+
isComplexExpression: true,
|
2490
|
+
});
|
2467
2491
|
}
|
2468
2492
|
}
|
2469
2493
|
}
|