@zzzen/pyright-internal 1.2.0-dev.20230326 → 1.2.0-dev.20230409

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.
Files changed (161) hide show
  1. package/dist/analyzer/binder.d.ts +8 -0
  2. package/dist/analyzer/binder.js +46 -1
  3. package/dist/analyzer/binder.js.map +1 -1
  4. package/dist/analyzer/cacheManager.js +1 -1
  5. package/dist/analyzer/checker.js +54 -20
  6. package/dist/analyzer/checker.js.map +1 -1
  7. package/dist/analyzer/constraintSolver.js +4 -1
  8. package/dist/analyzer/constraintSolver.js.map +1 -1
  9. package/dist/analyzer/constructorTransform.js +4 -3
  10. package/dist/analyzer/constructorTransform.js.map +1 -1
  11. package/dist/analyzer/declarationUtils.d.ts +8 -0
  12. package/dist/analyzer/declarationUtils.js +147 -1
  13. package/dist/analyzer/declarationUtils.js.map +1 -1
  14. package/dist/analyzer/importStatementUtils.js +1 -1
  15. package/dist/analyzer/parameterUtils.d.ts +25 -1
  16. package/dist/analyzer/parameterUtils.js +182 -1
  17. package/dist/analyzer/parameterUtils.js.map +1 -1
  18. package/dist/analyzer/patternMatching.js +39 -2
  19. package/dist/analyzer/patternMatching.js.map +1 -1
  20. package/dist/analyzer/program.d.ts +2 -0
  21. package/dist/analyzer/program.js +62 -11
  22. package/dist/analyzer/program.js.map +1 -1
  23. package/dist/analyzer/properties.js +13 -13
  24. package/dist/analyzer/properties.js.map +1 -1
  25. package/dist/analyzer/protocols.js +3 -2
  26. package/dist/analyzer/protocols.js.map +1 -1
  27. package/dist/analyzer/pythonPathUtils.js +1 -1
  28. package/dist/analyzer/regions.js +4 -4
  29. package/dist/analyzer/regions.js.map +1 -1
  30. package/dist/analyzer/service.js +17 -8
  31. package/dist/analyzer/service.js.map +1 -1
  32. package/dist/analyzer/sourceFile.js +2 -2
  33. package/dist/analyzer/sourceFile.js.map +1 -1
  34. package/dist/analyzer/sourceFileInfoUtils.js +1 -1
  35. package/dist/analyzer/sourceMapper.js +1 -1
  36. package/dist/analyzer/sourceMapperUtils.d.ts +0 -8
  37. package/dist/analyzer/sourceMapperUtils.js +18 -25
  38. package/dist/analyzer/sourceMapperUtils.js.map +1 -1
  39. package/dist/analyzer/staticExpressions.js +2 -2
  40. package/dist/analyzer/symbolUtils.js +1 -1
  41. package/dist/analyzer/testWalker.js +3 -0
  42. package/dist/analyzer/testWalker.js.map +1 -1
  43. package/dist/analyzer/tracePrinter.js +1 -1
  44. package/dist/analyzer/typeCacheUtils.js +25 -1
  45. package/dist/analyzer/typeCacheUtils.js.map +1 -1
  46. package/dist/analyzer/typeEvaluator.js +180 -150
  47. package/dist/analyzer/typeEvaluator.js.map +1 -1
  48. package/dist/analyzer/typeEvaluatorTypes.d.ts +3 -3
  49. package/dist/analyzer/typeEvaluatorTypes.js +0 -1
  50. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  51. package/dist/analyzer/typeEvaluatorWithTracker.js +3 -5
  52. package/dist/analyzer/typeEvaluatorWithTracker.js.map +1 -1
  53. package/dist/analyzer/typeGuards.js +182 -159
  54. package/dist/analyzer/typeGuards.js.map +1 -1
  55. package/dist/analyzer/typeUtils.d.ts +13 -25
  56. package/dist/analyzer/typeUtils.js +157 -235
  57. package/dist/analyzer/typeUtils.js.map +1 -1
  58. package/dist/analyzer/typeVarContext.js +6 -2
  59. package/dist/analyzer/typeVarContext.js.map +1 -1
  60. package/dist/analyzer/typedDicts.js +42 -7
  61. package/dist/analyzer/typedDicts.js.map +1 -1
  62. package/dist/analyzer/types.d.ts +1 -0
  63. package/dist/analyzer/types.js +10 -0
  64. package/dist/analyzer/types.js.map +1 -1
  65. package/dist/common/configOptions.js +1 -1
  66. package/dist/common/configOptions.js.map +1 -1
  67. package/dist/common/diagnosticSink.js +1 -1
  68. package/dist/common/envVarUtils.js +7 -7
  69. package/dist/common/envVarUtils.js.map +1 -1
  70. package/dist/common/fileBasedCancellationUtils.js +1 -1
  71. package/dist/common/host.js +1 -1
  72. package/dist/common/lspUtils.js +1 -1
  73. package/dist/common/pathConsts.d.ts +1 -0
  74. package/dist/common/pathConsts.js +2 -1
  75. package/dist/common/pathConsts.js.map +1 -1
  76. package/dist/common/positionUtils.d.ts +2 -1
  77. package/dist/common/positionUtils.js +18 -12
  78. package/dist/common/positionUtils.js.map +1 -1
  79. package/dist/common/progressReporter.js +4 -1
  80. package/dist/common/progressReporter.js.map +1 -1
  81. package/dist/common/pythonVersion.js +1 -2
  82. package/dist/common/pythonVersion.js.map +1 -1
  83. package/dist/common/realFileSystem.js +1 -1
  84. package/dist/common/textEditTracker.js +1 -1
  85. package/dist/common/workspaceEditUtils.js +1 -1
  86. package/dist/languageServerBase.js +1 -1
  87. package/dist/languageServerBase.js.map +1 -1
  88. package/dist/languageService/analyzerServiceExecutor.js +2 -2
  89. package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
  90. package/dist/languageService/autoImporter.js +1 -0
  91. package/dist/languageService/autoImporter.js.map +1 -1
  92. package/dist/languageService/callHierarchyProvider.d.ts +7 -3
  93. package/dist/languageService/callHierarchyProvider.js +38 -6
  94. package/dist/languageService/callHierarchyProvider.js.map +1 -1
  95. package/dist/languageService/completionProvider.d.ts +1 -0
  96. package/dist/languageService/completionProvider.js +29 -10
  97. package/dist/languageService/completionProvider.js.map +1 -1
  98. package/dist/languageService/completionProviderUtils.js +2 -2
  99. package/dist/languageService/completionProviderUtils.js.map +1 -1
  100. package/dist/languageService/documentSymbolCollector.js +4 -1
  101. package/dist/languageService/documentSymbolCollector.js.map +1 -1
  102. package/dist/languageService/documentSymbolProvider.js +1 -2
  103. package/dist/languageService/documentSymbolProvider.js.map +1 -1
  104. package/dist/languageService/hoverProvider.d.ts +2 -0
  105. package/dist/languageService/hoverProvider.js +53 -43
  106. package/dist/languageService/hoverProvider.js.map +1 -1
  107. package/dist/languageService/importSorter.js +1 -1
  108. package/dist/languageService/indentationUtils.js +7 -1
  109. package/dist/languageService/indentationUtils.js.map +1 -1
  110. package/dist/languageService/insertionPointUtils.js +2 -1
  111. package/dist/languageService/insertionPointUtils.js.map +1 -1
  112. package/dist/languageService/tooltipUtils.js +2 -2
  113. package/dist/localization/localize.d.ts +0 -3
  114. package/dist/localization/localize.js +0 -1
  115. package/dist/localization/localize.js.map +1 -1
  116. package/dist/localization/package.nls.en-us.json +0 -1
  117. package/dist/pyright.js +1 -2
  118. package/dist/pyright.js.map +1 -1
  119. package/dist/tests/chainedSourceFiles.test.js +27 -0
  120. package/dist/tests/chainedSourceFiles.test.js.map +1 -1
  121. package/dist/tests/checker.test.js +1 -1
  122. package/dist/tests/checker.test.js.map +1 -1
  123. package/dist/tests/fourslash/fourslash.d.ts +5 -0
  124. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.aliasedFunction.fourslash.d.ts +1 -0
  125. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.aliasedFunction.fourslash.js +34 -0
  126. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.aliasedFunction.fourslash.js.map +1 -0
  127. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.aliasedVariable.fourslash.d.ts +1 -0
  128. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.aliasedVariable.fourslash.js +19 -0
  129. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.aliasedVariable.fourslash.js.map +1 -0
  130. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.function.fourslash.d.ts +1 -0
  131. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.function.fourslash.js +39 -0
  132. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.function.fourslash.js.map +1 -0
  133. package/dist/tests/harness/fourslash/testState.d.ts +5 -0
  134. package/dist/tests/harness/fourslash/testState.js +21 -0
  135. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  136. package/dist/tests/indentationUtils.reindent.test.js +19 -0
  137. package/dist/tests/indentationUtils.reindent.test.js.map +1 -1
  138. package/dist/tests/insertionPointUtils.test.js +13 -0
  139. package/dist/tests/insertionPointUtils.test.js.map +1 -1
  140. package/dist/tests/moveSymbol.insertion.test.js +21 -0
  141. package/dist/tests/moveSymbol.insertion.test.js.map +1 -1
  142. package/dist/tests/positionUtils.test.d.ts +1 -0
  143. package/dist/tests/positionUtils.test.js +48 -0
  144. package/dist/tests/positionUtils.test.js.map +1 -0
  145. package/dist/tests/typeEvaluator1.test.js +10 -0
  146. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  147. package/dist/tests/typeEvaluator2.test.js +20 -0
  148. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  149. package/dist/tests/typeEvaluator3.test.js +9 -1
  150. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  151. package/dist/tests/typeEvaluator4.test.js +43 -115
  152. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  153. package/dist/tests/typeEvaluator5.test.js +1 -5
  154. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  155. package/dist/workspaceFactory.d.ts +1 -0
  156. package/dist/workspaceFactory.js +24 -14
  157. package/dist/workspaceFactory.js.map +1 -1
  158. package/package.json +1 -1
  159. package/dist/analyzer/aliasDeclarationUtils.d.ts +0 -9
  160. package/dist/analyzer/aliasDeclarationUtils.js +0 -157
  161. package/dist/analyzer/aliasDeclarationUtils.js.map +0 -1
