@zzzen/pyright-internal 1.2.0-dev.20230507 → 1.2.0-dev.20230521
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/analyzerFileInfo.d.ts +1 -0
- package/dist/analyzer/analyzerFileInfo.js +4 -3
- package/dist/analyzer/analyzerFileInfo.js.map +1 -1
- package/dist/analyzer/backgroundAnalysisProgram.d.ts +17 -15
- package/dist/analyzer/backgroundAnalysisProgram.js +43 -53
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/binder.d.ts +0 -2
- package/dist/analyzer/binder.js +2 -20
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.d.ts +1 -1
- package/dist/analyzer/checker.js +97 -29
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +14 -15
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +5 -1
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.js +248 -189
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +5 -2
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declarationUtils.js +1 -0
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/docStringConversion.js +1 -1
- package/dist/analyzer/docStringConversion.js.map +1 -1
- package/dist/analyzer/enums.js +8 -0
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +4 -4
- package/dist/analyzer/importResolver.js +93 -69
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importResult.d.ts +2 -2
- package/dist/analyzer/importStatementUtils.js +2 -2
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/namedTuples.js +2 -5
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +1 -1
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.js +2 -34
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/parseTreeWalker.js +2 -2
- package/dist/analyzer/parseTreeWalker.js.map +1 -1
- package/dist/analyzer/patternMatching.js +1 -0
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +18 -34
- package/dist/analyzer/program.js +57 -259
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/protocols.js +4 -2
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/service.d.ts +8 -16
- package/dist/analyzer/service.js +33 -47
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +1 -15
- package/dist/analyzer/sourceFile.js +14 -96
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceMapper.js +1 -1
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/symbol.d.ts +3 -1
- package/dist/analyzer/symbol.js +5 -0
- package/dist/analyzer/symbol.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.js +1 -1
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.d.ts +2 -2
- package/dist/analyzer/typeEvaluator.js +495 -196
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +7 -2
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +1 -0
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.d.ts +3 -3
- package/dist/analyzer/typePrinter.js +255 -101
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +12 -7
- package/dist/analyzer/typeUtils.js +174 -49
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.d.ts +1 -2
- package/dist/analyzer/typeVarContext.js +16 -34
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/typedDicts.js +138 -41
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +10 -3
- package/dist/analyzer/types.js +32 -16
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +25 -19
- package/dist/backgroundAnalysisBase.js +161 -115
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.d.ts +1 -1
- package/dist/backgroundThreadBase.js +1 -1
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +3 -4
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/configOptions.js +1 -1
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/extensibility.d.ts +26 -5
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/logTracker.d.ts +2 -0
- package/dist/common/logTracker.js +8 -1
- package/dist/common/logTracker.js.map +1 -1
- package/dist/common/lspUtils.d.ts +4 -1
- package/dist/common/lspUtils.js +38 -1
- package/dist/common/lspUtils.js.map +1 -1
- package/dist/common/pythonVersion.d.ts +2 -1
- package/dist/common/pythonVersion.js +1 -0
- package/dist/common/pythonVersion.js.map +1 -1
- package/dist/common/textRange.js +1 -1
- package/dist/common/textRange.js.map +1 -1
- package/dist/common/workspaceEditUtils.d.ts +3 -3
- package/dist/common/workspaceEditUtils.js +15 -17
- package/dist/common/workspaceEditUtils.js.map +1 -1
- package/dist/languageServerBase.d.ts +2 -5
- package/dist/languageServerBase.js +35 -62
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +51 -52
- package/dist/languageService/autoImporter.js +126 -211
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.js +8 -33
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +42 -81
- package/dist/languageService/completionProvider.js +608 -841
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.d.ts +2 -2
- package/dist/languageService/documentSymbolCollector.js +40 -30
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/documentSymbolProvider.d.ts +13 -35
- package/dist/languageService/documentSymbolProvider.js +52 -264
- package/dist/languageService/documentSymbolProvider.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +1 -3
- package/dist/languageService/hoverProvider.js +11 -97
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/referencesProvider.d.ts +3 -3
- package/dist/languageService/referencesProvider.js +6 -8
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/renameProvider.d.ts +0 -1
- package/dist/languageService/renameProvider.js +2 -6
- package/dist/languageService/renameProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.js +1 -1
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/symbolIndexer.d.ts +23 -0
- package/dist/languageService/symbolIndexer.js +105 -0
- package/dist/languageService/symbolIndexer.js.map +1 -0
- package/dist/languageService/tooltipUtils.d.ts +8 -1
- package/dist/languageService/tooltipUtils.js +102 -1
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/languageService/workspaceSymbolProvider.d.ts +17 -0
- package/dist/languageService/workspaceSymbolProvider.js +133 -0
- package/dist/languageService/workspaceSymbolProvider.js.map +1 -0
- package/dist/localization/localize.d.ts +38 -4
- package/dist/localization/localize.js +21 -4
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +23 -6
- package/dist/parser/parseNodes.d.ts +8 -8
- package/dist/parser/parseNodes.js +20 -10
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.d.ts +3 -3
- package/dist/parser/parser.js +136 -159
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/stringTokenUtils.d.ts +3 -13
- package/dist/parser/stringTokenUtils.js +8 -181
- package/dist/parser/stringTokenUtils.js.map +1 -1
- package/dist/parser/tokenizer.d.ts +3 -0
- package/dist/parser/tokenizer.js +211 -24
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/parser/tokenizerTypes.d.ts +31 -1
- package/dist/parser/tokenizerTypes.js +51 -1
- package/dist/parser/tokenizerTypes.js.map +1 -1
- package/dist/pyright.js +26 -4
- package/dist/pyright.js.map +1 -1
- package/dist/readonlyAugmentedFileSystem.js +1 -1
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/tests/chainedSourceFiles.test.js +15 -20
- package/dist/tests/chainedSourceFiles.test.js.map +1 -1
- package/dist/tests/checker.test.js +14 -0
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/completions.test.js +11 -236
- package/dist/tests/completions.test.js.map +1 -1
- package/dist/tests/docStringConversion.test.js +36 -2
- package/dist/tests/docStringConversion.test.js.map +1 -1
- package/dist/tests/fourslash/completions.override2.fourslash.js +1 -16
- package/dist/tests/fourslash/completions.override2.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.js +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.d.ts +14 -8
- package/dist/tests/harness/fourslash/testState.js +27 -37
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/importResolver.test.js +84 -4
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/textRange.test.js +45 -0
- package/dist/tests/textRange.test.js.map +1 -0
- package/dist/tests/tokenizer.test.js +272 -58
- package/dist/tests/tokenizer.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +16 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +14 -0
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +7 -2
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +29 -9
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/workspaceEditUtils.test.js +15 -10
- package/dist/tests/workspaceEditUtils.test.js.map +1 -1
- package/dist/workspaceFactory.js +3 -5
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -1
- package/dist/languageService/importAdder.d.ts +0 -40
- package/dist/languageService/importAdder.js +0 -388
- package/dist/languageService/importAdder.js.map +0 -1
- package/dist/tests/fourslash/completions.commitChars.fourslash.d.ts +0 -1
- package/dist/tests/fourslash/completions.commitChars.fourslash.js +0 -81
- package/dist/tests/fourslash/completions.commitChars.fourslash.js.map +0 -1
- package/dist/tests/importAdder.test.js +0 -1325
- package/dist/tests/importAdder.test.js.map +0 -1
- /package/dist/tests/{importAdder.test.d.ts → textRange.test.d.ts} +0 -0
@@ -27,7 +27,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
27
27
|
return result;
|
28
28
|
};
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
30
|
-
exports.
|
30
|
+
exports.printLiteralValue = exports.printObjectTypeForClass = exports.printFunctionParts = exports.printType = exports.PrintTypeFlags = void 0;
|
31
|
+
const collectionUtils_1 = require("../common/collectionUtils");
|
31
32
|
const parameterUtils_1 = require("./parameterUtils");
|
32
33
|
const ParseTreeUtils = __importStar(require("./parseTreeUtils"));
|
33
34
|
const types_1 = require("./types");
|
@@ -63,7 +64,90 @@ var PrintTypeFlags;
|
|
63
64
|
// Expand TypedDict kwargs to show the keys from the TypedDict instead of **kwargs.
|
64
65
|
PrintTypeFlags[PrintTypeFlags["ExpandTypedDictArgs"] = 1024] = "ExpandTypedDictArgs";
|
65
66
|
})(PrintTypeFlags = exports.PrintTypeFlags || (exports.PrintTypeFlags = {}));
|
66
|
-
function printType(type, printTypeFlags, returnTypeCallback
|
67
|
+
function printType(type, printTypeFlags, returnTypeCallback) {
|
68
|
+
const uniqueNameMap = new UniqueNameMap(printTypeFlags, returnTypeCallback);
|
69
|
+
uniqueNameMap.build(type);
|
70
|
+
return printTypeInternal(type, printTypeFlags, returnTypeCallback, uniqueNameMap, [], 0);
|
71
|
+
}
|
72
|
+
exports.printType = printType;
|
73
|
+
function printFunctionParts(type, printTypeFlags, returnTypeCallback) {
|
74
|
+
const uniqueNameMap = new UniqueNameMap(printTypeFlags, returnTypeCallback);
|
75
|
+
uniqueNameMap.build(type);
|
76
|
+
return printFunctionPartsInternal(type, printTypeFlags, returnTypeCallback, uniqueNameMap, [], 0);
|
77
|
+
}
|
78
|
+
exports.printFunctionParts = printFunctionParts;
|
79
|
+
function printObjectTypeForClass(type, printTypeFlags, returnTypeCallback) {
|
80
|
+
const uniqueNameMap = new UniqueNameMap(printTypeFlags, returnTypeCallback);
|
81
|
+
uniqueNameMap.build(type);
|
82
|
+
return printObjectTypeForClassInternal(type, printTypeFlags, returnTypeCallback, uniqueNameMap, [], 0);
|
83
|
+
}
|
84
|
+
exports.printObjectTypeForClass = printObjectTypeForClass;
|
85
|
+
function printLiteralValue(type, quotation = "'") {
|
86
|
+
const literalValue = type.literalValue;
|
87
|
+
if (literalValue === undefined) {
|
88
|
+
return '';
|
89
|
+
}
|
90
|
+
let literalStr;
|
91
|
+
if (typeof literalValue === 'string') {
|
92
|
+
let effectiveLiteralValue = literalValue;
|
93
|
+
// Limit the length of the string literal.
|
94
|
+
const maxLiteralStringLength = 50;
|
95
|
+
if (literalValue.length > maxLiteralStringLength) {
|
96
|
+
effectiveLiteralValue = literalValue.substring(0, maxLiteralStringLength) + '…';
|
97
|
+
}
|
98
|
+
if (type.details.name === 'bytes') {
|
99
|
+
let bytesString = '';
|
100
|
+
// There's no good built-in conversion routine in javascript to convert
|
101
|
+
// bytes strings. Determine on a character-by-character basis whether
|
102
|
+
// it can be rendered into an ASCII character. If not, use an escape.
|
103
|
+
for (let i = 0; i < effectiveLiteralValue.length; i++) {
|
104
|
+
const char = effectiveLiteralValue.substring(i, i + 1);
|
105
|
+
const charCode = char.charCodeAt(0);
|
106
|
+
if (charCode >= 20 && charCode <= 126) {
|
107
|
+
if (charCode === 34) {
|
108
|
+
bytesString += '\\' + char;
|
109
|
+
}
|
110
|
+
else {
|
111
|
+
bytesString += char;
|
112
|
+
}
|
113
|
+
}
|
114
|
+
else {
|
115
|
+
bytesString += `\\x${((charCode >> 4) & 0xf).toString(16)}${(charCode & 0xf).toString(16)}`;
|
116
|
+
}
|
117
|
+
}
|
118
|
+
literalStr = `b"${bytesString}"`;
|
119
|
+
}
|
120
|
+
else {
|
121
|
+
// JSON.stringify will perform proper escaping for " case.
|
122
|
+
// So, we only need to do our own escaping for ' case.
|
123
|
+
literalStr = JSON.stringify(effectiveLiteralValue).toString();
|
124
|
+
if (quotation !== '"') {
|
125
|
+
literalStr = `'${literalStr
|
126
|
+
.substring(1, literalStr.length - 1)
|
127
|
+
.replace(escapedDoubleQuoteRegEx, '"')
|
128
|
+
.replace(singleTickRegEx, "\\'")}'`;
|
129
|
+
}
|
130
|
+
}
|
131
|
+
}
|
132
|
+
else if (typeof literalValue === 'boolean') {
|
133
|
+
literalStr = literalValue ? 'True' : 'False';
|
134
|
+
}
|
135
|
+
else if (literalValue instanceof types_1.EnumLiteral) {
|
136
|
+
literalStr = `${literalValue.className}.${literalValue.itemName}`;
|
137
|
+
}
|
138
|
+
else if (typeof literalValue === 'bigint') {
|
139
|
+
literalStr = literalValue.toString();
|
140
|
+
if (literalStr.endsWith('n')) {
|
141
|
+
literalStr = literalStr.substring(0, literalStr.length - 1);
|
142
|
+
}
|
143
|
+
}
|
144
|
+
else {
|
145
|
+
literalStr = literalValue.toString();
|
146
|
+
}
|
147
|
+
return literalStr;
|
148
|
+
}
|
149
|
+
exports.printLiteralValue = printLiteralValue;
|
150
|
+
function printTypeInternal(type, printTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount) {
|
67
151
|
const originalPrintTypeFlags = printTypeFlags;
|
68
152
|
const parenthesizeUnion = (printTypeFlags & 16 /* ParenthesizeUnion */) !== 0;
|
69
153
|
printTypeFlags &= ~(16 /* ParenthesizeUnion */ | 128 /* ParenthesizeCallable */);
|
@@ -90,6 +174,10 @@ function printType(type, printTypeFlags, returnTypeCallback, recursionTypes = []
|
|
90
174
|
try {
|
91
175
|
recursionTypes.push(type);
|
92
176
|
let aliasName = type.typeAliasInfo.name;
|
177
|
+
// Use the fully-qualified name if the name isn't unique.
|
178
|
+
if (!uniqueNameMap.isUnique(aliasName)) {
|
179
|
+
aliasName = type.typeAliasInfo.fullName;
|
180
|
+
}
|
93
181
|
const typeParams = type.typeAliasInfo.typeParameters;
|
94
182
|
if (typeParams) {
|
95
183
|
let argumentStrings;
|
@@ -107,11 +195,11 @@ function printType(type, printTypeFlags, returnTypeCallback, recursionTypes = []
|
|
107
195
|
(0, typeUtils_1.isTupleClass)(typeArg) &&
|
108
196
|
typeArg.tupleTypeArguments) {
|
109
197
|
typeArg.tupleTypeArguments.forEach((tupleTypeArg) => {
|
110
|
-
argumentStrings.push(
|
198
|
+
argumentStrings.push(printTypeInternal(tupleTypeArg.type, printTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount));
|
111
199
|
});
|
112
200
|
}
|
113
201
|
else {
|
114
|
-
argumentStrings.push(
|
202
|
+
argumentStrings.push(printTypeInternal(typeArg, printTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount));
|
115
203
|
}
|
116
204
|
});
|
117
205
|
}
|
@@ -121,7 +209,7 @@ function printType(type, printTypeFlags, returnTypeCallback, recursionTypes = []
|
|
121
209
|
typeParams.some((typeParam) => !(0, types_1.isUnknown)(typeParam))) {
|
122
210
|
argumentStrings = [];
|
123
211
|
typeParams.forEach((typeParam) => {
|
124
|
-
argumentStrings.push(
|
212
|
+
argumentStrings.push(printTypeInternal(typeParam, printTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount));
|
125
213
|
});
|
126
214
|
}
|
127
215
|
}
|
@@ -158,11 +246,15 @@ function printType(type, printTypeFlags, returnTypeCallback, recursionTypes = []
|
|
158
246
|
}
|
159
247
|
if (type.typeAliasInfo) {
|
160
248
|
if (!type.typeAliasInfo.typeParameters) {
|
161
|
-
|
249
|
+
let name = type.typeAliasInfo.name;
|
250
|
+
if (!uniqueNameMap.isUnique(name)) {
|
251
|
+
name = type.typeAliasInfo.fullName;
|
252
|
+
}
|
253
|
+
return name;
|
162
254
|
}
|
163
255
|
try {
|
164
256
|
recursionTypes.push(type);
|
165
|
-
return
|
257
|
+
return printTypeInternal(type, printTypeFlags & ~32 /* ExpandTypeAlias */, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount);
|
166
258
|
}
|
167
259
|
finally {
|
168
260
|
recursionTypes.pop();
|
@@ -200,7 +292,7 @@ function printType(type, printTypeFlags, returnTypeCallback, recursionTypes = []
|
|
200
292
|
if (type.literalValue !== undefined) {
|
201
293
|
return `Literal[${printLiteralValue(type)}]`;
|
202
294
|
}
|
203
|
-
return `${
|
295
|
+
return `${printObjectTypeForClassInternal(type, printTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount)}${getConditionalIndicator(type)}`;
|
204
296
|
}
|
205
297
|
else {
|
206
298
|
let typeToWrap;
|
@@ -208,21 +300,21 @@ function printType(type, printTypeFlags, returnTypeCallback, recursionTypes = []
|
|
208
300
|
typeToWrap = `Literal[${printLiteralValue(type)}]`;
|
209
301
|
}
|
210
302
|
else {
|
211
|
-
typeToWrap = `${
|
303
|
+
typeToWrap = `${printObjectTypeForClassInternal(type, printTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount)}`;
|
212
304
|
}
|
213
305
|
return `${_printNestedInstantiable(type, typeToWrap)}${getConditionalIndicator(type)}`;
|
214
306
|
}
|
215
307
|
}
|
216
308
|
case 5 /* Function */: {
|
217
309
|
if (types_1.TypeBase.isInstantiable(type)) {
|
218
|
-
const typeString = printFunctionType(types_1.TypeBase.cloneTypeAsInstance(type), printTypeFlags, returnTypeCallback, recursionTypes, recursionCount);
|
310
|
+
const typeString = printFunctionType(types_1.TypeBase.cloneTypeAsInstance(type), printTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount);
|
219
311
|
return `Type[${typeString}]`;
|
220
312
|
}
|
221
|
-
return printFunctionType(type, originalPrintTypeFlags, returnTypeCallback, recursionTypes, recursionCount);
|
313
|
+
return printFunctionType(type, originalPrintTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount);
|
222
314
|
}
|
223
315
|
case 6 /* OverloadedFunction */: {
|
224
316
|
const overloadedType = type;
|
225
|
-
const overloads = overloadedType.overloads.map((overload) =>
|
317
|
+
const overloads = overloadedType.overloads.map((overload) => printTypeInternal(overload, printTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount));
|
226
318
|
if (printTypeFlags & 256 /* PythonSyntax */) {
|
227
319
|
return 'Callable[..., Any]';
|
228
320
|
}
|
@@ -266,7 +358,7 @@ function printType(type, printTypeFlags, returnTypeCallback, recursionTypes = []
|
|
266
358
|
}
|
267
359
|
}
|
268
360
|
if (matchedAllSubtypes && !allSubtypesPreviouslyHandled) {
|
269
|
-
subtypeStrings.add(
|
361
|
+
subtypeStrings.add(printTypeInternal(typeAliasSource, updatedPrintTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount));
|
270
362
|
indicesCoveredByTypeAlias.forEach((index) => subtypeHandledSet.add(index));
|
271
363
|
}
|
272
364
|
}
|
@@ -277,7 +369,7 @@ function printType(type, printTypeFlags, returnTypeCallback, recursionTypes = []
|
|
277
369
|
if ((0, types_1.isNever)(typeWithoutNone)) {
|
278
370
|
return 'None';
|
279
371
|
}
|
280
|
-
const optionalType =
|
372
|
+
const optionalType = printTypeInternal(typeWithoutNone, updatedPrintTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount);
|
281
373
|
if (printTypeFlags & 8 /* PEP604 */) {
|
282
374
|
const unionString = optionalType + ' | None';
|
283
375
|
if (parenthesizeUnion) {
|
@@ -298,7 +390,7 @@ function printType(type, printTypeFlags, returnTypeCallback, recursionTypes = []
|
|
298
390
|
literalClassStrings.add(printLiteralValue(subtype));
|
299
391
|
}
|
300
392
|
else {
|
301
|
-
subtypeStrings.add(
|
393
|
+
subtypeStrings.add(printTypeInternal(subtype, updatedPrintTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount));
|
302
394
|
}
|
303
395
|
}
|
304
396
|
});
|
@@ -336,9 +428,9 @@ function printType(type, printTypeFlags, returnTypeCallback, recursionTypes = []
|
|
336
428
|
// aliases, return the type alias name.
|
337
429
|
if (type.details.recursiveTypeAliasName) {
|
338
430
|
if ((printTypeFlags & 32 /* ExpandTypeAlias */) !== 0 && type.details.boundType) {
|
339
|
-
return
|
431
|
+
return printTypeInternal(types_1.TypeBase.isInstance(type)
|
340
432
|
? (0, typeUtils_1.convertToInstance)(type.details.boundType)
|
341
|
-
: type.details.boundType, printTypeFlags, returnTypeCallback, recursionTypes, recursionCount);
|
433
|
+
: type.details.boundType, printTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount);
|
342
434
|
}
|
343
435
|
return type.details.recursiveTypeAliasName;
|
344
436
|
}
|
@@ -346,7 +438,7 @@ function printType(type, printTypeFlags, returnTypeCallback, recursionTypes = []
|
|
346
438
|
// print the type with a special character that indicates that the type
|
347
439
|
// is internally represented as a TypeVar.
|
348
440
|
if (type.details.isSynthesizedSelf && type.details.boundType) {
|
349
|
-
let boundTypeString =
|
441
|
+
let boundTypeString = printTypeInternal(type.details.boundType, printTypeFlags & ~32 /* ExpandTypeAlias */, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount);
|
350
442
|
if (!(0, types_1.isAnyOrUnknown)(type.details.boundType)) {
|
351
443
|
if (printTypeFlags & 256 /* PythonSyntax */) {
|
352
444
|
boundTypeString = `Self`;
|
@@ -399,8 +491,7 @@ function printType(type, printTypeFlags, returnTypeCallback, recursionTypes = []
|
|
399
491
|
recursionTypes.pop();
|
400
492
|
}
|
401
493
|
}
|
402
|
-
|
403
|
-
function printFunctionType(type, printTypeFlags, returnTypeCallback, recursionTypes = [], recursionCount = 0) {
|
494
|
+
function printFunctionType(type, printTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount) {
|
404
495
|
if (printTypeFlags & 256 /* PythonSyntax */) {
|
405
496
|
// Callable works only in cases where all parameters are positional-only.
|
406
497
|
let isPositionalParamsOnly = false;
|
@@ -418,7 +509,7 @@ function printFunctionType(type, printTypeFlags, returnTypeCallback, recursionTy
|
|
418
509
|
const returnType = returnTypeCallback(type);
|
419
510
|
let returnTypeString = 'Any';
|
420
511
|
if (returnType) {
|
421
|
-
returnTypeString =
|
512
|
+
returnTypeString = printTypeInternal(returnType, printTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount);
|
422
513
|
}
|
423
514
|
if (isPositionalParamsOnly) {
|
424
515
|
const paramTypes = [];
|
@@ -426,7 +517,7 @@ function printFunctionType(type, printTypeFlags, returnTypeCallback, recursionTy
|
|
426
517
|
if (param.name) {
|
427
518
|
const paramType = types_1.FunctionType.getEffectiveParameterType(type, index);
|
428
519
|
if (recursionTypes.length < types_1.maxTypeRecursionCount) {
|
429
|
-
paramTypes.push(
|
520
|
+
paramTypes.push(printTypeInternal(paramType, printTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount));
|
430
521
|
}
|
431
522
|
else {
|
432
523
|
paramTypes.push('Any');
|
@@ -448,7 +539,7 @@ function printFunctionType(type, printTypeFlags, returnTypeCallback, recursionTy
|
|
448
539
|
}
|
449
540
|
}
|
450
541
|
else {
|
451
|
-
const parts =
|
542
|
+
const parts = printFunctionPartsInternal(type, printTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount);
|
452
543
|
const paramSignature = `(${parts[0].join(', ')})`;
|
453
544
|
if (types_1.FunctionType.isParamSpecValue(type)) {
|
454
545
|
return paramSignature;
|
@@ -461,74 +552,13 @@ function printFunctionType(type, printTypeFlags, returnTypeCallback, recursionTy
|
|
461
552
|
return fullSignature;
|
462
553
|
}
|
463
554
|
}
|
464
|
-
function
|
465
|
-
const literalValue = type.literalValue;
|
466
|
-
if (literalValue === undefined) {
|
467
|
-
return '';
|
468
|
-
}
|
469
|
-
let literalStr;
|
470
|
-
if (typeof literalValue === 'string') {
|
471
|
-
let effectiveLiteralValue = literalValue;
|
472
|
-
// Limit the length of the string literal.
|
473
|
-
const maxLiteralStringLength = 50;
|
474
|
-
if (literalValue.length > maxLiteralStringLength) {
|
475
|
-
effectiveLiteralValue = literalValue.substring(0, maxLiteralStringLength) + '…';
|
476
|
-
}
|
477
|
-
if (type.details.name === 'bytes') {
|
478
|
-
let bytesString = '';
|
479
|
-
// There's no good built-in conversion routine in javascript to convert
|
480
|
-
// bytes strings. Determine on a character-by-character basis whether
|
481
|
-
// it can be rendered into an ASCII character. If not, use an escape.
|
482
|
-
for (let i = 0; i < effectiveLiteralValue.length; i++) {
|
483
|
-
const char = effectiveLiteralValue.substring(i, i + 1);
|
484
|
-
const charCode = char.charCodeAt(0);
|
485
|
-
if (charCode >= 20 && charCode <= 126) {
|
486
|
-
if (charCode === 34) {
|
487
|
-
bytesString += '\\' + char;
|
488
|
-
}
|
489
|
-
else {
|
490
|
-
bytesString += char;
|
491
|
-
}
|
492
|
-
}
|
493
|
-
else {
|
494
|
-
bytesString += `\\x${((charCode >> 4) & 0xf).toString(16)}${(charCode & 0xf).toString(16)}`;
|
495
|
-
}
|
496
|
-
}
|
497
|
-
literalStr = `b"${bytesString}"`;
|
498
|
-
}
|
499
|
-
else {
|
500
|
-
// JSON.stringify will perform proper escaping for " case.
|
501
|
-
// So, we only need to do our own escaping for ' case.
|
502
|
-
literalStr = JSON.stringify(effectiveLiteralValue).toString();
|
503
|
-
if (quotation !== '"') {
|
504
|
-
literalStr = `'${literalStr
|
505
|
-
.substring(1, literalStr.length - 1)
|
506
|
-
.replace(escapedDoubleQuoteRegEx, '"')
|
507
|
-
.replace(singleTickRegEx, "\\'")}'`;
|
508
|
-
}
|
509
|
-
}
|
510
|
-
}
|
511
|
-
else if (typeof literalValue === 'boolean') {
|
512
|
-
literalStr = literalValue ? 'True' : 'False';
|
513
|
-
}
|
514
|
-
else if (literalValue instanceof types_1.EnumLiteral) {
|
515
|
-
literalStr = `${literalValue.className}.${literalValue.itemName}`;
|
516
|
-
}
|
517
|
-
else if (typeof literalValue === 'bigint') {
|
518
|
-
literalStr = literalValue.toString();
|
519
|
-
if (literalStr.endsWith('n')) {
|
520
|
-
literalStr = literalStr.substring(0, literalStr.length - 1);
|
521
|
-
}
|
522
|
-
}
|
523
|
-
else {
|
524
|
-
literalStr = literalValue.toString();
|
525
|
-
}
|
526
|
-
return literalStr;
|
527
|
-
}
|
528
|
-
exports.printLiteralValue = printLiteralValue;
|
529
|
-
function printObjectTypeForClass(type, printTypeFlags, returnTypeCallback, recursionTypes = [], recursionCount = 0) {
|
555
|
+
function printObjectTypeForClassInternal(type, printTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount) {
|
530
556
|
var _a, _b;
|
531
557
|
let objName = type.aliasName || type.details.name;
|
558
|
+
// Use the fully-qualified name if the name isn't unique.
|
559
|
+
if (!uniqueNameMap.isUnique(objName)) {
|
560
|
+
objName = type.details.fullName;
|
561
|
+
}
|
532
562
|
// If this is a pseudo-generic class, don't display the type arguments
|
533
563
|
// or type parameters because it will confuse users.
|
534
564
|
if (!types_1.ClassType.isPseudoGenericClass(type)) {
|
@@ -561,11 +591,11 @@ function printObjectTypeForClass(type, printTypeFlags, returnTypeCallback, recur
|
|
561
591
|
}
|
562
592
|
}
|
563
593
|
else {
|
564
|
-
|
594
|
+
(0, collectionUtils_1.appendArray)(typeArgStrings, typeArg.type.tupleTypeArguments.map((typeArg) => {
|
565
595
|
if (!(0, types_1.isUnknown)(typeArg.type)) {
|
566
596
|
isAllUnknown = false;
|
567
597
|
}
|
568
|
-
const typeArgText =
|
598
|
+
const typeArgText = printTypeInternal(typeArg.type, printTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount);
|
569
599
|
if (typeArg.isUnbounded) {
|
570
600
|
return _printUnpack(`tuple[${typeArgText}, ...]`, printTypeFlags);
|
571
601
|
}
|
@@ -577,7 +607,7 @@ function printObjectTypeForClass(type, printTypeFlags, returnTypeCallback, recur
|
|
577
607
|
if (!(0, types_1.isUnknown)(typeArg.type)) {
|
578
608
|
isAllUnknown = false;
|
579
609
|
}
|
580
|
-
const typeArgTypeText =
|
610
|
+
const typeArgTypeText = printTypeInternal(typeArg.type, printTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount);
|
581
611
|
if (typeArg.isUnbounded) {
|
582
612
|
if (typeArgs.length === 1) {
|
583
613
|
typeArgStrings.push(typeArgTypeText, '...');
|
@@ -618,7 +648,7 @@ function printObjectTypeForClass(type, printTypeFlags, returnTypeCallback, recur
|
|
618
648
|
'[' +
|
619
649
|
typeParams
|
620
650
|
.map((typeParam) => {
|
621
|
-
return
|
651
|
+
return printTypeInternal(typeParam, printTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount);
|
622
652
|
})
|
623
653
|
.join(', ') +
|
624
654
|
']';
|
@@ -626,10 +656,15 @@ function printObjectTypeForClass(type, printTypeFlags, returnTypeCallback, recur
|
|
626
656
|
}
|
627
657
|
}
|
628
658
|
}
|
659
|
+
// Wrap in a "Partial" for TypedDict that has been synthesized as partial.
|
660
|
+
if (type.isTypedDictPartial) {
|
661
|
+
if ((printTypeFlags & 256 /* PythonSyntax */) === 0) {
|
662
|
+
objName = `Partial[${objName}]`;
|
663
|
+
}
|
664
|
+
}
|
629
665
|
return objName;
|
630
666
|
}
|
631
|
-
|
632
|
-
function printFunctionParts(type, printTypeFlags, returnTypeCallback, recursionTypes = [], recursionCount = 0) {
|
667
|
+
function printFunctionPartsInternal(type, printTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount) {
|
633
668
|
const paramTypeStrings = [];
|
634
669
|
let sawDefinedName = false;
|
635
670
|
type.details.parameters.forEach((param, index) => {
|
@@ -642,7 +677,7 @@ function printFunctionParts(type, printTypeFlags, returnTypeCallback, recursionT
|
|
642
677
|
types_1.ClassType.isBuiltIn(specializedParamType, 'tuple') &&
|
643
678
|
specializedParamType.tupleTypeArguments) {
|
644
679
|
specializedParamType.tupleTypeArguments.forEach((paramType) => {
|
645
|
-
const paramString =
|
680
|
+
const paramString = printTypeInternal(paramType.type, printTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount);
|
646
681
|
paramTypeStrings.push(paramString);
|
647
682
|
});
|
648
683
|
return;
|
@@ -653,7 +688,7 @@ function printFunctionParts(type, printTypeFlags, returnTypeCallback, recursionT
|
|
653
688
|
printTypeFlags & 1024 /* ExpandTypedDictArgs */ &&
|
654
689
|
param.type.category === 7 /* Class */) {
|
655
690
|
param.type.details.typedDictEntries.forEach((v, k) => {
|
656
|
-
const valueTypeString =
|
691
|
+
const valueTypeString = printTypeInternal(v.valueType, printTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount);
|
657
692
|
paramTypeStrings.push(`${k}: ${valueTypeString}`);
|
658
693
|
});
|
659
694
|
return;
|
@@ -685,7 +720,7 @@ function printFunctionParts(type, printTypeFlags, returnTypeCallback, recursionT
|
|
685
720
|
if (param.hasDeclaredType || param.isTypeInferred) {
|
686
721
|
const paramType = types_1.FunctionType.getEffectiveParameterType(type, index);
|
687
722
|
let paramTypeString = recursionTypes.length < types_1.maxTypeRecursionCount
|
688
|
-
?
|
723
|
+
? printTypeInternal(paramType, printTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount)
|
689
724
|
: '';
|
690
725
|
if (emittedParamName) {
|
691
726
|
paramString += ': ';
|
@@ -763,16 +798,15 @@ function printFunctionParts(type, printTypeFlags, returnTypeCallback, recursionT
|
|
763
798
|
paramTypeStrings.push(`**kwargs: ${type.details.paramSpec}.kwargs`);
|
764
799
|
}
|
765
800
|
else {
|
766
|
-
paramTypeStrings.push(`**${
|
801
|
+
paramTypeStrings.push(`**${printTypeInternal(type.details.paramSpec, printTypeFlags, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount)}`);
|
767
802
|
}
|
768
803
|
}
|
769
804
|
const returnType = returnTypeCallback(type);
|
770
805
|
const returnTypeString = recursionTypes.length < types_1.maxTypeRecursionCount
|
771
|
-
?
|
806
|
+
? printTypeInternal(returnType, printTypeFlags | 16 /* ParenthesizeUnion */ | 128 /* ParenthesizeCallable */, returnTypeCallback, uniqueNameMap, recursionTypes, recursionCount)
|
772
807
|
: '';
|
773
808
|
return [paramTypeStrings, returnTypeString];
|
774
809
|
}
|
775
|
-
exports.printFunctionParts = printFunctionParts;
|
776
810
|
function _printUnpack(textToWrap, flags) {
|
777
811
|
return flags & 512 /* UseTypingUnpack */ ? `Unpack[${textToWrap}]` : `*${textToWrap}`;
|
778
812
|
}
|
@@ -792,4 +826,124 @@ function _getReadableTypeVarName(type, usePythonSyntax) {
|
|
792
826
|
}
|
793
827
|
return types_1.TypeVarType.getReadableName(type);
|
794
828
|
}
|
829
|
+
// Represents a map of named types (classes and type aliases) that appear within
|
830
|
+
// a specified type to determine whether any of the names require disambiguation
|
831
|
+
// (i.e. their fully-qualified name is required).
|
832
|
+
class UniqueNameMap {
|
833
|
+
constructor(_printTypeFlags, _returnTypeCallback) {
|
834
|
+
this._printTypeFlags = _printTypeFlags;
|
835
|
+
this._returnTypeCallback = _returnTypeCallback;
|
836
|
+
this._map = new Map();
|
837
|
+
}
|
838
|
+
build(type, recursionTypes = [], recursionCount = 0) {
|
839
|
+
var _a;
|
840
|
+
if (recursionCount > types_1.maxTypeRecursionCount) {
|
841
|
+
return;
|
842
|
+
}
|
843
|
+
recursionCount++;
|
844
|
+
if (type.typeAliasInfo) {
|
845
|
+
let expandTypeAlias = true;
|
846
|
+
if ((this._printTypeFlags & 32 /* ExpandTypeAlias */) === 0) {
|
847
|
+
expandTypeAlias = false;
|
848
|
+
}
|
849
|
+
else {
|
850
|
+
if (recursionTypes.find((t) => t === type)) {
|
851
|
+
expandTypeAlias = false;
|
852
|
+
}
|
853
|
+
}
|
854
|
+
if (!expandTypeAlias) {
|
855
|
+
this._addIfUnique(type.typeAliasInfo.name, type, /* useTypeAliasName */ true);
|
856
|
+
// Recursively add the type arguments if present.
|
857
|
+
if (type.typeAliasInfo.typeArguments) {
|
858
|
+
recursionTypes.push(type);
|
859
|
+
try {
|
860
|
+
type.typeAliasInfo.typeArguments.forEach((typeArg) => {
|
861
|
+
this.build(typeArg, recursionTypes, recursionCount);
|
862
|
+
});
|
863
|
+
}
|
864
|
+
finally {
|
865
|
+
recursionTypes.pop();
|
866
|
+
}
|
867
|
+
}
|
868
|
+
return;
|
869
|
+
}
|
870
|
+
}
|
871
|
+
try {
|
872
|
+
recursionTypes.push(type);
|
873
|
+
switch (type.category) {
|
874
|
+
case 5 /* Function */: {
|
875
|
+
type.details.parameters.forEach((_, index) => {
|
876
|
+
const paramType = types_1.FunctionType.getEffectiveParameterType(type, index);
|
877
|
+
this.build(paramType, recursionTypes, recursionCount);
|
878
|
+
});
|
879
|
+
const returnType = this._returnTypeCallback(type);
|
880
|
+
this.build(returnType, recursionTypes, recursionCount);
|
881
|
+
break;
|
882
|
+
}
|
883
|
+
case 6 /* OverloadedFunction */: {
|
884
|
+
type.overloads.forEach((overload) => {
|
885
|
+
this.build(overload, recursionTypes, recursionCount);
|
886
|
+
});
|
887
|
+
break;
|
888
|
+
}
|
889
|
+
case 7 /* Class */: {
|
890
|
+
if (type.literalValue !== undefined) {
|
891
|
+
break;
|
892
|
+
}
|
893
|
+
this._addIfUnique(type.aliasName || type.details.name, type);
|
894
|
+
if (!types_1.ClassType.isPseudoGenericClass(type)) {
|
895
|
+
if (type.tupleTypeArguments) {
|
896
|
+
type.tupleTypeArguments.forEach((typeArg) => {
|
897
|
+
this.build(typeArg.type, recursionTypes, recursionCount);
|
898
|
+
});
|
899
|
+
}
|
900
|
+
else if (type.typeArguments) {
|
901
|
+
type.typeArguments.forEach((typeArg) => {
|
902
|
+
this.build(typeArg, recursionTypes, recursionCount);
|
903
|
+
});
|
904
|
+
}
|
905
|
+
}
|
906
|
+
break;
|
907
|
+
}
|
908
|
+
case 9 /* Union */: {
|
909
|
+
(0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
|
910
|
+
this.build(subtype, recursionTypes, recursionCount);
|
911
|
+
});
|
912
|
+
(_a = type.typeAliasSources) === null || _a === void 0 ? void 0 : _a.forEach((typeAliasSource) => {
|
913
|
+
this.build(typeAliasSource, recursionTypes, recursionCount);
|
914
|
+
});
|
915
|
+
break;
|
916
|
+
}
|
917
|
+
}
|
918
|
+
}
|
919
|
+
finally {
|
920
|
+
recursionTypes.pop();
|
921
|
+
}
|
922
|
+
}
|
923
|
+
isUnique(name) {
|
924
|
+
const entry = this._map.get(name);
|
925
|
+
return !entry || entry.length === 1;
|
926
|
+
}
|
927
|
+
_addIfUnique(name, type, useTypeAliasName = false) {
|
928
|
+
const existingEntry = this._map.get(name);
|
929
|
+
if (!existingEntry) {
|
930
|
+
this._map.set(name, [type]);
|
931
|
+
}
|
932
|
+
else {
|
933
|
+
if (!existingEntry.some((t) => this._isSameTypeName(t, type, useTypeAliasName))) {
|
934
|
+
existingEntry.push(type);
|
935
|
+
}
|
936
|
+
}
|
937
|
+
}
|
938
|
+
_isSameTypeName(type1, type2, useTypeAliasName) {
|
939
|
+
var _a, _b;
|
940
|
+
if (useTypeAliasName) {
|
941
|
+
return ((_a = type1.typeAliasInfo) === null || _a === void 0 ? void 0 : _a.fullName) === ((_b = type2.typeAliasInfo) === null || _b === void 0 ? void 0 : _b.fullName);
|
942
|
+
}
|
943
|
+
if ((0, types_1.isClass)(type1) && (0, types_1.isClass)(type2)) {
|
944
|
+
return types_1.ClassType.isSameGenericClass(type1, type2);
|
945
|
+
}
|
946
|
+
return false;
|
947
|
+
}
|
948
|
+
}
|
795
949
|
//# sourceMappingURL=typePrinter.js.map
|