@zzzen/pyright-internal 1.2.0-dev.20260726 → 1.2.0-dev.20260809
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/analyzerNodeInfo.d.ts +4 -1
- package/dist/analyzer/analyzerNodeInfo.js +13 -0
- package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
- package/dist/analyzer/binder.js +6 -0
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +34 -15
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/declaration.d.ts +2 -2
- package/dist/analyzer/declaration.js.map +1 -1
- package/dist/analyzer/patternMatching.js +23 -1
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/typeGuards.js +26 -21
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +4 -0
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +12 -0
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ClassNode, ComprehensionNode, ExecutionScopeNode, FunctionNode, LambdaNode, ModuleNode, ParseNode, StringNode } from '../parser/parseNodes';
|
|
1
|
+
import { ClassNode, ComprehensionNode, ExecutionScopeNode, FunctionNode, IfNode, LambdaNode, ModuleNode, ParseNode, StringNode } from '../parser/parseNodes';
|
|
2
2
|
import { AnalyzerFileInfo } from './analyzerFileInfo';
|
|
3
3
|
import { FlowNode } from './codeFlowTypes';
|
|
4
4
|
import { Declaration } from './declaration';
|
|
@@ -18,6 +18,7 @@ export interface AnalyzerNodeInfo {
|
|
|
18
18
|
fileInfo?: AnalyzerFileInfo;
|
|
19
19
|
codeFlowExpressions?: Set<string>;
|
|
20
20
|
codeFlowComplexity?: number;
|
|
21
|
+
staticConditionValue?: boolean;
|
|
21
22
|
dunderAllInfo?: DunderAllInfo | undefined;
|
|
22
23
|
}
|
|
23
24
|
export type ScopedNode = ModuleNode | ClassNode | FunctionNode | LambdaNode | ComprehensionNode;
|
|
@@ -38,6 +39,8 @@ export declare function getCodeFlowExpressions(node: ExecutionScopeNode): Set<st
|
|
|
38
39
|
export declare function setCodeFlowExpressions(node: ExecutionScopeNode, expressions: Set<string>): void;
|
|
39
40
|
export declare function getCodeFlowComplexity(node: ExecutionScopeNode): number;
|
|
40
41
|
export declare function setCodeFlowComplexity(node: ExecutionScopeNode, complexity: number): void;
|
|
42
|
+
export declare function getStaticConditionValue(node: IfNode): boolean | undefined;
|
|
43
|
+
export declare function setStaticConditionValue(node: IfNode, value: boolean | undefined): void;
|
|
41
44
|
export declare function getDunderAllInfo(node: ModuleNode): DunderAllInfo | undefined;
|
|
42
45
|
export declare function setDunderAllInfo(node: ModuleNode, names: DunderAllInfo | undefined): void;
|
|
43
46
|
export declare function isCodeUnreachable(node: ParseNode): boolean;
|
|
@@ -28,6 +28,8 @@ exports.getCodeFlowExpressions = getCodeFlowExpressions;
|
|
|
28
28
|
exports.setCodeFlowExpressions = setCodeFlowExpressions;
|
|
29
29
|
exports.getCodeFlowComplexity = getCodeFlowComplexity;
|
|
30
30
|
exports.setCodeFlowComplexity = setCodeFlowComplexity;
|
|
31
|
+
exports.getStaticConditionValue = getStaticConditionValue;
|
|
32
|
+
exports.setStaticConditionValue = setStaticConditionValue;
|
|
31
33
|
exports.getDunderAllInfo = getDunderAllInfo;
|
|
32
34
|
exports.setDunderAllInfo = setDunderAllInfo;
|
|
33
35
|
exports.isCodeUnreachable = isCodeUnreachable;
|
|
@@ -57,6 +59,9 @@ function cleanNodeAnalysisInfo(node) {
|
|
|
57
59
|
if (info?.codeFlowComplexity) {
|
|
58
60
|
info.codeFlowComplexity = undefined;
|
|
59
61
|
}
|
|
62
|
+
if (info?.staticConditionValue !== undefined) {
|
|
63
|
+
info.staticConditionValue = undefined;
|
|
64
|
+
}
|
|
60
65
|
if (info?.dunderAllInfo) {
|
|
61
66
|
info.dunderAllInfo = undefined;
|
|
62
67
|
}
|
|
@@ -128,6 +133,14 @@ function setCodeFlowComplexity(node, complexity) {
|
|
|
128
133
|
const info = getAnalyzerInfoForWrite(node);
|
|
129
134
|
info.codeFlowComplexity = complexity;
|
|
130
135
|
}
|
|
136
|
+
function getStaticConditionValue(node) {
|
|
137
|
+
const info = getAnalyzerInfo(node);
|
|
138
|
+
return info?.staticConditionValue;
|
|
139
|
+
}
|
|
140
|
+
function setStaticConditionValue(node, value) {
|
|
141
|
+
const info = getAnalyzerInfoForWrite(node);
|
|
142
|
+
info.staticConditionValue = value;
|
|
143
|
+
}
|
|
131
144
|
function getDunderAllInfo(node) {
|
|
132
145
|
const info = getAnalyzerInfo(node);
|
|
133
146
|
return info?.dunderAllInfo;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyzerNodeInfo.js","sourceRoot":"","sources":["../../../../../src/analyzer/analyzerNodeInfo.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;
|
|
1
|
+
{"version":3,"file":"analyzerNodeInfo.js","sourceRoot":"","sources":["../../../../../src/analyzer/analyzerNodeInfo.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;AAwEH,sDAqCC;AAED,sCAGC;AAED,sCAGC;AAED,4BAGC;AAED,4BAGC;AAED,wCAGC;AAED,wCAGC;AAED,kCAGC;AAED,kCAGC;AAED,4CAGC;AAED,4CAGC;AAED,kCAMC;AAED,kCAGC;AAED,wDAGC;AAED,wDAGC;AAED,sDAGC;AAED,sDAGC;AAED,0DAGC;AAED,0DAGC;AAED,4CAGC;AAED,4CAGC;AAED,8CAcC;AArND,mDAAsD;AAuDtD,8DAA8D;AAC9D,iCAAiC;AACjC,SAAgB,qBAAqB,CAAC,IAAe;IACjD,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACnC,IAAI,IAAI,EAAE,KAAK,EAAE,CAAC;QACd,IAAI,CAAC,KAAK,GAAG,S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;IACnC,OAAO,IAAI,EAAE,aAAa,CAAC;AAC/B,CAAC;AAED,SAAgB,gBAAgB,CAAC,IAAgB,EAAE,KAAgC;IAC/E,MAAM,IAAI,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAC;IAC3C,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;AAC/B,CAAC;AAED,SAAgB,iBAAiB,CAAC,IAAe;IAC7C,IAAI,OAAO,GAA0B,IAAI,CAAC;IAE1C,mDAAmD;IACnD,2BAA2B;IAC3B,OAAO,OAAO,EAAE,CAAC;QACb,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;QACtC,IAAI,QAAQ,EAAE,CAAC;YACX,OAAO,CAAC,QAAQ,CAAC,KAAK,GAAG,CAAC,yBAAS,CAAC,0BAA0B,GAAG,yBAAS,CAAC,qBAAqB,CAAC,CAAC,KAAK,CAAC,CAAC;QAC7G,CAAC;QACD,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAC7B,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAS,eAAe,CAAC,IAAe;IACpC,OAAO,IAAI,CAAC,CAAiC,CAAC;AAClD,CAAC;AAED,SAAS,uBAAuB,CAAC,IAAe;IAC5C,IAAI,IAAI,GAAG,IAAI,CAAC,CAAiC,CAAC;IAClD,IAAI,CAAC,IAAI,EAAE,CAAC;QACR,IAAI,CAAC,CAAC,GAAG,IAAI,GAAG,EAAE,CAAC;IACvB,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC"}
|
package/dist/analyzer/binder.js
CHANGED
|
@@ -443,6 +443,11 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
|
443
443
|
/* proxyScope */ undefined,
|
|
444
444
|
/* chainedModuleLevelScopeLookup */ undefined, () => {
|
|
445
445
|
AnalyzerNodeInfo.setScope(node, this._currentScope);
|
|
446
|
+
const enclosingClass = ParseTreeUtils.getEnclosingClass(node);
|
|
447
|
+
if (enclosingClass) {
|
|
448
|
+
// Lambdas create the same implicit __class__ closure as named functions.
|
|
449
|
+
this._addImplicitSymbolToCurrentScope('__class__', node, '__class__');
|
|
450
|
+
}
|
|
446
451
|
this._deferBinding(() => {
|
|
447
452
|
// Create a start node for the lambda.
|
|
448
453
|
this._currentFlowNode = this._createStartFlowNode();
|
|
@@ -1051,6 +1056,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
|
1051
1056
|
// Determine if the test condition is always true or always false. If so,
|
|
1052
1057
|
// we can treat either the then or the else clause as unconditional.
|
|
1053
1058
|
const constExprValue = StaticExpressions.evaluateStaticBoolLikeExpression(node.d.testExpr, this._fileInfo.executionEnvironment, this._fileInfo.definedConstants, this._typingImportAliases, this._sysImportAliases);
|
|
1059
|
+
AnalyzerNodeInfo.setStaticConditionValue(node, constExprValue);
|
|
1054
1060
|
this._bindConditional(node.d.testExpr, thenLabel, elseLabel);
|
|
1055
1061
|
// Handle the if clause.
|
|
1056
1062
|
this._currentFlowNode =
|