@@ -5,15 +5,14 @@
5
5
  * Licensed under the MIT license.
6
6
  * Author: Eric Traut
7
7
  *
8
- * Collection of functions that operate on Type objects.
8
+ * Functions that operate on Type objects.
9
9
  */
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.isTypeVarLimitedToCallable = exports.getTypeVarArgumentsRecursive = exports.addTypeVarsToListIfUnique = exports.getClassFieldsRecursive = exports.getClassIterator = exports.getClassMemberIterator = exports.lookUpClassMember = exports.lookUpObjectMember = exports.getContainerDepth = exports.getProtocolSymbols = exports.transformExpectedTypeForConstructor = exports.validateTypeVarDefault = exports.applySolvedTypeVars = exports.populateTypeVarContextForSelfType = exports.partiallySpecializeType = exports.isUnboundedTupleClass = exports.isTupleClass = exports.isMaybeDescriptorInstance = exports.isDescriptorInstance = exports.isProperty = exports.isEllipsisType = exports.getUnionSubtypeCount = exports.getLiteralTypeClassName = exports.containsLiteralType = exports.containsType = exports.isLiteralTypeOrUnion = exports.isLiteralType = exports.getSpecializedTupleType = exports.getTypeVarScopeId = exports.transformPossibleRecursiveTypeAlias = exports.isTypeAliasRecursive = exports.isTypeAliasPlaceholder = exports.getTypeCondition = exports.addConditionToType = exports.getFullNameOfType = exports.derivesFromAnyOrUnknown = exports.isUnionableType = exports.preserveUnknown = exports.areTypesSame = exports.doForEachSubtype = exports.sortTypes = exports.mapSubtypes = exports.makeInferenceContext = exports.isIncompleteUnknown = exports.isOptionalType = exports.getParameterListDetails = exports.ParameterSource = exports.AssignTypeFlags = exports.ClassIteratorFlags = exports.ClassMemberLookupFlags = void 0;
12
- exports.convertParamSpecValueToType = exports.convertTypeToParamSpecValue = exports.getDeclaringModulesForType = exports.computeMroLinearization = exports.isVarianceOfTypeArgumentCompatible = exports.combineVariances = exports.requiresSpecialization = exports.requiresTypeArguments = exports.getGeneratorTypeArgs = exports.removeParamSpecVariadicsFromFunction = exports.removeParamSpecVariadicsFromSignature = exports.specializeTupleClass = exports.combineSameSizedTuples = exports.explodeGenericClass = exports.isPartlyUnknown = exports.containsUnknown = exports.getMembersForModule = exports.getMembersForClass = exports.convertToInstantiable = exports.convertToInstance = exports.isEffectivelyInstantiable = exports.isMetaclassInstance = exports.getGeneratorYieldType = exports.getDeclaredGeneratorReturnType = exports.synthesizeTypeVarForSelfCls = exports.derivesFromClassRecursive = exports.specializeForBaseClass = exports.buildTypeVarContext = exports.buildTypeVarContextFromSpecializedClass = exports.setTypeArgumentsRecursive = exports.specializeClassType = void 0;
11
+ exports.getTypeVarArgumentsRecursive = exports.addTypeVarsToListIfUnique = exports.getClassFieldsRecursive = exports.getClassIterator = exports.getClassMemberIterator = exports.lookUpClassMember = exports.lookUpObjectMember = exports.getContainerDepth = exports.getProtocolSymbols = exports.transformExpectedTypeForConstructor = exports.validateTypeVarDefault = exports.applySolvedTypeVars = exports.ensureFunctionSignaturesAreUnique = exports.populateTypeVarContextForSelfType = exports.partiallySpecializeType = exports.isUnboundedTupleClass = exports.isTupleClass = exports.isMaybeDescriptorInstance = exports.isDescriptorInstance = exports.isProperty = exports.isEllipsisType = exports.getUnionSubtypeCount = exports.getLiteralTypeClassName = exports.containsLiteralType = exports.containsType = exports.isLiteralTypeOrUnion = exports.isLiteralType = exports.getSpecializedTupleType = exports.getTypeVarScopeId = exports.transformPossibleRecursiveTypeAlias = exports.isTypeAliasRecursive = exports.isTypeAliasPlaceholder = exports.getTypeCondition = exports.addConditionToType = exports.getFullNameOfType = exports.derivesFromAnyOrUnknown = exports.isUnionableType = exports.preserveUnknown = exports.areTypesSame = exports.doForEachSubtype = exports.sortTypes = exports.mapSubtypes = exports.makeInferenceContext = exports.isTypeVarSame = exports.isIncompleteUnknown = exports.isOptionalType = exports.UniqueSignatureTracker = exports.AssignTypeFlags = exports.ClassIteratorFlags = exports.ClassMemberLookupFlags = void 0;
12
+ exports.convertParamSpecValueToType = exports.convertTypeToParamSpecValue = exports.getDeclaringModulesForType = exports.computeMroLinearization = exports.isVarianceOfTypeArgumentCompatible = exports.combineVariances = exports.requiresSpecialization = exports.requiresTypeArguments = exports.getGeneratorTypeArgs = exports.removeParamSpecVariadicsFromFunction = exports.removeParamSpecVariadicsFromSignature = exports.specializeTupleClass = exports.combineSameSizedTuples = exports.explodeGenericClass = exports.isPartlyUnknown = exports.containsUnknown = exports.getMembersForModule = exports.getMembersForClass = exports.convertToInstantiable = exports.convertToInstance = exports.isEffectivelyInstantiable = exports.isMetaclassInstance = exports.getGeneratorYieldType = exports.getDeclaredGeneratorReturnType = exports.synthesizeTypeVarForSelfCls = exports.derivesFromClassRecursive = exports.specializeForBaseClass = exports.buildTypeVarContext = exports.buildTypeVarContextFromSpecializedClass = exports.setTypeArgumentsRecursive = exports.specializeClassType = exports.isTypeVarLimitedToCallable = void 0;
13
13
  const collectionUtils_1 = require("../common/collectionUtils");
