@zzzen/pyright-internal 1.2.0-dev.20241027 → 1.2.0-dev.20241110
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.d.ts +2 -3
- package/dist/analyzer/binder.js +36 -21
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +11 -7
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +2 -2
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +18 -1
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.js +1 -1
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +0 -4
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declaration.d.ts +1 -1
- package/dist/analyzer/declaration.js.map +1 -1
- package/dist/analyzer/enums.js +3 -1
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +1 -1
- package/dist/analyzer/importResolver.js +5 -5
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/operations.js +6 -0
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/parameterUtils.js +2 -0
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +4 -2
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/protocols.js +1 -1
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/service.js +1 -1
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/serviceUtils.d.ts +0 -2
- package/dist/analyzer/serviceUtils.js +3 -5
- package/dist/analyzer/serviceUtils.js.map +1 -1
- package/dist/analyzer/sourceFile.js +1 -1
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/tuples.d.ts +2 -2
- package/dist/analyzer/typeEvaluator.js +153 -43
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -1
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +10 -5
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +6 -0
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +0 -1
- package/dist/analyzer/typeUtils.js +51 -30
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.d.ts +2 -1
- package/dist/analyzer/typedDicts.js +21 -1
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.js +4 -5
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/pathConsts.d.ts +3 -0
- package/dist/common/pathConsts.js +4 -1
- package/dist/common/pathConsts.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +6 -2
- package/dist/languageService/autoImporter.js +15 -15
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/completionProvider.js +4 -2
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/fileWatcherDynamicFeature.js +2 -2
- package/dist/languageService/fileWatcherDynamicFeature.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +2 -1
- package/dist/languageService/hoverProvider.js +33 -10
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.js +21 -13
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +5 -4
- package/dist/localization/localize.js +5 -2
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +1 -2
- package/dist/localization/package.nls.de.json +2 -3
- package/dist/localization/package.nls.en-us.json +19 -4
- package/dist/localization/package.nls.es.json +2 -3
- package/dist/localization/package.nls.fr.json +1 -2
- package/dist/localization/package.nls.it.json +2 -3
- package/dist/localization/package.nls.ja.json +1 -2
- package/dist/localization/package.nls.ko.json +1 -2
- package/dist/localization/package.nls.pl.json +1 -2
- package/dist/localization/package.nls.pt-br.json +1 -2
- package/dist/localization/package.nls.qps-ploc.json +1 -2
- package/dist/localization/package.nls.ru.json +1 -2
- package/dist/localization/package.nls.tr.json +1 -2
- package/dist/localization/package.nls.zh-cn.json +1 -2
- package/dist/localization/package.nls.zh-tw.json +1 -2
- package/dist/parser/parseNodes.d.ts +3 -2
- package/dist/parser/parseNodes.js +2 -1
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.d.ts +2 -1
- package/dist/parser/parser.js +36 -7
- package/dist/parser/parser.js.map +1 -1
- package/dist/tests/fourslash/hover.typedDict.get.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.typedDict.get.fourslash.js +16 -0
- package/dist/tests/fourslash/hover.typedDict.get.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.dataclassAlias.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/signature.dataclassAlias.fourslash.js +73 -0
- package/dist/tests/fourslash/signature.dataclassAlias.fourslash.js.map +1 -0
- package/dist/tests/harness/fourslash/testState.js +14 -1
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/fourslash/testStateUtils.js +2 -2
- package/dist/tests/harness/fourslash/testStateUtils.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +4 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +6 -2
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +1 -1
- package/dist/tests/typeEvaluator5.test.js +7 -1
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/typeEvaluator6.test.js +17 -1
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +13 -3
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typeEvaluator8.test.js +4 -0
- package/dist/tests/typeEvaluator8.test.js.map +1 -1
- package/package.json +1 -1
@@ -1,10 +1,8 @@
|
|
1
|
-
import { DocStringService } from '../common/docStringService';
|
2
1
|
import { AssertNode, AssignmentExpressionNode, AssignmentNode, AugmentedAssignmentNode, AwaitNode, BinaryOperationNode, BreakNode, CallNode, ClassNode, ComprehensionNode, ContinueNode, DelNode, ExceptNode, ForNode, FunctionNode, GlobalNode, IfNode, ImportAsNode, ImportFromNode, IndexNode, LambdaNode, MatchNode, MemberAccessNode, ModuleNameNode, ModuleNode, NameNode, NonlocalNode, ParseNode, PatternAsNode, PatternCaptureNode, PatternMappingExpandEntryNode, RaiseNode, ReturnNode, SuiteNode, TernaryNode, TryNode, TypeAliasNode, TypeAnnotationNode, TypeParameterListNode, UnaryOperationNode, WhileNode, WithNode, YieldFromNode, YieldNode } from '../parser/parseNodes';
|
3
2
|
import { AnalyzerFileInfo } from './analyzerFileInfo';
|
4
3
|
import { ParseTreeWalker } from './parseTreeWalker';
|
5
4
|
import { Scope } from './scope';
|
6
5
|
export declare class Binder extends ParseTreeWalker {
|
7
|
-
private _docStringService;
|
8
6
|
private _moduleSymbolOnly;
|
9
7
|
private readonly _fileInfo;
|
10
8
|
private _deferredBindingTasks;
|
@@ -19,6 +17,7 @@ export declare class Binder extends ParseTreeWalker {
|
|
19
17
|
private _finallyTargets;
|
20
18
|
private _currentReturnTarget;
|
21
19
|
private _currentScopeCodeFlowExpressions;
|
20
|
+
private _currentMatchSubjExpr;
|
22
21
|
private _typingImportAliases;
|
23
22
|
private _sysImportAliases;
|
24
23
|
private _dataclassesImportAliases;
|
@@ -34,7 +33,7 @@ export declare class Binder extends ParseTreeWalker {
|
|
34
33
|
private _potentialHiddenSymbols;
|
35
34
|
private _potentialPrivateSymbols;
|
36
35
|
private _codeFlowComplexity;
|
37
|
-
constructor(fileInfo: AnalyzerFileInfo,
|
36
|
+
constructor(fileInfo: AnalyzerFileInfo, _moduleSymbolOnly?: boolean);
|
38
37
|
bindModule(node: ModuleNode): void;
|
39
38
|
visitModule(node: ModuleNode): boolean;
|
40
39
|
visitSuite(node: SuiteNode): boolean;
|
package/dist/analyzer/binder.js
CHANGED
@@ -64,9 +64,8 @@ const symbolNameUtils_1 = require("./symbolNameUtils");
|
|
64
64
|
// flow nodes. This number is somewhat arbitrary and is tuned empirically.
|
65
65
|
const flowNodeComplexityContribution = 0.05;
|
66
66
|
class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
67
|
-
constructor(fileInfo,
|
67
|
+
constructor(fileInfo, _moduleSymbolOnly = false) {
|
68
68
|
super();
|
69
|
-
this._docStringService = _docStringService;
|
70
69
|
this._moduleSymbolOnly = _moduleSymbolOnly;
|
71
70
|
// A queue of deferred analysis operations.
|
72
71
|
this._deferredBindingTasks = [];
|
@@ -317,14 +316,8 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
317
316
|
this._currentFlowNode = this._createStartFlowNode();
|
318
317
|
this._codeFlowComplexity = 0;
|
319
318
|
node.d.params.forEach((paramNode) => {
|
320
|
-
var _a, _b;
|
321
319
|
if (paramNode.d.name) {
|
322
320
|
const symbol = this._bindNameToScope(this._currentScope, paramNode.d.name);
|
323
|
-
// Extract the parameter docString from the function docString
|
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 : []);
|
325
|
-
if (docString !== undefined) {
|
326
|
-
docString = this._docStringService.extractParameterDocumentation(docString, paramNode.d.name.d.value);
|
327
|
-
}
|
328
321
|
if (symbol) {
|
329
322
|
const paramDeclaration = {
|
330
323
|
type: 2 /* DeclarationType.Param */,
|
@@ -333,7 +326,6 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
333
326
|
range: (0, positionUtils_1.convertTextRangeToRange)(paramNode, this._fileInfo.lines),
|
334
327
|
moduleName: this._fileInfo.moduleName,
|
335
328
|
isInExceptSuite: this._isInExceptSuite,
|
336
|
-
docString: docString,
|
337
329
|
};
|
338
330
|
symbol.addDeclaration(paramDeclaration);
|
339
331
|
AnalyzerNodeInfo.setDeclaration(paramNode.d.name, paramDeclaration);
|
@@ -1177,19 +1169,23 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1177
1169
|
return false;
|
1178
1170
|
}
|
1179
1171
|
visitAwait(node) {
|
1180
|
-
var _a;
|
1172
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
1181
1173
|
// Make sure this is within an async lambda or function.
|
1182
|
-
const
|
1183
|
-
if (
|
1184
|
-
if (this._fileInfo.ipythonMode &&
|
1174
|
+
const execScopeNode = ParseTreeUtils.getExecutionScopeNode(node);
|
1175
|
+
if ((execScopeNode === null || execScopeNode === void 0 ? void 0 : execScopeNode.nodeType) !== 31 /* ParseNodeType.Function */ || !execScopeNode.d.isAsync) {
|
1176
|
+
if (this._fileInfo.ipythonMode && (execScopeNode === null || execScopeNode === void 0 ? void 0 : execScopeNode.nodeType) === 36 /* ParseNodeType.Module */) {
|
1185
1177
|
// Top level await is allowed in ipython mode.
|
1186
1178
|
return true;
|
1187
1179
|
}
|
1180
|
+
const isInGenerator = ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 11 /* ParseNodeType.Comprehension */ &&
|
1181
|
+
((_c = (_b = node.parent) === null || _b === void 0 ? void 0 : _b.parent) === null || _c === void 0 ? void 0 : _c.nodeType) !== 34 /* ParseNodeType.List */ &&
|
1182
|
+
((_e = (_d = node.parent) === null || _d === void 0 ? void 0 : _d.parent) === null || _e === void 0 ? void 0 : _e.nodeType) !== 45 /* ParseNodeType.Set */ &&
|
1183
|
+
((_g = (_f = node.parent) === null || _f === void 0 ? void 0 : _f.parent) === null || _g === void 0 ? void 0 : _g.nodeType) !== 18 /* ParseNodeType.Dictionary */;
|
1188
1184
|
// Allow if it's within a generator expression. Execution of
|
1189
1185
|
// generator expressions is deferred and therefore can be
|
1190
1186
|
// run within the context of an async function later.
|
1191
|
-
if (
|
1192
|
-
this._addSyntaxError(localize_1.LocMessage.awaitNotInAsync(), node);
|
1187
|
+
if (!isInGenerator) {
|
1188
|
+
this._addSyntaxError(localize_1.LocMessage.awaitNotInAsync(), node.d.awaitToken);
|
1193
1189
|
}
|
1194
1190
|
}
|
1195
1191
|
return true;
|
@@ -1650,7 +1646,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1650
1646
|
}
|
1651
1647
|
this._createNewScope(1 /* ScopeType.Comprehension */, this._getNonClassParentScope(),
|
1652
1648
|
/* proxyScope */ undefined, () => {
|
1653
|
-
var _a;
|
1649
|
+
var _a, _b, _c;
|
1654
1650
|
AnalyzerNodeInfo.setScope(node, this._currentScope);
|
1655
1651
|
const falseLabel = this._createBranchLabel();
|
1656
1652
|
// We'll walk the forIfNodes list twice. The first time we'll
|
@@ -1669,7 +1665,9 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1669
1665
|
// Allow if it's within a generator expression. Execution of
|
1670
1666
|
// generator expressions is deferred and therefore can be
|
1671
1667
|
// run within the context of an async function later.
|
1672
|
-
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 34 /* ParseNodeType.List */
|
1668
|
+
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 34 /* ParseNodeType.List */ ||
|
1669
|
+
((_b = node.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 45 /* ParseNodeType.Set */ ||
|
1670
|
+
((_c = node.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 18 /* ParseNodeType.Dictionary */) {
|
1673
1671
|
this._addSyntaxError(localize_1.LocMessage.asyncNotInAsyncFunction(), compr.d.asyncToken);
|
1674
1672
|
}
|
1675
1673
|
}
|
@@ -1738,9 +1736,18 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1738
1736
|
foundIrrefutableCase = true;
|
1739
1737
|
}
|
1740
1738
|
this._currentFlowNode = this._finishFlowLabel(preGuardLabel);
|
1739
|
+
// Note the active match subject expression prior to binding
|
1740
|
+
// the pattern. If the pattern involves any targets that overwrite
|
1741
|
+
// the subject expression, this will be set to undefined.
|
1742
|
+
this._currentMatchSubjExpr = node.d.expr;
|
1741
1743
|
// Bind the pattern.
|
1742
1744
|
this.walk(caseStatement.d.pattern);
|
1743
|
-
|
1745
|
+
// If the pattern involves targets that overwrite the subject
|
1746
|
+
// expression, skip creating a flow node for narrowing the subject.
|
1747
|
+
if (this._currentMatchSubjExpr) {
|
1748
|
+
this._createFlowNarrowForPattern(node.d.expr, caseStatement);
|
1749
|
+
this._currentMatchSubjExpr = undefined;
|
1750
|
+
}
|
1744
1751
|
// Apply the guard expression.
|
1745
1752
|
if (caseStatement.d.guardExpr) {
|
1746
1753
|
this._bindConditional(caseStatement.d.guardExpr, preSuiteLabel, postCaseLabel);
|
@@ -1892,6 +1899,13 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1892
1899
|
_addPatternCaptureTarget(target) {
|
1893
1900
|
const symbol = this._bindNameToScope(this._currentScope, target);
|
1894
1901
|
this._createAssignmentTargetFlowNodes(target, /* walkTargets */ false, /* unbound */ false);
|
1902
|
+
// See if the target overwrites all or a portion of the subject expression.
|
1903
|
+
if (this._currentMatchSubjExpr) {
|
1904
|
+
if (ParseTreeUtils.isMatchingExpression(target, this._currentMatchSubjExpr) ||
|
1905
|
+
ParseTreeUtils.isPartialMatchingExpression(target, this._currentMatchSubjExpr)) {
|
1906
|
+
this._currentMatchSubjExpr = undefined;
|
1907
|
+
}
|
1908
|
+
}
|
1895
1909
|
if (symbol) {
|
1896
1910
|
const declaration = {
|
1897
1911
|
type: 1 /* DeclarationType.Variable */,
|
@@ -3177,9 +3191,10 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
3177
3191
|
// To determine whether the first parameter of the method
|
3178
3192
|
// refers to the class or the instance, we need to apply
|
3179
3193
|
// some heuristics.
|
3180
|
-
|
3181
|
-
|
3182
|
-
//
|
3194
|
+
const implicitClassMethods = ['__new__', '__init_subclass__', '__class_getitem__'];
|
3195
|
+
if (implicitClassMethods.includes(methodNode.d.name.d.value)) {
|
3196
|
+
// Several methods are special. They act as class methods even
|
3197
|
+
// though they don't have a @classmethod decorator.
|
3183
3198
|
isInstanceMember = false;
|
3184
3199
|
}
|
3185
3200
|
else {
|