14
14
  const debug_1 = require("../common/debug");
15
15
  const symbol_1 = require("./symbol");
16
- const symbolNameUtils_1 = require("./symbolNameUtils");
17
16
  const symbolUtils_1 = require("./symbolUtils");
18
17
  const types_1 = require("./types");
19
18
  const typeVarContext_1 = require("./typeVarContext");
@@ -100,185 +99,26 @@ var AssignTypeFlags;
100
99
  // employing narrowing or widening, and don't strip literals.
101
100
  AssignTypeFlags[AssignTypeFlags["PopulatingExpectedType"] = 1024] = "PopulatingExpectedType";
102
101
  })(AssignTypeFlags = exports.AssignTypeFlags || (exports.AssignTypeFlags = {}));
103
- var ParameterSource;
104
- (function (ParameterSource) {
105
- ParameterSource[ParameterSource["PositionOnly"] = 0] = "PositionOnly";
106
- ParameterSource[ParameterSource["PositionOrKeyword"] = 1] = "PositionOrKeyword";
107
- ParameterSource[ParameterSource["KeywordOnly"] = 2] = "KeywordOnly";
108
- })(ParameterSource = exports.ParameterSource || (exports.ParameterSource = {}));
109
- // Examines the input parameters within a function signature and creates a
110
- // "virtual list" of parameters, stripping out any markers and expanding
111
- // any *args with unpacked tuples.
112
- function getParameterListDetails(type) {
113
- const result = {
114
- firstPositionOrKeywordIndex: 0,
115
- positionParamCount: 0,
116
- positionOnlyParamCount: 0,
117
- params: [],
118
- hasUnpackedVariadicTypeVar: false,
119
- hasUnpackedTypedDict: false,
120
- };
121
- let positionOnlyIndex = type.details.parameters.findIndex((p) => p.category === 0 /* Simple */ && !p.name);
122
- // Handle the old (pre Python 3.8) way of specifying positional-only
123
- // parameters by naming them with "__".
124
- if (positionOnlyIndex < 0) {
125
- for (let i = 0; i < type.details.parameters.length; i++) {
126
- const p = type.details.parameters[i];
127
- if (p.category !== 0 /* Simple */) {
128
- break;
129
- }
130
- if (!p.name) {
131
- break;
132
- }
133
- if ((0, symbolNameUtils_1.isDunderName)(p.name) || !p.name.startsWith('__')) {
134
- break;
135
- }
136
- positionOnlyIndex = i + 1;
137
- }
138
- }
139
- if (positionOnlyIndex >= 0) {
140
- result.firstPositionOrKeywordIndex = positionOnlyIndex;
102
+ class UniqueSignatureTracker {
103
+ constructor() {
104
+ this.signaturesSeen = [];
141
105
  }
142
- for (let i = 0; i < positionOnlyIndex; i++) {
143
- if (type.details.parameters[i].hasDefault) {
144
- break;
145
- }
146
- result.positionOnlyParamCount++;
106
+ findSignature(signature) {
107
+ return this.signaturesSeen.find((s) => {
108
+ return (0, types_1.isTypeSame)(signature, s.type);
109
+ });
147
110
  }
148
- let sawKeywordOnlySeparator = false;
149
- const addVirtualParameter = (param, index, typeOverride, defaultArgTypeOverride, sourceOverride) => {
150
- if (param.name) {
151
- let source;
152
- if (sourceOverride !== undefined) {
153
- source = sourceOverride;
154
- }
155
- else if (param.category === 1 /* VarArgList */) {
156
- source = ParameterSource.PositionOnly;
157
- }
158
- else if (sawKeywordOnlySeparator) {
159
- source = ParameterSource.KeywordOnly;
160
- }
161
- else if (positionOnlyIndex >= 0 && index < positionOnlyIndex) {
162
- source = ParameterSource.PositionOnly;
163
- }
164
- else {
165
- source = ParameterSource.PositionOrKeyword;
166
- }
167
- result.params.push({
168
- param,
169
- index,
170
- type: typeOverride !== null && typeOverride !== void 0 ? typeOverride : types_1.FunctionType.getEffectiveParameterType(type, index),
171
- defaultArgType: defaultArgTypeOverride,
172
- source,
173
- });
174
- }
175
- };
176
- type.details.parameters.forEach((param, index) => {
177
- var _a, _b;
178
- if (param.category === 1 /* VarArgList */) {
179
- // If this is an unpacked tuple, expand the entries.
180
- const paramType = types_1.FunctionType.getEffectiveParameterType(type, index);
181
- if (param.name && (0, types_1.isUnpackedClass)(paramType) && paramType.tupleTypeArguments) {
182
- const addToPositionalOnly = index < result.positionOnlyParamCount;
183
- paramType.tupleTypeArguments.forEach((tupleArg, tupleIndex) => {
184
- const category = (0, types_1.isVariadicTypeVar)(tupleArg.type) || tupleArg.isUnbounded
185
- ? 1 /* VarArgList */
186
- : 0 /* Simple */;
187
- if (category === 1 /* VarArgList */) {
188
- result.argsIndex = result.params.length;
189
- }
190
- if ((0, types_1.isVariadicTypeVar)(param.type)) {
191
- result.hasUnpackedVariadicTypeVar = true;
192
- }
193
- addVirtualParameter({
194
- category,
195
- name: `${param.name}[${tupleIndex.toString()}]`,
196
- isNameSynthesized: true,
197
- type: tupleArg.type,
198
- hasDeclaredType: true,
199
- }, index, tupleArg.type,
200
- /* defaultArgTypeOverride */ undefined, ParameterSource.PositionOnly);
201
- if (category === 0 /* Simple */) {
202
- result.positionParamCount++;
203
- }
204
- if (tupleIndex > 0 && addToPositionalOnly) {
205
- result.positionOnlyParamCount++;
206
- }
207
- });
208
- // Normally, a VarArgList parameter (either named or as an unnamed separator)
209
- // would signify the start of keyword-only parameters. However, we can construct
210
- // callable signatures that defy this rule by using Callable and TypeVarTuples
211
- // or unpacked tuples.
212
- if (!sawKeywordOnlySeparator && (positionOnlyIndex < 0 || index >= positionOnlyIndex)) {
213
- result.firstKeywordOnlyIndex = result.params.length;
214
- sawKeywordOnlySeparator = true;
215
- }
216
- }
217
- else {
218
- if (param.name && result.argsIndex === undefined) {
219
- result.argsIndex = result.params.length;
220
- if ((0, types_1.isVariadicTypeVar)(param.type)) {
221
- result.hasUnpackedVariadicTypeVar = true;
222
- }
223
- }
224
- // Normally, a VarArgList parameter (either named or as an unnamed separator)
225
- // would signify the start of keyword-only parameters. However, we can construct
226
- // callable signatures that defy this rule by using Callable and TypeVarTuples
227
- // or unpacked tuples.
228
- if (!sawKeywordOnlySeparator && (positionOnlyIndex < 0 || index >= positionOnlyIndex)) {
229
- result.firstKeywordOnlyIndex = result.params.length;
230
- if (param.name) {
231
- result.firstKeywordOnlyIndex++;
232
- }
233
- sawKeywordOnlySeparator = true;
234
- }
235
- addVirtualParameter(param, index);
236
- }
237
- }
238
- else if (param.category === 2 /* VarArgDictionary */) {
239
- sawKeywordOnlySeparator = true;
240
- const paramType = types_1.FunctionType.getEffectiveParameterType(type, index);
241
- // Is this an unpacked TypedDict? If so, expand the entries.
242
- if ((0, types_1.isClassInstance)(paramType) && (0, types_1.isUnpackedClass)(paramType) && paramType.details.typedDictEntries) {
243
- if (result.firstKeywordOnlyIndex === undefined) {
244
- result.firstKeywordOnlyIndex = result.params.length;
245
- }
246
- const typedDictType = paramType;
247
- paramType.details.typedDictEntries.forEach((entry, name) => {
248
- const specializedParamType = partiallySpecializeType(entry.valueType, typedDictType);
249
- addVirtualParameter({
250
- category: 0 /* Simple */,
251
- name,
252
- type: specializedParamType,
253
- hasDeclaredType: true,
254
- hasDefault: !entry.isRequired,
255
- }, index, specializedParamType);
256
- });
257
- result.hasUnpackedTypedDict = true;
258
- }
259
- else if (param.name) {
260
- if (result.kwargsIndex === undefined) {
261
- result.kwargsIndex = result.params.length;
262
- }
263
- if (result.firstKeywordOnlyIndex === undefined) {
264
- result.firstKeywordOnlyIndex = result.params.length;
265
- }
266
- addVirtualParameter(param, index);
267
- }
111
+ addSignature(signature) {
112
+ const existingSignature = this.findSignature(signature);
113
+ if (existingSignature) {
114
+ existingSignature.count++;
268
115
  }
269
- else if (param.category === 0 /* Simple */) {
270
- if (param.name && !sawKeywordOnlySeparator) {
271
- result.positionParamCount++;
272
- }
273
- addVirtualParameter(param, index,
274
- /* typeOverride */ undefined, ((_a = type.specializedTypes) === null || _a === void 0 ? void 0 : _a.parameterDefaultArgs)
275
- ? (_b = type.specializedTypes) === null || _b === void 0 ? void 0 : _b.parameterDefaultArgs[index]
276
- : undefined);
116
+ else {
117
+ this.signaturesSeen.push({ type: signature, count: 1 });
277
118
  }
278
- });
279
- return result;
119
+ }
280
120
  }
281
- exports.getParameterListDetails = getParameterListDetails;
121
+ exports.UniqueSignatureTracker = UniqueSignatureTracker;
282
122
  function isOptionalType(type) {
283
123
  if ((0, types_1.isUnion)(type)) {
284
124
  return (0, types_1.findSubtype)(type, (subtype) => (0, types_1.isNoneInstance)(subtype)) !== undefined;
@@ -290,6 +130,36 @@ function isIncompleteUnknown(type) {
290
130
  return (0, types_1.isUnknown)(type) && type.isIncomplete;
291
131
  }
292
132
  exports.isIncompleteUnknown = isIncompleteUnknown;
133
+ // Similar to isTypeSame except that type1 is a TypeVar and type2
134
+ // can be either a TypeVar of the same type or a union that includes
135
+ // conditional types associated with that bound TypeVar.
136
+ function isTypeVarSame(type1, type2) {
137
+ if ((0, types_1.isTypeSame)(type1, type2)) {
138
+ return true;
139
+ }
140
+ // If this isn't a bound TypeVar, return false.
141
+ if (type1.details.isParamSpec || type1.details.isVariadic || !type1.details.boundType) {
142
+ return false;
143
+ }
144
+ // If the second type isn't a union, return false.
145
+ if (!(0, types_1.isUnion)(type2)) {
146
+ return false;
147
+ }
148
+ let isCompatible = true;
149
+ doForEachSubtype(type2, (subtype) => {
150
+ if (!isCompatible) {
151
+ return;
152
+ }
153
+ if (!(0, types_1.isTypeSame)(type1, subtype)) {
154
+ const conditions = getTypeCondition(subtype);
155
+ if (!conditions || !conditions.some((condition) => condition.typeVarName === type1.nameWithScope)) {
156
+ isCompatible = false;
157
+ }
158
+ }
159
+ });
160
+ return isCompatible;
161
+ }
162
+ exports.isTypeVarSame = isTypeVarSame;
293
163
  function makeInferenceContext(expectedType, typeVarContext, isTypeIncomplete) {
294
164
  if (!expectedType) {
295
165
  return undefined;
@@ -837,6 +707,13 @@ function populateTypeVarContextForSelfType(typeVarContext, contextClassType, sel
837
707
  typeVarContext.setTypeVarType(synthesizedSelfTypeVar, convertToInstance(selfClass));
838
708
  }
839
709
  exports.populateTypeVarContextForSelfType = populateTypeVarContextForSelfType;
710
+ // Looks for duplicate function types within the type and ensures that
711
+ // if they are generic, they have unique type variables.
712
+ function ensureFunctionSignaturesAreUnique(type, signatureTracker) {
713
+ const transformer = new UniqueFunctionSignatureTransformer(signatureTracker);
714
+ return transformer.apply(type, 0);
715
+ }
716
+ exports.ensureFunctionSignaturesAreUnique = ensureFunctionSignaturesAreUnique;
840
717
  // Specializes a (potentially generic) type by substituting
841
718
  // type variables from a type var map.
842
719
  function applySolvedTypeVars(type, typeVarContext, options = {}) {
@@ -1597,11 +1474,13 @@ function convertToInstance(type, includeSubclasses = true) {
1597
1474
  if (type.typeAliasInfo && type !== result) {
1598
1475
  result = types_1.TypeBase.cloneForTypeAlias(result, type.typeAliasInfo.name, type.typeAliasInfo.fullName, type.typeAliasInfo.typeVarScopeId, type.typeAliasInfo.typeParameters, type.typeAliasInfo.typeArguments);
1599
1476
  }
1600
- // Cache the converted value for next time.
1601
- if (!type.cached) {
1602
- type.cached = {};
1477
+ if (type !== result) {
1478
+ // Cache the converted value for next time.
1479
+ if (!type.cached) {
1480
+ type.cached = {};
1481
+ }
1482
+ type.cached.instanceType = result;
1603
1483
  }
1604
- type.cached.instanceType = result;
1605
1484
  return result;
1606
1485
  }
1607
1486
  exports.convertToInstance = convertToInstance;
@@ -2323,7 +2202,7 @@ class TypeVarTransformer {
2323
2202
  return type;
2324
2203
  }
2325
2204
  recursionCount++;
2326
- type = this._transformGenericTypeAlias(type, recursionCount);
2205
+ type = this.transformGenericTypeAlias(type, recursionCount);
2327
2206
  // Shortcut the operation if possible.
2328
2207
  if (!requiresSpecialization(type)) {
2329
2208
  return type;
@@ -2405,7 +2284,7 @@ class TypeVarTransformer {
2405
2284
  return !(0, types_1.isNever)(newUnionType) ? newUnionType : types_1.UnknownType.create();
2406
2285
  }
2407
2286
  if ((0, types_1.isClass)(type)) {
2408
- return this._transformTypeVarsInClassType(type, recursionCount);
2287
+ return this.transformTypeVarsInClassType(type, recursionCount);
2409
2288
  }
2410
2289
  if ((0, types_1.isFunction)(type)) {
2411
2290
  // Prevent recursion.
@@ -2413,7 +2292,7 @@ class TypeVarTransformer {
2413
2292
  return type;
2414
2293
  }
2415
2294
  this._pendingFunctionTransformations.push(type);
2416
- const result = this._transformTypeVarsInFunctionType(type, recursionCount);
2295
+ const result = this.transformTypeVarsInFunctionType(type, recursionCount);
2417
2296
  this._pendingFunctionTransformations.pop();
2418
2297
  return result;
2419
2298
  }
@@ -2427,7 +2306,7 @@ class TypeVarTransformer {
2427
2306
  // Specialize each of the functions in the overload.
2428
2307
  const newOverloads = [];
2429
2308
  type.overloads.forEach((entry) => {
2430
- const replacementType = this._transformTypeVarsInFunctionType(entry, recursionCount);
2309
+ const replacementType = this.transformTypeVarsInFunctionType(entry, recursionCount);
2431
2310
  if ((0, types_1.isFunction)(replacementType)) {
2432
2311
  newOverloads.push(replacementType);
2433
2312
  }
@@ -2445,7 +2324,7 @@ class TypeVarTransformer {
2445
2324
  return type;
2446
2325
  }
2447
2326
  transformTypeVar(typeVar, recursionCount) {
2448
- return typeVar;
2327
+ return undefined;
2449
2328
  }
2450
2329
  transformTupleTypeVar(paramSpec, recursionCount) {
2451
2330
  return undefined;
@@ -2461,7 +2340,7 @@ class TypeVarTransformer {
2461
2340
  // can override this method as they see fit.
2462
2341
  return callback();
2463
2342
  }
2464
- _transformGenericTypeAlias(type, recursionCount) {
2343
+ transformGenericTypeAlias(type, recursionCount) {
2465
2344
  if (!type.typeAliasInfo || !type.typeAliasInfo.typeParameters || !type.typeAliasInfo.typeArguments) {
2466
2345
  return type;
2467
2346
  }
@@ -2477,12 +2356,12 @@ class TypeVarTransformer {
2477
2356
  ? types_1.TypeBase.cloneForTypeAlias(type, type.typeAliasInfo.name, type.typeAliasInfo.fullName, type.typeAliasInfo.typeVarScopeId, type.typeAliasInfo.typeParameters, newTypeArgs)
2478
2357
  : type;
2479
2358
  }
2480
- _transformTypeVarsInClassType(classType, recursionCount) {
2359
+ transformTypeVarsInClassType(classType, recursionCount) {
2481
2360
  // Handle the common case where the class has no type parameters.
2482
2361
  if (types_1.ClassType.getTypeParameters(classType).length === 0 && !types_1.ClassType.isSpecialBuiltIn(classType)) {
2483
2362
  return classType;
2484
2363
  }
2485
- let newTypeArgs = [];
2364
+ let newTypeArgs;
2486
2365
  let newTupleTypeArgs;
2487
2366
  let specializationNeeded = false;
2488
2367
  const typeParams = types_1.ClassType.getTypeParameters(classType);
@@ -2499,50 +2378,7 @@ class TypeVarTransformer {
2499
2378
  const wasTransformingTypeArg = this._isTransformingTypeArg;
2500
2379
  this._isTransformingTypeArg = true;
2501
2380
  // If type args were previously provided, specialize them.
2502
- if (classType.typeArguments) {
2503
- newTypeArgs = classType.typeArguments.map((oldTypeArgType) => {
2504
- if ((0, types_1.isTypeVar)(oldTypeArgType) && oldTypeArgType.details.isParamSpec) {
2505
- return transformParamSpec(oldTypeArgType);
2506
- }
2507
- let newTypeArgType = this.apply(oldTypeArgType, recursionCount);
2508
- if (newTypeArgType !== oldTypeArgType) {
2509
- specializationNeeded = true;
2510
- // If this was a variadic type variable that was part of a union
2511
- // (e.g. Union[Unpack[Vs]]), expand the subtypes into a union here.
2512
- if ((0, types_1.isTypeVar)(oldTypeArgType) &&
2513
- (0, types_1.isVariadicTypeVar)(oldTypeArgType) &&
2514
- oldTypeArgType.isVariadicInUnion) {
2515
- newTypeArgType = _expandVariadicUnpackedUnion(newTypeArgType);
2516
- }
2517
- }
2518
- return newTypeArgType;
2519
- });
2520
- }
2521
- else {
2522
- typeParams.forEach((typeParam) => {
2523
- let replacementType = typeParam;
2524
- if (typeParam.details.isParamSpec) {
2525
- replacementType = transformParamSpec(typeParam);
2526
- if (replacementType !== typeParam) {
2527
- specializationNeeded = true;
2528
- }
2529
- }
2530
- else {
2531
- const typeParamName = types_1.TypeVarType.getNameWithScope(typeParam);
2532
- if (!this._pendingTypeVarTransformations.has(typeParamName)) {
2533
- const transformedType = this.transformTypeVar(typeParam, recursionCount);
2534
- replacementType = transformedType !== null && transformedType !== void 0 ? transformedType : typeParam;
2535
- if (replacementType !== typeParam) {
2536
- specializationNeeded = true;
2537
- }
2538
- else if (transformedType !== undefined && !classType.typeArguments) {
2539
- specializationNeeded = true;
2540
- }
2541
- }
2542
- }
2543
- newTypeArgs.push(replacementType);
2544
- });
2545
- }
2381
+ // Handle tuples specially.
2546
2382
  if (types_1.ClassType.isTupleClass(classType)) {
2547
2383
  if (classType.tupleTypeArguments) {
2548
2384
  newTupleTypeArgs = [];
@@ -2568,6 +2404,66 @@ class TypeVarTransformer {
2568
2404
  specializationNeeded = true;
2569
2405
  }
2570
2406
  }
2407
+ // If this is an empty tuple, don't recompute the non-tuple type argument.
2408
+ if (newTupleTypeArgs && newTupleTypeArgs.length > 0) {
2409
+ // Combine the tuple type args into a single non-tuple type argument.
2410
+ newTypeArgs = [
2411
+ (0, types_1.combineTypes)(newTupleTypeArgs.map((t) => {
2412
+ if ((0, types_1.isTypeVar)(t.type) && (0, types_1.isUnpackedVariadicTypeVar)(t.type)) {
2413
+ // Treat the unpacked TypeVarTuple as a union.
2414
+ return types_1.TypeVarType.cloneForUnpacked(t.type, /* isInUnion */ true);
2415
+ }
2416
+ return t.type;
2417
+ })),
2418
+ ];
2419
+ }
2420
+ }
2421
+ if (!newTypeArgs) {
2422
+ if (classType.typeArguments) {
2423
+ newTypeArgs = classType.typeArguments.map((oldTypeArgType) => {
2424
+ if ((0, types_1.isTypeVar)(oldTypeArgType) && oldTypeArgType.details.isParamSpec) {
2425
+ return transformParamSpec(oldTypeArgType);
2426
+ }
2427
+ let newTypeArgType = this.apply(oldTypeArgType, recursionCount);
2428
+ if (newTypeArgType !== oldTypeArgType) {
2429
+ specializationNeeded = true;
2430
+ // If this was a variadic type variable that was part of a union
2431
+ // (e.g. Union[Unpack[Vs]]), expand the subtypes into a union here.
2432
+ if ((0, types_1.isTypeVar)(oldTypeArgType) &&
2433
+ (0, types_1.isVariadicTypeVar)(oldTypeArgType) &&
2434
+ oldTypeArgType.isVariadicInUnion) {
2435
+ newTypeArgType = _expandVariadicUnpackedUnion(newTypeArgType);
2436
+ }
2437
+ }
2438
+ return newTypeArgType;
2439
+ });
2440
+ }
2441
+ else {
2442
+ newTypeArgs = [];
2443
+ typeParams.forEach((typeParam) => {
2444
+ let replacementType = typeParam;
2445
+ if (typeParam.details.isParamSpec) {
2446
+ replacementType = transformParamSpec(typeParam);
2447
+ if (replacementType !== typeParam) {
2448
+ specializationNeeded = true;
2449
+ }
2450
+ }
2451
+ else {
2452
+ const typeParamName = types_1.TypeVarType.getNameWithScope(typeParam);
2453
+ if (!this._pendingTypeVarTransformations.has(typeParamName)) {
2454
+ const transformedType = this.transformTypeVar(typeParam, recursionCount);
2455
+ replacementType = transformedType !== null && transformedType !== void 0 ? transformedType : typeParam;
2456
+ if (replacementType !== typeParam) {
2457
+ specializationNeeded = true;
2458
+ }
2459
+ else if (transformedType !== undefined && !classType.typeArguments) {
2460
+ specializationNeeded = true;
2461
+ }
2462
+ }
2463
+ }
2464
+ newTypeArgs.push(replacementType);
2465
+ });
2466
+ }
2571
2467
  }
2572
2468
  this._isTransformingTypeArg = wasTransformingTypeArg;
2573
2469
  // If specialization wasn't needed, don't allocate a new class.
@@ -2578,7 +2474,7 @@ class TypeVarTransformer {
2578
2474
  /* isTypeArgumentExplicit */ true,
2579
2475
  /* includeSubclasses */ undefined, newTupleTypeArgs);
2580
2476
  }
2581
- _transformTypeVarsInFunctionType(sourceType, recursionCount) {
2477
+ transformTypeVarsInFunctionType(sourceType, recursionCount) {
2582
2478
  return this.doForEachSignatureContext(() => {
2583
2479
  let functionType = sourceType;
2584
2480
  // Handle functions with a parameter specification in a special manner.
@@ -2754,6 +2650,32 @@ class TypeVarDefaultValidator extends TypeVarTransformer {
2754
2650
  return undefined;
2755
2651
  }
2756
2652
  }
2653
+ class UniqueFunctionSignatureTransformer extends TypeVarTransformer {
2654
+ constructor(_signatureTracker) {
2655
+ super();
2656
+ this._signatureTracker = _signatureTracker;
2657
+ }
2658
+ transformTypeVarsInFunctionType(sourceType, recursionCount) {
2659
+ // If this function is not generic, there's no need to check for uniqueness.
2660
+ if (sourceType.details.typeParameters.length === 0) {
2661
+ return super.transformTypeVarsInFunctionType(sourceType, recursionCount);
2662
+ }
2663
+ let updatedSourceType = sourceType;
2664
+ const existingSignature = this._signatureTracker.findSignature(sourceType);
2665
+ if (existingSignature) {
2666
+ const typeVarContext = new typeVarContext_1.TypeVarContext(getTypeVarScopeId(sourceType));
2667
+ // Create new type variables with the same scope but with
2668
+ // different (unique) names.
2669
+ sourceType.details.typeParameters.forEach((typeParam) => {
2670
+ const replacement = types_1.TypeVarType.cloneForNewName(typeParam, `${typeParam.details.name}(${existingSignature.count})`);
2671
+ typeVarContext.setTypeVarType(typeParam, replacement);
2672
+ updatedSourceType = applySolvedTypeVars(sourceType, typeVarContext);
2673
+ });
2674
+ }
2675
+ this._signatureTracker.addSignature(sourceType);
2676
+ return updatedSourceType;
2677
+ }
2678
+ }
2757
2679
  // Specializes a (potentially generic) type by substituting
2758
2680
  // type variables from a type var map.
2759
2681
  class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {